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



#include "complexDatatypeNode.h"
#include "enumeratedDatatypeNode.h"
#include "interactionClassFedNode.h"
#include "objectClassFedNode.h"
#include "simpleDatatypeNode.h"
#include "arrayDatatypeNode.h"
#include "fixedDatatypeNode.h"
#include "variantDatatypeNode.h"
#include "basicDataRepresentationNode.h"
#include "noteNode.h"
#include "boolAttrNode.h"
#include "descriptionNode.h"
#include "dimensionNode.h"
#include "timeRepNode.h"
#include "synchroNode.h"
#include "tagNode.h"

class DtExerciseConn;

#include <vlutil/vlString.h>
#ifdef DtHLA
#ifndef DtUSE_UTILITIES_NAMESPACE
#include <vl/rtiNamespace.h>
#endif
#endif
#include <list>
#ifdef DtUSE_UTILITIES_NAMESPACE
namespace DtUSE_UTILITIES_NAMESPACE
{
#endif
enum DtHLAProtocolVersion { DtUnknownHLA, DtHLA13, DtHLA1516, DtHLA1516e, DtHLA4 };

struct DtOMTTreePOC
{
   DtString myPOCHonorificName;
   DtString myPOCFirstName;
   DtString myPOCLastName;
   DtString myPOCOrgName;
   DtString myPOCPhone;
   DtString myPOCEmail;
   DtString myPOCType;
};

struct DtOMTTreeReference
{
   DtString myReferenceType;
   DtString myReferenceIdentification;
};

class DtUpdateRateNode;

//! A tree using the an OMT File information.
//! \ingroup omtReader
class DT_DLL_OMTREADER DtOMTTree
{
public:

   //! default constructor
   DtOMTTree();
   
   //! destructor
   virtual ~DtOMTTree();


   virtual void setHlaVersion(DtHLAProtocolVersion version);
   virtual DtHLAProtocolVersion hlaVersion() const;

   virtual void setName(const DtString&);
   virtual const DtString& getName();

   virtual void setVersionNo(const DtString&);
   virtual const DtString& getVersionNo();

   virtual void setType(const DtString&);
   virtual const DtString& getType();

   virtual void setPurpose(const DtString&);
   virtual const DtString& getPurpose();

   virtual void setApplicationDomain(const DtString&);
   virtual const DtString& getApplicationDomain();

   virtual void setSponsorOrgName(const DtString&);
   virtual const DtString& getSponsorOrgName();

   virtual void setModificationDate(const DtString&);
   virtual const DtString& getModificationDate();

   virtual void setSecurityClassification(const DtString&);
   virtual const DtString& getSecurityClassification() const;

   virtual void setReleaseRestriction(const DtString&);
   virtual const DtString& getReleaseRestriction() const;

   virtual void setDescription(const DtString&);
   virtual const DtString& getDescription() const;

   virtual void setMOMVersion(const DtString&);
   virtual const DtString& getMOMVersion();

   //! These are only for HLA1516-2000
   virtual void setReference(const DtString&);
   virtual const DtString& getReference();

   //! These are only for HLA1516-2010
   virtual const std::vector<DtOMTTreeReference>& getReferences() const;
   virtual void setReferences(const std::vector<DtOMTTreeReference> & s);
   virtual void addReference(const DtOMTTreeReference & s);

   virtual void setOther(const DtString&);
   virtual const DtString& getOther();

   virtual void setUseLimitation(const DtString&);
   virtual const DtString& getUseLimitation();

   virtual void setUseHistory(const DtString&);
   virtual const DtString& getUseHistory();
   
   virtual void addPOC(const DtOMTTreePOC& poc);
   virtual void addPOC(const DtString& honorificName,
      const DtString& firstName, const DtString& LastName, 
      const DtString& orgName, const DtString& phone, 
      const DtString& email, const DtString& poctype);
   virtual std::list<DtOMTTreePOC>::iterator getPOCList();
   virtual std::list<DtOMTTreePOC>::iterator getPOCEndNode();
      
  virtual void addBasicDataRepresentationNode(DtBasicDataRepresentationNode*);
  virtual DtBasicDataRepresentationNode* getBasicDataRepresentationNode(const DtString& name);
  virtual std::list<DtBasicDataRepresentationNode*>::iterator getBasicDataRepresentationNodeList();
  virtual std::list<DtBasicDataRepresentationNode*>::iterator getBasicDataRepresentationEndNode();
   
  virtual void addVariantDatatypeNode(DtVariantDatatypeNode*);
  virtual DtVariantDatatypeNode* getVariantDatatypeNode(const DtString& name);
  virtual std::list<DtVariantDatatypeNode*>::iterator getVariantDatatypeNodeList();
  virtual std::list<DtVariantDatatypeNode*>::iterator getVariantDatatypeEndNode();
   
  virtual void addFixedDatatypeNode(DtFixedDatatypeNode*);
  virtual DtFixedDatatypeNode* getFixedDatatypeNode(const DtString& name);
  virtual std::list<DtFixedDatatypeNode*>::iterator getFixedDatatypeNodeList();
  virtual std::list<DtFixedDatatypeNode*>::iterator getFixedDatatypeEndNode();
   
