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



#include <fstream>
#include <omtReader/omtReader.h>
#include <vlutil/vlString.h>
#include <vlutil/vlFilename.h>

#ifdef DtUSE_UTILITIES_NAMESPACE
namespace DtUSE_UTILITIES_NAMESPACE
{
#endif

//! Inputs data from a comma delimited file format
//! \ingroup omtReader
class DT_DLL_OMTREADER DtCSVReader 
{  

public:
   DtCSVReader( const DtFilename & filename );
   virtual ~DtCSVReader();
        
   //! Read the next line of the file.  Returns false if no more lines.
   virtual bool readLine();
   
   //! Returns one or more fields as a string.
   //! See QTextStream::section() for details.
   virtual DtString stringVar( int start, int end ) const;

   //! Returns the field number "pos" as an integer. 
   //! validNum indicates if the conversion to an integer
   //! was possible.  
   virtual int intVar( int pos, bool * validNum ) const;

   virtual void setSeparator(char newSeparator);
   virtual char separator();

   //! Returns the number of columns on the line, given the separator
   virtual int numColumns() const;

   const DtString& currLine() const;

protected:
   char        mySeparator;
   DtFilename  myFile;
   std::ifstream myTS;
   bool        myValidFile;
   DtString     myCurrLine;
};

inline const DtString& DtCSVReader::currLine() const
{
   return myCurrLine;
}

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

