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

#ifndef fedReader_H_
#define fedReader_H_

//! \file fedReader.h
//! \ingroup mtl
//! \brief This file declares DtFedReader and several helper classes.

#include <stdio.h>
#include <vlutil/vlFedTarget.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

class DtFilename;

enum DtFedReadStatus
{
   DtFedReadOK,
   DtCouldNotOpenFed,
   DtErrorReadingFed,
   DtUnknownFileFormat
};

enum DtFedReadStrictChecking
{
   DtFedReadStrictDisabled = 0x0000,
   DtFedReadStrictBasic    = 0x0001,
   DtFedReadStrictTables   = 0x0002,
};

//! Instances of DtFedReader are used to read a FED file, and fill in a 
//! DtFedTarget with the information read.  
//! Base class for contained file format specific (i.e. - mtl and xml)
//! FED file readers
//! \ingroup mtl
class DT_DLL_MTL DtFedReader
{
public:
   static const DtString theHlaEvolvedStandardMimFileName;
   static const DtString theHla4StandardMimFileName;
   static const DtString theInvalidStandardMimFileName;

public:

   //! Constructor
   DtFedReader();

   //! Destructor
   virtual ~DtFedReader();

private:

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

public:

   //! Get the FOM Type
   //@{
   static DtFomType checkFomType(const char* fedFileName, void* fedFilePtr );
   static DtFomType checkFomType(const char* fedFileName);
   //@}

   //! Return the standard MIM filename given the FOM type
   static const DtString& standardMimFileName(DtFomType fomType);

   //! Return true if file is the standard MIM file of the given type
   static bool isStandardMimFileName(DtString const& fileName, DtFomType fomType);

   //! Open file from name and return FILE*
   static FILE* openFedFile(const char* fileName, bool isBinary = false);

   //! Read the file from the FILE* into the buffer.
   static bool readFileIntoBuffer(FILE* fileHandle, char** fileBuffer, unsigned int* fileSize);

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 readFed(const char* fedFileName, 
      DtFedTarget* fedTarget, unsigned int strictCheckingMask=DtFedReadStrictDisabled, bool useDTD=false, bool dontParseSwitches=false );

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

   //! get the a file handle to the FED File for reading in
   //!    text or binary mode 
   virtual FILE* openFedFileWithErrCheck( const char* fileName, bool isBinary = false );

   //! Set status of strict checking. Use Enums to OR together desired checks
   //! Returns the previous value of strict checking
   virtual unsigned int setStrictChecking(unsigned int checkMask);

   //! Returns bool: strictChecking enabled for types of checks provided
   virtual bool strictChecking(unsigned int checkMask) const;

   //! Set/Get expected FOM type
   virtual void setExpectedFomType(DtFomType fomType);
   virtual DtFomType expectedFomType() const;

   //! Returns the FOM type of the last FOM read
   virtual DtFomType lastFomType() const;

   //! Get the last error
   virtual const DtString& lastError() const;

   //! Buffer containing the most recently read FDD file
   char* myCurrFddBuffer;
   //! Size of the buffer for the most recently read FDD file
   unsigned int myCurrFddBufferSize;

   char* takeCurrFddData();

protected:

   void appendErrorLine(xmlNode* node, DtString& output) const;

   DtFedTarget* myFedTarget;
   DtFedReader* myChildReader;
   unsigned int myStrictChecking;
   bool myDontParseSwitchTable;

   //! When set, the FOM must conform to this type
   DtFomType myExpectedFomType;

   //! The type of FOM format that was last read
   DtFomType myLastFomType;

   //! Description of last encountered error
   DtString myLastError;

};

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


#endif

