CChunk class

(C)Copyright 2000 NTT Cyber Space Laboratories

# `CChunk class`

name
  `CChunk` - class for storing TwinVQ header information
interface
  `class CChunk{
  public:
  // type declaration
  typedef std::vector<char> CChunkData;
  // initialize, destructor
  CChunk(std::string ID); // constructor
  virtual ~CChunk(); // destructor
  ////////////////////////////
  // member functions
  // input
  const std::string& GetID(); // get chunk ID
  const int GetSize(); // get chunk size
  const CChunkData& GetData(); // get chunk data
  // output
  int PutData( int size, char inputData[] ); // character array
  int PutData( CChunkData& inputData ); // vector
  int PutData( std::string& theString); // character string
  // inquiry
  virtual std::string whatami(); // type of chunk
  protected:
  int GetNInt( int size=sizeof(long) ); // get size byte integer from current position
  CChunkData GetVector( int size=0 ); // get size byte vector from current position
  std::string GetRndString( int length=0 ); // get length of character string
  void PutNInt( unsigned int inputData, int size=sizeof(long) ); // put size byte integer from current position
  void cnk_rewind(); // move current position to top
  void cnk_delete(); // delete cunk data
  const int GetCurrentPosition(); // get current position
  // exception
  class err_FailPut; // output failure
  }`
description
  The class `CChunk` helps construction and acquisition of the chunk data which contain header information. `CChunk` consists of ID, size and data as for other data format chunk. Reading procedures of ID, size, and data are available. However, it is not allowed to write ID and size directly. ID can be once defined at construction, and the size is automatically updated according to the data contents. Access method of data field of `CChunk`is not open, since the structures of the data field depend on the chunk. Some subclasses inherit the `CChunk` and the data field can be accessed by protected member functions.
generation, initialization
  This class has constructor for chunk ID as well as default constructor. The data field of the constructor for chunk ID is initialized to be empty, and the chunk size is set 0.
description of member functions(public)
  `const std::string& GetID()`
    gets chunk ID.
  `const int GetSize()`
    gets chunk size.
  `const CChunkData& GetData()`
    gets information in a CChunkData form.
  `int PutData( int size, char inputData[] )`
    appends size byte of inputData at the end of data field.
  `int PutData( CChunkData& inputData )`
    appends inputData at the end of data field.
  `int PutData( std::string& theString )`
    appends theString at the end of data field.
description of member functions (protected)
  Protected member functions release access procedure to subclasses. `CChunk` class holds current position. Current position is automatically moved to the data field. The current position can be obtained by `GetCurrentPosition()` and can be set to the top by `cnk_rewind()`.
  `int GetNInt( int size=sizeof(long) )`
    gets size byte integer from current position. (Default size is 4.)
  `CChunkData GetVector( int size=0 )`
    gets size byte of vector `(CChunkData)` from current position. (Default size is a size of data field to the end.)
  `std::string GetRndString ( int size=0 )`
    gets size of character string. (Default size is a size of data field to the end.)
  `void PutNInt( unsigned int inputData, int size=sizeof(long) )`
    puts size byte of integer. (Default size is 4.)
  `void cnk_rewind()`
    sets the current position to the top.
  `void cnk_delete()`
    deletes contents of data field.
  `const int GetCurrentPosition()`
    gets the current position.
necessary include file
  `CChunk.h`
file name containing these functions
  `CChunk.cxx`
reference
  TwinVQ data format manual