/***************************************************************************
** Copyright (c) 1992-2025 MAK Technologies, Inc
** All rights reserved.
***************************************************************************/
//! \file objectHistory.h
//! \ingroup omtReader
#pragma once



#pragma warning(disable : 4100)
#include <vlutil/vlMachineTypes.h>

//VR-Link Includes
#ifdef DtHLA_1516
#include "RTI/RTI1516.h"
#elif DtHLA
#include "RTI.hh"
#endif
#ifdef DtHLA
#include <vl/stateMsgHLA.h>
#include <vl/stateRepository.h>
#include <vl/rtiNamespace.h>
#endif
#include <omtReader/stringTree.h>
#include <omtReader/attributeHistory.h>

#include <map>
#include <string>
#include <set>

#ifdef DtUSE_UTILITIES_NAMESPACE
namespace DtUSE_UTILITIES_NAMESPACE
{
#endif
// This class only works if we actually have an HLA Connection
#ifdef DtHLA

//This class contains information about a single object
class DT_DLL_OMTREADER  DtObjectHistory
{  
public:

   //! Constructor
   DtObjectHistory(const char* name, RTI::ObjectClassHandle classHandle, DtHlaObject* obj,
      DtDatatypeManager& dm);

   //! Destructor    
   virtual ~DtObjectHistory();

   //! Get the object name
   virtual const char * objectName() const;

   //! Get the object class handle
   virtual RTI::ObjectClassHandle objectClassHandle() const;

   //! Get the HLA object
   virtual DtHlaObject* hlaObject();

   //! Get the attribute history for the given attribute
   virtual DtAttributeHistory* getAttribute(RTI::AttributeHandle handle);

   //! Create a string tree for the given attribute handle
   virtual DtStringTree* createStringTree(RTI::AttributeHandle handle, const DtDatatypeFedNode* omtNode);

   //! Update the object history with the updates from the given update message
   virtual void updateAttributes(const DtStateMsg& msg);

   //! Get an attribute handle set of the updated attribute
#if DtHLA_1516
   virtual const RTI::AttributeHandleSet& updatedAttributes() const;
#else
   virtual const std::set<RTI::AttributeHandle>& updatedAttributes() const;
#endif

   //! Make known attributes dirty and emit as if updated
   virtual void forceUpdate();

protected:

   //! Set the attribute history for the given attribute
   //! Note: This function takes ownership of the Attribute Repository
   virtual void setAttribute(RTI::AttributeHandle handle, const void* buffer, int length);

   //! Set the attribute for each attribute value in the given value set.
   virtual void setAttributes(const HandleValueMap& attrValues);

protected: 

   DtDatatypeManager& myDatatypeManager;
   DtString myObjectName;
   RTI::ObjectClassHandle myClassHandle;
   DtHlaObject* myObject;
   std::map<RTI::AttributeHandle, DtAttributeHistory*> myAttributes;
#if DtHLA_1516
   RTI::AttributeHandleSet myUpdatedAttributes;
#else
   std::set<RTI::AttributeHandle> myUpdatedAttributes;
#endif
};

#endif

#ifdef DtUSE_UTILITIES_NAMESPACE
} // end of namespace DtUSE_UTILITIES_NAMESPACE
#endif
