name: Constant : public AlgorithmBase
synopsis:

>     g++ [flags ...] file ... -l /isip/tools/lib/$ISIP_BINARY/lib_algo.a

>     #include <Constant.h>

>     Constant(ALGORITHM algorithm = DEF_ALGORITHM, IMPLEMENTATION implementation = DEF_IMPLEMENTATION);
>     Constant(const Constant& arg);
>     boolean assign(const Constant& arg);
>     boolean setAlgorithm(ALGORITHM type);
>     boolean setDataType(AlgorithmData::DATA_TYPE type);

quick start:

>     Constant cons;
>     Vector <CircularBuffer <AlgorithmData>> in;
>     Vector <AlgorithmData> out;
>     cons.apply(output, input);

description:
The Constant class is used to write (or read) constants from a file. This is a very important class for implementation of recipes that require multiple passes through the data (e.g., cepstral mean subtraction). For example, the constant class can be combined with the Statistics class to compute and save the average value of a signal. This constant can then be read in a subsequent stage of processing using the same class, and used in the next pass of calculations.
The Constant class supports all data types currently supported in the AlgorithmData class. The table below is provided for reference purposes:
The output (or input) filename is set by the user using the setFilenamemethod. The object is written using an object-specific I/O method (e.g., VECTOR_FLOAT uses the class VectorFloat's I/O methods).
The main use of this class is in isip_transform's recipe processing code. Users need not use this class - they can use the standard object I/O methods directly in their code.
dependencies:

- AlgorithmBase

public constants:

- define the class name:

      static const String CLASS_NAME = L"Constant";

- define algorithm choices:

      enum ALGORITHM { DATA = 0, DEF_ALGORITHM = DATA };

- define the implementation choices:

      enum IMPLEMENTATION { READ = 0, WRITE, DEF_IMPLEMENTATION = READ };

- define the static NameMap objects

      static const NameMap ALGO_MAP(L"DATA");

      static const NameMap IMPL_MAP(L"READ, WRITE");

- define i/o related variables:

      static const String DEF_PARAM = L"";

      static const String DEF_FILENAME = L"diagnose_file.sof";

      static const String PARAM_ALGORITHM = L"algorithm";

      static const String PARAM_IMPLEMENTATION = L"implementation";

      static const String PARAM_DATATYPE = L"datatype";

      static const String PARAM_FILENAME = L"filename";

      static const String PARAM_CHANNEL = L"channels";

      static const String PARAM_CHANNELINDEX = L"channelindex";

- define default value(s) of the class data:

      static const boolean DEF_DATA_EXIST = false;

- default arguments to methods:

      static const AlgorithmData::COEF_TYPE DEF_COEF_TYPE = AlgorithmData::SEF_CTYPE;

error codes:

- error code indicating Constant class general error:

      static const long ERR = 70500;

protected data:

- data common to all algorithms and implementations:
  - algorithm name:

        ALGORITHM algorithm_d;

  - implementation name:

        IMPLEMENTATION implementation_d;

  - file name:

        String file_name_d;

  - total channels:

        Long channels_d;

  - channel index:

        Vector <Long> channel_index_d;

  - data type:

        AlgorithmData::DATA_TYPE data_type_d;

  - data holder:

        Vector <AlgorithmData> data_d;

  - data exist indicator:

        boolean data_exist_d;

  - static memory manager:

        static MemoryManager mgr_d;

  - static hash table:

        static HashTable hash_files_d;

required public methods:

- static methods:

      static const String& name();

      static boolean diagnose(Integral::DEBUG debug_level);

- debug methods: setDebug method is inherited from base class

      boolean debug(const unichar* message) const;

- destructor/constructor(s):

      ~Constant();

      Constant(ALGORITHM algorithm = DEF_ALGORITHM, IMPLEMENTATION implementation = DEF_IMPLEMENTATION);

      Constant(const Constant& arg);

- assign methods:

      boolean assign(const Constant& arg);

- operator= methods:

      Constant& operator= (const Constant& arg);

- i/o methods:

      long sofSize() const;

      boolean read(Sof& sof, long tag, const String& name = CLASS_NAME);

      boolean write(Sof& sof, long tag, const String& name = CLASS_NAME) const;

      boolean readData(Sof& sof, const String& pname = DEF_PARAM, long size = SofParser::FULL_OBJECT, boolean param = true, boolean nested = false);

      boolean readData(Sof& sof, long size = SofParser::FULL_OBJECT, boolean param = true, boolean nested = false);

      boolean writeData(Sof& sof, const String& pname = DEF_PARAM) const;

      boolean writeData(Sof& sof) const;

- equality methods:

      boolean eq(const Constant& arg) const;

- memory management methods:

      static void* operator new(size_t size);

      static void* operator new[](size_t size);

      static void operator delete(void* ptr);

      static void operator delete[](void* ptr);

      static boolean setGrowSize(long grow_size);

      boolean clear();

class-specific public methods:

- set methods:

      boolean setAlgorithm(ALGORITHM algorithm);

      boolean setImplementation(IMPLEMENTATION implementation);

      boolean setChannel(long channels);

      boolean setDataType(AlgorithmData::DATA_TYPE type);

      boolean setFilename(String filename);

      boolean set(ALGORITHM algorithm = DEF_ALGORITHM, IMPLEMENTATION implementation = DEF_IMPLEMENTATION);

- get methods:

      ALGORITHM getAlgorithm() const;

      IMPLEMENTATION getImplementation() const;

      long getChannel() const;

      boolean getFilename(String& filename) const;

      boolean getInputFilename(String& filename) const;

      boolean getOutputFilename(String& filename) const;

      AlgorithmData::DATA_TYPE getDataType() const;

      boolean get (ALGORITHM& algorithm, IMPLEMENTATION& implementationconst) const;

- AlgorithmBase interface contract methods:

      boolean assign(const AlgorithmBase& arg);

      boolean eq(const AlgorithmBase& arg) const;

      boolean apply(Vector<AlgorithmData>& output, const Vector<CircularBuffer<AlgorithmData> >& input);

      const String& className() const;

      boolean init();

      boolean setParser(SofParser* parser);

private methods:

- i/o methods:

      boolean readDataConstant(Sof& sof, const String& pname, long size, boolean param, boolean nested);

      boolean writeDataConstant(Sof& sof, const String& pname);

- implementation specific compute methods: READ

      boolean computeRead(Vector<AlgorithmData>& output_a, const Vector< CircularBuffer<AlgorithmData> >& input_a);

- implementation specific compute methods: WRITE

      boolean computeWrite(Vector<AlgorithmData>& output_a, const Vector< CircularBuffer<AlgorithmData> >& input_a);

- implementation specific compute methods: HASH

      boolean getFromHash();

examples:

- This example shows how to write a constant to a file:

      // declare a Constant
      //
      Constant c1;

      // set the source constant file
      //
      c1.setFilename(L"diagnose_file.sof");

      // set implementation to write mode
      //
      c1.setImplementation(WRITE);

      // set data type
      //
      c1.setDataType(AlgorithmData::VECTOR_FLOAT);

      // set channels
      //
      c1.setChannel(4);

      // define some variables
      //
      Vector <CircularBuffer <AlgorithmData>> in;
      Vector <AlgorithmData> out;

      // initiate data
      //
      long N = 4;
      in.setLength(N);

      for (long i = 0; i < N; i++) {
        in(i)(0).makeVectorFloat();
        in(i)(0).getVectorFloat().assign(result(i));
        in(i)(0).setCoefType(AlgorithmData::SIGNAL);
      }

      // call apply method
      //
      c1.apply(out, in);

notes:

- none.