// file: $isip_ifc/class/algo/Constant/Constant.h // version: $Id: Constant.h 10532 2006-03-29 21:26:30Z raghavan $ // // make sure definitions are only made once // #ifndef ISIP_CONSTANT #define ISIP_CONSTANT // isip include files // #ifndef ISIP_ALGORITHM_BASE #include #endif #ifndef ISIP_HASH_TABLE #include #endif // Constant: a class is used to get constants from a file, it works // similarly with Generator class(no input data needed). Users can get // constants from this class, which get the constants from a file. These // constants can be used to continue calculation. Constant class supports // all data type defined in AlgorithmData class. // class Constant : public AlgorithmBase { //--------------------------------------------------------------------------- // // public constants // //--------------------------------------------------------------------------- public: // define the class name // static const String CLASS_NAME; //---------------------------------------- // // other important constants // //---------------------------------------- // define the algorithm choices // enum ALGORITHM { DATA = 0, DEF_ALGORITHM = DATA}; // define the implementation choices // enum IMPLEMENTATION { READ = 0, WRITE, DEF_IMPLEMENTATION = READ}; // define output filename mode choices // enum OUT_FILENAME_MODE { NORMAL = 0, TEMPORARY, DEF_OUT_FILENAME_MODE = NORMAL}; // define the static NameMap objects // static const NameMap ALGO_MAP; static const NameMap IMPL_MAP; static const NameMap OUT_FILENAME_MODE_MAP; //---------------------------------------- // // i/o related constants // //---------------------------------------- static const String DEF_PARAM; static const String DEF_FILENAME; static const String PARAM_ALGORITHM; static const String PARAM_IMPLEMENTATION; static const String PARAM_OUT_FILENAME_MODE; static const String PARAM_DATATYPE; static const String PARAM_FILENAME; static const String PARAM_CHANNEL; static const String PARAM_CHANNEL_INDEX; //---------------------------------------- // // default values and arguments // //---------------------------------------- // define a default value for the channel // static const bool8 DEF_DATA_EXIST = false; // define default argument(s) // static const AlgorithmData::COEF_TYPE DEF_COEF_TYPE = AlgorithmData::DEF_CTYPE; //---------------------------------------- // // error codes // //---------------------------------------- static const int32 ERR = 70500; //--------------------------------------------------------------------------- // // protected data // //--------------------------------------------------------------------------- protected: // algorithm name // ALGORITHM algorithm_d; // implementation name // IMPLEMENTATION implementation_d; // output filename mode // OUT_FILENAME_MODE out_filename_mode_d; // specify a filename to read/write a constant value // String filename_d; // specify the total number of channels // Long channels_d; // specify a channel index // Vector channel_index_d; // define the type of data to be stored // AlgorithmData::DATA_TYPE data_type_d; // define a variable to hold the data // Vector data_d; // define a flag that indicates whether the data has already been read // bool8 data_exist_d; // static memory manager // static MemoryManager mgr_d; // define the static HashTable object // static HashTable hash_files_d; //--------------------------------------------------------------------------- // // required public methods // //--------------------------------------------------------------------------- public: // method: name // static const String& name() { return CLASS_NAME; } // other static methods // static bool8 diagnose(Integral::DEBUG debug_level); // debug methods: // setDebug is inherited from the base class // bool8 debug(const unichar* msg) const; // method: destructor // ~Constant() {} // method: default constructor // Constant(ALGORITHM algorithm = DEF_ALGORITHM, IMPLEMENTATION implementation = DEF_IMPLEMENTATION) { algorithm_d = algorithm; implementation_d = implementation; data_type_d = AlgorithmData::DEF_DTYPE; out_filename_mode_d = DEF_OUT_FILENAME_MODE; filename_d.assign(DEF_FILENAME); data_exist_d = DEF_DATA_EXIST; channels_d = DEF_NUM_CHANNELS; is_valid_d = false; } // method: copy constructor // Constant(const Constant& arg) { assign(arg); } // assign methods // bool8 assign(const Constant& arg); // method: operator= // Constant& operator= (const Constant& arg) { assign(arg); return *this; } // i/o methods // int32 sofSize() const; bool8 read(Sof& sof, int32 tag, const String& name = CLASS_NAME); bool8 write(Sof& sof, int32 tag, const String& name = CLASS_NAME) const; bool8 readData(Sof& sof, const String& pname = DEF_PARAM, int32 size = SofParser::FULL_OBJECT, bool8 param = true, bool8 nested = false); bool8 writeData(Sof& sof, const String& pname = DEF_PARAM) const; // equality methods // bool8 eq(const Constant& arg) const; // method: new // static void* operator new(size_t size) { return mgr_d.get(); } // method: new[] // static void* operator new[](size_t size) { return mgr_d.getBlock(size); } // method: delete // static void operator delete(void* ptr) { mgr_d.release(ptr); } // method: delete[] // static void operator delete[](void* ptr) { mgr_d.releaseBlock(ptr); } // method: setGrowSize // static bool8 setGrowSize(int32 grow_size) { return mgr_d.setGrow(grow_size); } // other memory management methods // bool8 clear(Integral::CMODE ctype = Integral::DEF_CMODE); //--------------------------------------------------------------------------- // // class-specific public methods: // set methods // //--------------------------------------------------------------------------- // method: setAlgorithm // bool8 setAlgorithm(ALGORITHM algorithm) { algorithm_d = algorithm; is_valid_d = false; return true; } // method: setImplementation // bool8 setImplementation(IMPLEMENTATION implementation) { implementation_d = implementation; is_valid_d = false; return true; } // method: setOutFilenameMode // bool8 setOutFilenameMode(OUT_FILENAME_MODE out_filename_mode) { out_filename_mode_d = out_filename_mode; is_valid_d = false; return true; } // method: setChannel // bool8 setChannel(int32 channels) { channels_d = channels; is_valid_d = false; return true; } // method: setDataType // bool8 setDataType(AlgorithmData::DATA_TYPE type) { data_type_d = type; is_valid_d = false; return true; } // method: setFilename // bool8 setFilename(String filename) { filename_d = filename; is_valid_d = false; return true; } // method: set // bool8 set(ALGORITHM algorithm = DEF_ALGORITHM, IMPLEMENTATION implementation = DEF_IMPLEMENTATION) { algorithm_d = algorithm; implementation_d = implementation; is_valid_d = false; return true; } //--------------------------------------------------------------------------- // // class-specific public methods: // get methods // //--------------------------------------------------------------------------- // method: getAlgorithm // ALGORITHM getAlgorithm() const { return algorithm_d; } // method: getImplementation // IMPLEMENTATION getImplementation() const { return implementation_d; } // method: getImplementation // OUT_FILENAME_MODE getOutFilenameMode() const { return out_filename_mode_d; } // method: getChannel // int32 getChannel() const { return channels_d; } // method: getFilename // bool8 getFilename(String& filename) const { filename = filename_d; return true; } // method: getInputFilename // bool8 getInputFilename(String& filename) const { if (implementation_d == READ) { filename = filename_d; } else filename.assign(String::NULL_STRING); return true; } // method: getOutputFilename // bool8 getOutputFilename(String& filename) const { if (implementation_d == WRITE) { filename = filename_d; } else filename.assign(String::NULL_STRING); return true; } // method: getDataType // AlgorithmData::DATA_TYPE getDataType() const { return data_type_d; } // method: get // bool8 get(ALGORITHM& algorithm, IMPLEMENTATION& implementation) const{ algorithm = algorithm_d; implementation = implementation_d; return true; } //--------------------------------------------------------------------------- // // class-specific public methods: // computational methods // //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- // // class-specific public methods: // public methods required by the AlgorithmBase interface contract // //--------------------------------------------------------------------------- // assign method // bool8 assign(const AlgorithmBase& arg); // equality method // bool8 eq(const AlgorithmBase& arg) const; // method: className // const String& className() const { return CLASS_NAME; } // initialization method // bool8 init(); // apply method // bool8 apply(Vector& output, const Vector< CircularBuffer >& input); // method to set the parser // bool8 setParser(SofParser* parser); //--------------------------------------------------------------------------- // // private methods // //--------------------------------------------------------------------------- private: // i/o methods // bool8 readDataConstant(Sof& sof, const String& pname, int32 size, bool8 param, bool8 nested); bool8 writeDataConstant(Sof& sof, const String& pname) const; // implementation specific compute methods // bool8 computeRead(Vector& output, const Vector< CircularBuffer >& input); bool8 computeWrite(Vector& output, const Vector< CircularBuffer >& input); bool8 getFromHash(); }; // end of include file // #endif