/***************************************************************************
                          SIMPLY POWERFUL TOOLKIT (SPTK)
                          CExcelRecordsBuffer.h  -  description
                             -------------------
    begin                : Mon Jan 19 2004
    copyright            : (C) 2004 by Alexey S.Parshin
    email                : alexeyp@gmail.com
 ***************************************************************************/

/***************************************************************************
   This library is free software; you can redistribute it and/or modify it 
   under the terms of the GNU Library General Public License as published by
   the Free Software Foundation; either version 2 of the License, or (at 
   your option) any later version.

   This library is distributed in the hope that it will be useful, but 
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
   General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; if not, write to the Free Software Foundation, 
   Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.

   Please report all bugs and problems to "alexeyp@gmail.com"
 ***************************************************************************/

#ifndef __CEXCELRECORDSBUFFER_H__
#define __CEXCELRECORDSBUFFER_H__

#include <sptk3/CBuffer.h>
#include <sptk3/excel/CExcelRecord.h>
#include <sptk3/CIntList.h>

namespace sptk {

   /// @addtogroup excel Excel Classes
   /// @{

   /// The buffer that contains the Excel commands
	class CExcelRecordsBuffer : public CBuffer {
		unsigned m_currentPosition;         /// Current position for next()
		CIntList m_sheetPosition;           /// The list of BOUNDSHEET record positions - for creating a new records buffer 
	public:
      /// Constructor
      /// creates an empty buffer of pre-allocated size
      /// @param sz unsigned, the required size of the buffer
		CExcelRecordsBuffer(unsigned sz) : CBuffer(sz) { m_currentPosition = 0; }

      /// Constructor
      /// creates a buffer of the appropriate size and stores data into it
      /// @param data void *, the pointer to the data
      /// @param sz unsigned, the size of the data
		CExcelRecordsBuffer(void *data,unsigned sz) : CBuffer(data,sz) { m_currentPosition = 0;}

      /// Reset the internal data
		void reset();

      /// Adds a new BOUNDSHEET record position in the buffer - for creating a new records buffer 
      /// @param pos unsigned, the position of the new BOUNDSHEET record in the stream
		void addSheetPosition(unsigned pos) { m_sheetPosition.push_back(pos); }

      /// Returns a position of the sheet in the stream
      /// @param sheetIndex unsigned, the sheet index 
		unsigned sheetPosition(unsigned sheetIndex) const { return m_sheetPosition[sheetIndex]; }

      /// Positions the current record to the first available record, or NULL
      /// @returns pointer to the new CExcelRecord object with the data of the first available record
      /// Application should delete this object eventually
		CExcelRecord *first();

      /// Positions the current record to the next available record, or NULL
      /// @returns pointer to the new CExcelRecord object with the data of the first available record
      /// Application should delete this object eventually
		CExcelRecord *next();

      /// Appends a copy of CExcelRecord to the record buffer
      /// @param rec const CExcelRecord *, the Excel record buffer
		void append(const CExcelRecord *rec);

      /// Appends the raw data to the record buffer
      /// @param recordType unsigned, record type
      /// @param dataSize unsigned, record data size
      /// @param data const char *, record data
		void append(unsigned recordType,unsigned dataSize,const char *data);

      /// Appends the raw data to the record buffer
      /// @param data const char *, raw data
      /// @param dataSize unsigned, raw data size
		void append(const char *data,unsigned dataSize) { CBuffer::append(data,dataSize); }

      /// Appends the raw data buffer to the record buffer
      /// @param buffer const CBuffer&, raw data
		void append(const CBuffer& buffer) { CBuffer::append(buffer.data(),buffer.bytes()); }
	};
   /// @}
}
#endif