  virtual void addSimpleDatatypeNode(DtSimpleDatatypeNode*);
  virtual DtSimpleDatatypeNode* getSimpleDatatypeNode(const DtString& name);
  virtual std::list<DtSimpleDatatypeNode*>::iterator getSimpleDatatypeNodeList();
  virtual std::list<DtSimpleDatatypeNode*>::iterator getSimpleDatatypeEndNode();
   
  virtual void addComplexDatatypeNode(DtComplexDatatypeNode*);
  virtual DtComplexDatatypeNode* getComplexDatatypeNode(const DtString& name);
  virtual std::list<DtComplexDatatypeNode*>::iterator getComplexDatatypeNodeList();
  virtual std::list<DtComplexDatatypeNode*>::iterator getComplexDatatypeEndNode();
   
  virtual void addArrayDatatypeNode(DtArrayDatatypeNode*);
  virtual DtArrayDatatypeNode* getArrayDatatypeNode(const DtString& name);
  virtual std::list<DtArrayDatatypeNode*>::iterator getArrayDatatypeNodeList();
  virtual std::list<DtArrayDatatypeNode*>::iterator getArrayDatatypeEndNode();
   
  virtual void addEnumeratedDatatypeNode(DtEnumeratedDatatypeNode*);
  virtual DtEnumeratedDatatypeNode* getEnumeratedDatatypeNode(const DtString& name);
  virtual std::list<DtEnumeratedDatatypeNode*>::iterator getEnumeratedDatatypeNodeList();
  virtual std::list<DtEnumeratedDatatypeNode*>::iterator getEnumeratedDatatypeEndNode();

  virtual void addNoteNode(DtNoteNode*);
  virtual DtNoteNode* getNoteNode(int val);
  virtual DtNoteNode* getNoteNode(DtString val);
  virtual std::list<DtNoteNode*>::iterator getNoteNodeList();
  virtual std::list<DtNoteNode*>::iterator getNoteEndNode();

  virtual void addUpdateRateNode(DtUpdateRateNode* node);
  virtual DtUpdateRateNode* getUpdateRateNode(const DtString& name);
  virtual std::list<DtUpdateRateNode*>::iterator getUpdateRateNodeList();
  virtual std::list<DtUpdateRateNode*>::iterator getUpdateRateEndNode();


  //@{
  //! Accessor/Mutator for object class root node.
  virtual void setObjectClassRoot(DtObjectClassFedNode* node);
  virtual DtObjectClassFedNode* objectClassRoot();
  //@}

  virtual void addObjectClassNode(DtObjectClassFedNode*);
#ifdef DtHLA
#ifndef DtUSE_UTILITIES_NAMESPACE
  virtual DtObjectClassFedNode* getObjectClassNode(RTI::ObjectClassHandle value);
#endif
#endif
  //! Returns root node by default (name is empty string).
  virtual DtObjectClassFedNode* getObjectClassNode(const DtString& name = "");
  virtual DtObjectClassFedNode* getObjectClassNodeByID(int id);
  virtual std::list<DtObjectClassFedNode*>::iterator getObjectClassNodeBegin();
  virtual std::list<DtObjectClassFedNode*>::iterator getObjectClassNodeEnd();
  virtual std::list<DtObjectClassFedNode*>::reverse_iterator getObjectClassNodeRBegin();
  virtual std::list<DtObjectClassFedNode*>::reverse_iterator getObjectClassNodeREnd();

  //@{
  //! Accessor/Mutator for interaction class root node.
  virtual void setInteractionClassRoot(DtInteractionClassFedNode* node);
  virtual DtInteractionClassFedNode* interactionClassRoot();
  //@}

  virtual void addInteractionClassNode(DtInteractionClassFedNode*);
#ifdef DtHLA
#ifndef DtUSE_UTILITIES_NAMESPACE
  virtual DtInteractionClassFedNode* getInteractionClassNode(RTI::InteractionClassHandle value);
#endif
#endif
  //! Returns root node by default (name is empty string).
  virtual DtInteractionClassFedNode* getInteractionClassNode(const DtString& name = "");
  virtual DtInteractionClassFedNode* getInteractionClassNodeByID(int id);
  virtual std::list<DtInteractionClassFedNode*>::iterator getInteractionClassNodeBegin();
  virtual std::list<DtInteractionClassFedNode*>::iterator getInteractionClassNodeEnd();
  virtual std::list<DtInteractionClassFedNode*>::reverse_iterator getInteractionClassNodeRBegin();
  virtual std::list<DtInteractionClassFedNode*>::reverse_iterator getInteractionClassNodeREnd();

  virtual void addSwitchNode(DtBoolAttrNode*);
  virtual DtBoolAttrNode* getSwitchNode(const DtString& name);
  virtual std::list<DtBoolAttrNode*>::iterator getSwitchNodeList();
  virtual std::list<DtBoolAttrNode*>::iterator getSwitchEndNode();

