// file: $isip/class/algo/Algorithm/Algorithm.h // version: $Id: Algorithm.h 10654 2008-01-04 19:39:43Z dom5 $ // // make sure definitions are only made once // #ifndef ISIP_ALGORITHM #define ISIP_ALGORITHM #ifndef ISIP_ALGORITHM_BASE #include #endif #ifndef ISIP_ALGORITHM_UNDEFINED #include #endif #ifndef ISIP_COEFFICIENT_LABEL #include #endif #ifndef ISIP_MEMORY_MANAGER #include #endif #ifndef ISIP_OUTOUT #include #endif #ifndef ISIP_GENERATOR #include #endif #ifndef ISIP_CONSTANT #include #endif #ifndef ISIP_NAME_MAP #include #endif // Algorithm: a class that transforms data using an abstract base // class having virtual functions. The virtual functions allow the // derived class to replace the functionality provided by the base // class. The class AlgorithmBase defines the interface contract for // all the Algorithms. // class Algorithm : public AlgorithmBase { //--------------------------------------------------------------------------- // // public constants // //--------------------------------------------------------------------------- public: // define the class name // static const String CLASS_NAME; //---------------------------------------- // // other important constants // //---------------------------------------- // define the enumeration for data type // enum TYPES { ALGORITHM_CONTAINER = 0, CALCULUS, CEPSTRUM, COEFFICIENT_LABEL, CONNECTION, CONSTANT, CORRELATION, COVARIANCE, DISPLAY_DATA, DYNAMIC_FILTER, ENERGY, FILTER, FILTER_BANK, FOURIER_TRANSFORM, GENERATOR, LOG_AREA_RATIO, MASK, MATH, OUTPUT, PREDICTION, REFLECTION, SPECTRUM, STATISTICS, WINDOW, RPS, LYAPUNOV, CORRELATION_INTEGRAL, MUTUAL_INFORMATION, CORRELATION_ENTROPY, CORRELATION_DIMENSION, DEF_TYPES = CALCULUS }; // define static NameMap objects // static const NameMap TYPES_MAP; //---------------------------------------- // // i/o related constants // //---------------------------------------- static const String DEF_PARAM; static const String PARAM_TYPES; //---------------------------------------- // // error codes // //---------------------------------------- static const int32 ERR = 70050; //--------------------------------------------------------------------------- // // protected data // //--------------------------------------------------------------------------- protected: // pointer to the base class object // AlgorithmBase* virtual_algo_d; // define an empty object used for uninitialized things // static AlgorithmUndefined NO_ALGORITHM; // memory manager // static MemoryManager mgr_d; //--------------------------------------------------------------------------- // // required public methods // //--------------------------------------------------------------------------- public: // method: name // static const String& name() { return CLASS_NAME; } // other static methods // static bool8 diagnose(Integral::DEBUG debug_level); // method: debug // bool8 debug(const unichar* msg) const { return virtual_algo_d->debug(msg); } // destructor/constructor(s) // ~Algorithm(); Algorithm(); Algorithm(const Algorithm& arg); // assign methods // bool8 assign(const Algorithm& arg); // 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; // method: eq // bool8 eq(const Algorithm& arg) const { return virtual_algo_d->eq(*(arg.virtual_algo_d)); } // 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); } // method: clear // bool8 clear(Integral::CMODE ctype = Integral::DEF_CMODE) { if (virtual_algo_d != (AlgorithmBase*)&NO_ALGORITHM) { delete virtual_algo_d; virtual_algo_d = &NO_ALGORITHM; } return true; } //--------------------------------------------------------------------------- // // class-specific public methods: // set methods // // note: not all the set methods available in AlgorithmBase are // preserved here. // //--------------------------------------------------------------------------- // method: setInputFilename // bool8 setInputFilename(Filename& inputname) { if (getType() == OUTPUT) (dynamic_cast< Output*>(virtual_algo_d))->setInputFilename(inputname); return true; } // method: setOutputDirectory // bool8 setOutputDirectory(String& new_dir) { if (getType() == OUTPUT) dynamic_cast (virtual_algo_d)->setOutputDirectory(new_dir); return true; } // method: setOutputBasename // bool8 setOutputBasename(String& new_basename) { if (getType() == OUTPUT) dynamic_cast (virtual_algo_d)->setOutputBasename(new_basename); return true; } // method: setOutputExtension // bool8 setOutputExtension(String& new_ext) { if (getType() == OUTPUT) dynamic_cast (virtual_algo_d)->setOutputExtension(new_ext); return true; } // method: setOutputPreserve // bool8 setOutputPreserve(int32 new_preserve_level) { if (getType() == OUTPUT) dynamic_cast (virtual_algo_d)->setOutputPreserve(new_preserve_level); return true; } // method: setOutputSuffix // bool8 setOutputSuffix(String& new_suffix) { if (getType() == OUTPUT) dynamic_cast (virtual_algo_d)->setOutputSuffix(new_suffix); return true; } // method: setOutputType // bool8 setOutputType(File::TYPE type) { if (getType() == OUTPUT) dynamic_cast (virtual_algo_d)->setOutputType(type); return true; } // method: setSampleFrequency // bool8 setSampleFrequency(float32 sf) { return virtual_algo_d->setSampleFrequency(sf); } // method: setGenSampleFrequency // bool8 setGenSampleFrequency(float32 sf) { if (getType() == GENERATOR) dynamic_cast (virtual_algo_d)->setGenSampleFrequency(sf); return true; } // method: setFrameDuration // bool8 setFrameDuration(float32 dur) { return virtual_algo_d->setFrameDuration(dur); } // method: setSignalDuration // bool8 setSignalDuration(float32 dur) { return virtual_algo_d->setSignalDuration(dur); } // method: setLeftoverSamps // bool8 setLeftoverSamps(int32 samps) { return virtual_algo_d->setLeftoverSamps(samps); } // method: setFrameIndex // bool8 setFrameIndex(int32 index) { return virtual_algo_d->setFrameIndex(index); } // configuration methods // bool8 setType(TYPES type); //--------------------------------------------------------------------------- // // class-specific public methods: // get methods // // note: not all the get methods available in AlgorithmBase are // preserved here. // //--------------------------------------------------------------------------- // method: getInputFilename // bool8 getInputFilename(Filename& filename) const { if (getType() == OUTPUT) dynamic_cast (virtual_algo_d)->getInputFilename(filename); return true; } // method: getInputFilename // bool8 getInputFilename(String& filename) const { if (getType() == CONSTANT) { dynamic_cast (virtual_algo_d)->getInputFilename(filename); } else filename.assign(String::NULL_STRING); return true; } // method: getOutputFilename // bool8 getOutputFilename(String& filename) const { if (getType() == OUTPUT) { dynamic_cast (virtual_algo_d)->getOutputFilename(filename); } else if (getType() == CONSTANT) { dynamic_cast (virtual_algo_d)->getOutputFilename(filename); } else filename.assign(String::NULL_STRING); return true; } // method: getOutputDirectory // bool8 getOutputDirectory(String& directory) const { if (getType() == OUTPUT) return dynamic_cast (virtual_algo_d)-> getOutputDirectory(directory); else return true; } // method: getOutputBasename // bool8 getOutputBasename(String& basename) const { if (getType() == OUTPUT) return dynamic_cast (virtual_algo_d)-> getOutputBasename(basename); else return true; } // method: getOutputExtension // bool8 getOutputExtension(String& extension) const { if (getType() == OUTPUT) return dynamic_cast (virtual_algo_d)-> getOutputExtension(extension); else return true; } // method: getOutputPreserve // int32 getOutputPreserve() const { if (getType() == OUTPUT) return dynamic_cast (virtual_algo_d)-> getOutputPreserve(); else return 0; } // method: getOutputSuffix // bool8 getOutputSuffix(String& suffix) const { if (getType() == OUTPUT) return dynamic_cast (virtual_algo_d)-> getOutputSuffix(suffix); else return true; } // method: getGenSampleFrequency // bool8 getGenSampleFrequency(Float& sf) { if (getType() == GENERATOR) return dynamic_cast (virtual_algo_d)-> getGenSampleFrequency(sf); return true; } // other miscellaneouos get methods: // TYPES getType() const; const String& getCLabelVariable() const; CoefficientLabel::TYPE getCLabelType() const; int32 getContainerGraphTag() const; //--------------------------------------------------------------------------- // // class-specific public methods: // public methods required by the AlgorithmBase interface contract // //--------------------------------------------------------------------------- // assign methods // bool8 assign(const AlgorithmBase& arg); // method: eq // bool8 eq(const AlgorithmBase& arg) const { return virtual_algo_d->eq(arg); } // method: className // const String& className() const { return virtual_algo_d->className(); } // method: init // bool8 init() { return virtual_algo_d->init(); } // method: apply // bool8 apply(Vector& output, const Vector< CircularBuffer >& input); // method: getLeadingPad // int32 getLeadingPad() const { return virtual_algo_d->getLeadingPad(); } // method: getTrailingPad // int32 getTrailingPad() const { return virtual_algo_d->getTrailingPad(); } //--------------------------------------------------------------------------- // // private methods // //--------------------------------------------------------------------------- private: }; // end of include file // #endif