// =====================================================================
/*!
//
//  \file TSoftwareDataFileModule.hh
//  \brief This file contains the TSoftwareDataFileModule class.
//  \author Go IWAI <goiwai@users.sourceforge.jp>
//
//  $Id: TSoftwareDataFileModule.hh,v 1.6 2004/03/07 10:30:31 goiwai Exp $
//  $Name: CLDAQ-1-14-03 $
//  $Log: TSoftwareDataFileModule.hh,v $
//  Revision 1.6  2004/03/07 10:30:31  goiwai
//  ROOTに組みこむためのおまじないマクロを埋めこみました。
//  全てにおいて完全に動作するわけではありません。
//
//  Revision 1.5  2004/01/19 21:09:41  goiwai
//  プリプロセッサの接頭辞をCLDAQ__に変更しました.
//
//  Revision 1.4  2003/11/03 08:35:13  goiwai
//  Doxygen用のタグとコメントをうちこんでいく試みを開始しました.
//
//  Revision 1.3  2003/10/06 17:02:40  goiwai
//  *** empty log message ***
//
//  Revision 1.2  2003/07/30 16:19:11  goiwai
//  ファイルにコミットログをつけることにしました.
//
*/
// =====================================================================
#ifndef CLDAQ__TSOFTWAREDATAFILEMODULE_HH
#define CLDAQ__TSOFTWAREDATAFILEMODULE_HH

#include "Tglobals.h"
#include "TSoftwareModule.hh"

class TDataSegment;
class TDataElement;


/*!
// \example
//
// If example code exists.
//
*/

/*!
// \class TSoftwareDataFileModule
// \brief This is the TSoftwareDataFileModule class.
// \author Go IWAI <goiwai@users.sourceforge.jp>
//
// The TSoftwareDataFileModule class detail description.
// Write it down ASAP!
//
// \todo None?
// \bug None?
// \ingroup ModulesCategory
*/
class TSoftwareDataFileModule
  : public TSoftwareModule
{

  private:
    enum { tDefaultBufferLength = 1048576 };

  private:
    Tstring theFileName;
    Tstring theSeparater;
    TdoubleList theChannel;
    Tint theBufferLength;
    Tint theNumberOfLine;
    TstringList theCommentStringList;
    Tifstream theInputFileStream;

  public:
    TSoftwareDataFileModule( const Tstring& filename, Tint nchannel );
    TSoftwareDataFileModule( const Tstring& filename, const TstringList& comment, Tint nchannel );
    TSoftwareDataFileModule( const Tstring& filename, const Tstring& separater, Tint nchannel );
    TSoftwareDataFileModule( const Tstring& filename, const TstringList& comment, const Tstring& separater, Tint nchannel );
    TSoftwareDataFileModule( const TSoftwareDataFileModule& right );
    ~TSoftwareDataFileModule();

  public:
    Tint Clear();
    Tint Update();
    Tint Initialize();

  public:
    Tvoid FillData( TDataElement& element, Tint channel );

  public:
    const TSoftwareDataFileModule& operator=( const TSoftwareDataFileModule& right );
    Tbool operator==( const TSoftwareDataFileModule& right ) const;
    Tbool operator!=( const TSoftwareDataFileModule& right ) const;

  public:
    const Tstring& GetFileName() const;
    const Tstring& GetSeparater() const;
    const TdoubleList& GetChannel() const;
    Tint GetBufferLength() const;
    const TstringList& GetCommentStringList() const;
    Tint GetNumberOfLine() const;
    Tifstream& GetInputFileStream();
    Tvoid SetFileName( const Tstring& fname );
    Tvoid SetSeparater( const Tstring& separater );
    Tvoid SetChannel( const TdoubleList& channels );
    Tvoid SetBufferLength( Tint buflen );
    Tvoid SetCommentStringList( const TstringList& commentlist );
    Tvoid SetNumberOfLine( Tint nline );

  private:
    const Tstring& eraseComment( Tstring& readline ) const;
    TdoubleList divideLine( Tstring readline ) const;
    Tint getNumberOfLine() const;

#ifdef __CLDAQ_ROOT_DLL
    ClassDef(TSoftwareDataFileModule,0)
#endif

};

inline const Tstring& TSoftwareDataFileModule::GetFileName() const
{
  return theFileName;
}

inline const Tstring& TSoftwareDataFileModule::GetSeparater() const
{
  return theSeparater;
}

inline const TdoubleList& TSoftwareDataFileModule::GetChannel() const
{
  return theChannel;
}

inline Tint TSoftwareDataFileModule::GetBufferLength() const
{
  return theBufferLength;
}

inline const TstringList& TSoftwareDataFileModule::GetCommentStringList() const
{
  return theCommentStringList;
}

inline Tint TSoftwareDataFileModule::GetNumberOfLine() const
{
  return theNumberOfLine;
}

inline Tifstream& TSoftwareDataFileModule::GetInputFileStream()
{
  return theInputFileStream;
}

inline Tvoid TSoftwareDataFileModule::SetFileName( const Tstring& fname )
{
  theFileName = fname;
  return;
}

inline Tvoid TSoftwareDataFileModule::SetSeparater( const Tstring& separater )
{
  theSeparater = separater;
  return;
}

inline Tvoid TSoftwareDataFileModule::SetChannel( const TdoubleList& channels )
{
  theChannel = channels;
  return;
}

inline Tvoid TSoftwareDataFileModule::SetBufferLength( Tint buflen )
{
  theBufferLength = buflen;
  return;
}

inline Tvoid TSoftwareDataFileModule::SetCommentStringList( const TstringList& commentlist )
{
  theCommentStringList = commentlist;
  return;
}

inline Tvoid TSoftwareDataFileModule::SetNumberOfLine( Tint nline )
{
  theNumberOfLine = nline;
  return;
}

#endif
