/*********************************************************************
** Copyright (c) 1992-2010 MAK Technologies, Inc
** All rights reserved.
*********************************************************************/

#ifndef xmlFedReader1516e_H_
#define xmlFedReader1516e_H_

//! \file xmlFedReader1516e.h
//! \ingroup mtl
//! \brief This file declares DtXmlFedReader1516e

#include <stdio.h>
#include <string>

#include <vlutil/vlFedTarget.h>
#include "fedReader.h"
#include <vlutil/vlString.h>



//! Forward declarations
struct _xmlNode;
struct _xmlDoc;
typedef unsigned char xmlChar;
typedef struct _xmlNode xmlNode;
typedef struct _xmlDoc xmlDoc;

#ifdef DtUSE_UTILITIES_NAMESPACE
namespace DtUSE_UTILITIES_NAMESPACE
{
#endif

//! Instances of DtXmlFedReader1516e are used to read a FED file, and fill in a 
//! DtFedTarget with the information read.
//! The FED file must be in the HLA Evolved XML file format
//! \ingroup mtl
class DT_DLL_MTL DtXmlFedReader1516e : public DtFedReader
{
public:

   //! Constructor
   DtXmlFedReader1516e();

   //! Destructor
   virtual ~DtXmlFedReader1516e();

private:

   //! Copy constructor and Assignment operator - Unimplemented
   DtXmlFedReader1516e( const DtXmlFedReader1516e& );
   DtXmlFedReader1516e& operator=( const DtXmlFedReader1516e& );

public:

   //! Read the FED file fedFileName, setting values to fedTarget.
   //! Note if fedTarget is NULL the fedfile will be read and verified only.
   virtual DtFedReadStatus readFedFilePtr(FILE* filePointer, DtFedTarget *fedTarget, 
      DtFilename fileName, unsigned int strictCheckingMask=DtFedReadStrictDisabled, bool useDTD=false, bool dontParseSwitches=false );

   //! Sets whether or not schema validation should be performed.
   virtual void setSchemaValidationEnabled(bool enabled);

protected:

   //! Validate the file against the given DTD.
   virtual bool schemaValidate(xmlDoc* pDoc, const char * schemaFile);

   //! open FED file and create a new XML Document Tree object
   virtual DtFedReadStatus openFile(const char *fedFileName,
                                    xmlDoc  **newXmlDocTree);

   //! get the specified node
   static xmlNode* getNodeByName( xmlNode* currentNode,
                                   const xmlChar* nodeName );
   //! process the FED directive
   virtual DtFedReadStatus processFed( xmlNode* fedObj );
   
   //! process the transportations directive
   virtual DtFedReadStatus parseTransportationsList( xmlNode* currentNode );

   //! process the Model Identification directive
   virtual DtFedReadStatus processModelIdentification( xmlNode* currentNode );

   //! process the Objects directive
   virtual DtFedReadStatus processObjects( xmlNode* currentNode );

   //! process the Interactions directive
   virtual DtFedReadStatus processInteractions( xmlNode* currentNode );

   //! process the list object of classes
   virtual DtFedReadStatus parseObjectTree( xmlNode* currentNode,
                                            const DtString& parentName );

   //! process an attribute of an object class
   virtual DtFedReadStatus parseAttribute( xmlNode* currentNode,
                                           const DtString& parentName );

   //! process attribute dimension associations
   virtual DtFedReadStatus parseAttributeDimensions( xmlNode* currentNode,
      DtString const& objectClass, DtString const& attribute);

   //! process the list of interaction classes
   virtual DtFedReadStatus parseInteractionTree( xmlNode* currentNode,
                                                 const DtString& parentName );

   //! process attribute dimension associations
   virtual DtFedReadStatus parseInteractionDimensions( xmlNode *currentNode,
      DtString const& interactionClass );

   //! process the list of dimensions
   virtual DtFedReadStatus parseDimensionList( xmlNode* currentNode );

   //! process a dimension
   virtual DtFedReadStatus parseDimension( xmlNode* currentNode );

   //! process switches
   virtual DtFedReadStatus parseSwitches( xmlNode* currentNode );

   //! process update rates
   virtual DtFedReadStatus parseUpdateRates( xmlNode* currentNode );

   //! process a parameter of an interaction class
   virtual DtFedReadStatus parseParameter( xmlNode* currentNode,
                                           const DtString& parentName );

   //! process the list of transportation classes
   virtual DtFedReadStatus parseTransportationTree( xmlNode* currentNode );

   //! process the list of datatype classes
   virtual DtFedReadStatus parseDataTypeTree( xmlNode* currentNode );

   //! process the list of notes classes
   virtual DtFedReadStatus parseNotesTree( xmlNode* currentNode );

   //! process the list of user defined tags.
   virtual DtFedReadStatus parseTagsTree( xmlNode* currentNode );

   //! process the list of basic data representations
   virtual DtFedReadStatus parseBasicDataTypesTree( xmlNode* currentNode );

   //! process the list of simple data types
   virtual DtFedReadStatus parseSimpleDataTypesTree( xmlNode* currentNode );

   //! process the list of array data types
   virtual DtFedReadStatus parseArrayDataTypesTree( xmlNode* currentNode );

   //! process the list of enumerated data types
   virtual DtFedReadStatus parseEnumeratedDataTypesTree( xmlNode* currentNode );

   //! process the list of fixed record data types
   virtual DtFedReadStatus parseFixedRecordDataTypesTree( xmlNode* currentNode );

   //! process the list of variant record data types
   virtual DtFedReadStatus parseVariantRecordDataTypesTree( xmlNode* currentNode );

   //! Appends the list of properties attached to an XML node to the given string
   virtual void appendNodeProperties( xmlNode* currentNode, DtString& output ) const;

   //! Appends the name and content of the given node to the given string
   virtual void appendNodeContent(xmlNode*  node, DtString& output) const;

   //! Return true if the node is blank text (space, tab, newline)
   virtual bool isBlankText(xmlNode*  node) const;

   //! Return the data for the specified property of the given node
   virtual const xmlChar* propertyByName( xmlNode* node, const xmlChar *name);

   //! Fill in a string with the data for the specified property
   //! of the given node (empty string if property not found)
   //! Return true if property is found
   virtual bool getPropertyByName( xmlNode* node, const xmlChar *name,
      DtString& propertyContent);

   //! Return the data for the specified child of the given node
   static const xmlChar* childContentByName( xmlNode* node, const xmlChar *name) ;

   //! Fill in a string with the data for the specified child
   //! of the given node (empty string if child not found)
   //! Return true if child is found
   virtual bool getChildContentByName( xmlNode* node, const xmlChar *name,
      DtString& childContent);

   //! get the data for the Transportation attribute of the current node
   virtual DtFedReadStatus getTransportType( xmlNode* currentNode,
                                             DtTransportType& transportType );

   //! get the data for the Order attribute of the current node
   virtual DtFedReadStatus getOrderType( xmlNode* currentNode,
                                         DtOrderType& orderType );

   bool convertStringToULong(std::string numericString,
      unsigned long& value);
#ifdef __sgi__
   void clipPrefix(std::string& valueSpec, char c);
#else
   template<typename operandType> void clipPrefix(std::string& valueSpec,
      operandType c);
#endif

public:

   static bool isEvolvedFormat(void* fedFilePtr);

protected:

   DtFedTarget* myFedTarget;

   // Whether or not schema validation should be performed
   bool mySchemaValidationEnabled;

};

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

#endif  //! xmlFedReader1516e_H_

