/***************************************************************************
                          Scriptor project
                          CExcelRowRecord.h  -  description
                             -------------------
    begin                : 15 March 2004
    copyright            : (C) 2000-2006 by Alexey S.Parshin
    email                : alexeyp@gmail.com
 ***************************************************************************/

#ifndef __CEXCELROWRECORD_H__
#define __CEXCELROWRECORD_H__

#include <sptk3/excel/CExcelRecordsBuffer.h>
#include <sptk3/excel/CExcelRow.h>
#include <sptk3/excel/CExcelSST.h>

namespace sptk {

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

   /// Represents Excel row
	class CExcelRowRecord : public CExcelRecord {
		unsigned     m_rowNumber;           ///< Row number, 0-based
		unsigned     m_streamPosition;      ///< Stream position of the row record
		unsigned     m_firstCellPosition;   ///< Stream position of the first cell record for the row
		unsigned     m_firstDefinedColumn;  ///< The column of the first defined cell in the row
		unsigned     m_lastDefinedColumn;   ///< The column of the last defined cell in the row
		CExcelRow   *m_cells;               ///< The actual Excel row

		void saveMultipleRK(CExcelRecordsBuffer& records,char *mulRKBuffer,unsigned firstColumn,unsigned& count);

      /// Updates row record with the actual cells columns and positions
      /// @param recordStreamPtr char *, ROW record pointer (in the output stream)
		void updateRowRecord(char *recordStreamPtr);
	public:

      /// Constructor
      /// @param rowNumber unsigned, number of row in the spreadseet, 0-based
      /// @param row CExcelRow *, the actual data of the row, kept as a pointer to an external data
		CExcelRowRecord(unsigned rowNumber,CExcelRow *row); 

      /// Saves ROW record into the external Excel format
      /// @param records CExcelRecordsBuffer&, the output buffer of Excel records
		void saveRowRecord(CExcelRecordsBuffer& records);

      /// Saves cell records (for this) into the external Excel format.
      /// Also updates the ROW record with the actual stream position, first and last cells of the row.
      /// @param records CExcelRecordsBuffer&, the output buffer of Excel records
      /// @param sst const CExcelSST&, the existing SST
      /// @param secondRowStart unsigned, the position of the second row of this set in the stream
		void saveCellRecords(CExcelRecordsBuffer& records,const CExcelSST& sst,unsigned secondRowStart);

      /// Returns the count of cells in the row, including empty cells
		unsigned size() const { return m_cells->size(); }

      /// Provides access to the cells in the row
      /// @param i unsigned, cell index
		CVariant& operator [] (unsigned i) const { return (*m_cells)[i]; }

      /// Returns stream position of the row record
		unsigned streamPosition() const { return m_streamPosition; }    

      /// Returns stream position of the first cell record for the row
		unsigned firstCellPosition() const { return m_firstCellPosition; }
	};
   /// @}
}
#endif