  virtual void addTransportationNode(DtDescriptionNode*);
  virtual DtDescriptionNode* getTransportationNode(const DtString& name);
  virtual std::list<DtDescriptionNode*>::iterator getTransportationNodeList();
  virtual std::list<DtDescriptionNode*>::iterator getTransportationEndNode();

  virtual void addDimensionNode(DtDimensionNode*);
  virtual DtDimensionNode* getDimensionNode(const DtString& name);
  virtual std::list<DtDimensionNode*>::iterator getDimensionNodeList();
  virtual std::list<DtDimensionNode*>::iterator getDimensionEndNode();

  virtual void addSynchroNode(DtSynchroNode*);
  virtual DtSynchroNode* getSynchroNode(const DtString& name);
  virtual std::list<DtSynchroNode*>::iterator getSynchroNodeList();
  virtual std::list<DtSynchroNode*>::iterator getSynchroEndNode();

  virtual void addTagNode(DtTagNode*);
  virtual DtTagNode* getTagNode(const DtString& name);
  virtual std::list<DtTagNode*>::iterator getTagNodeList();
  virtual std::list<DtTagNode*>::iterator getTagEndNode();

  virtual DtTimeRepNode* getTimeRepNode();

  virtual void merge(DtOMTTree* mergeTree);

protected:
   //! Merge the given source object node and its children into this tree.
   //! The source node's children are traversed recursively.
   //! If a node does not exist in this tree then a copy is added and its reference is returned.
   //! Return: reference to a copy of the source node if it was added (i.e. did not already exist); otherwise, null.
   virtual DtObjectClassFedNode* mergeObjectNode(const DtObjectClassFedNode& sourceNode);
   //! Merge the given source interaction node and its children into this tree.
   //! The source node's children are traversed recursively.
   //! If a node does not exist in this tree then a copy is added and its reference is returned.
   //! Return: reference to a copy of the source node if it was added (i.e. did not already exist); otherwise, null.
   virtual DtInteractionClassFedNode* mergeInteractionNode(const DtInteractionClassFedNode& sourceNode);
   virtual void mergeModelIdentification(DtOMTTree* mergeTree);
   virtual void mergeObjects(DtOMTTree* mergeTree);
   virtual void mergeInteractions(DtOMTTree* mergeTree);
   virtual void mergeDatatypes(DtOMTTree* mergeTree);
   virtual void mergeDimensions(DtOMTTree* mergTree);
   virtual void mergeNotes(DtOMTTree* mergeTree);
   virtual void mergeSyncPoints(DtOMTTree* mergeTree);
   virtual void mergeTransportations(DtOMTTree* mergeTree);
   virtual void mergeUpdateRates(DtOMTTree* mergeTree);
   virtual void mergeTags(DtOMTTree* mergeTree);
   virtual void mergeSwitches(DtOMTTree* mergeTree);

protected:
   std::list<DtNoteNode*> myNoteNodes;
   std::list<DtObjectClassFedNode*> myObjectClassNodes;
   std::list<DtInteractionClassFedNode*> myInteractionClassNodes;
   std::list<DtComplexDatatypeNode*> myComplexDatatypeNodes;
   std::list<DtEnumeratedDatatypeNode*> myEnumeratedDatatypeNodes;

   //1516 only tables
   std::list<DtBasicDataRepresentationNode*> myBasicDataRepresentationNodes;
   std::list<DtSimpleDatatypeNode*> mySimpleDatatypeNodes;
   std::list<DtArrayDatatypeNode*> myArrayDatatypeNodes;
   std::list<DtFixedDatatypeNode*> myFixedDatatypeNodes;
   std::list<DtVariantDatatypeNode*> myVariantDatatypeNodes;
   std::list<DtBoolAttrNode*> mySwitchNodes;
   std::list<DtDescriptionNode*> myTransportationNodes;
   std::list<DtDimensionNode*> myDimensionNodes;
   std::list<DtSynchroNode*> mySynchroNodes;
   std::list<DtTagNode*> myTagNodes;
   
   //! Evolved only tables
   std::list<DtUpdateRateNode*> myUpdateRateNodes;

   DtTimeRepNode* myTimeRepNode;
   
   DtObjectClassFedNode* myObjectClassRoot;
   DtInteractionClassFedNode* myInteractionClassRoot;

   DtString myName;
   DtString myVersionNo;
   DtString myType;
   DtString myPurpose;
   DtString myApplicationDomain;
   DtString mySponsorOrgName;
   DtString myModificationDate;
   DtString mySecurityClassification;
   DtString myReleaseRestriction;
   DtString myDescription;
   DtString myMOMVersion;
   DtString myReference;
   DtString myOther;
   DtString myUseLimitation;
   DtString myUseHistory;

   std::list<DtOMTTreePOC> myPOC;
   std::vector<DtOMTTreeReference> myReferences;
   DtHLAProtocolVersion myHlaVersion;
   
};


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