// file: $isip/class/sp/Component/Component.h // version: $Id: Component.h 9257 2003-07-01 01:31:13Z gao $ // // make sure definitions are only made once // #ifndef ISIP_COMPONENT #define ISIP_COMPONENT #ifndef ISIP_STRING #include #endif #ifndef ISIP_LONG #include #endif #ifndef ISIP_VECTOR #include #endif #ifndef ISIP_ALGORITHM #include #endif // Component: signal flow graphs in isip_transform are represented // using a graph of algorithm objects. this class is used to represent // a block in this graph. a related class, Recipe, is used to // represent the entire graph (as a graph of Component objects). // class Component { //--------------------------------------------------------------------------- // // public constants // //--------------------------------------------------------------------------- public: // define the class name // static const String CLASS_NAME; //---------------------------------------- // // i/o related constants // //---------------------------------------- static const String DEF_PARAM; static const String PARAM_INPUT_NAMES; static const String PARAM_OUTPUT_NAME; static const String PARAM_COMPONENT; //---------------------------------------- // // default values and arguments // //---------------------------------------- // define the default value(s) of the class data // static const Char DELIM; //---------------------------------------- // // error codes // //---------------------------------------- static const int32 ERR = 80100; //--------------------------------------------------------------------------- // // protected data // //--------------------------------------------------------------------------- protected: // start with this data: // note that each component can have multiple inputs and one output. // Vector input_names_d; Vector input_offsets_d; // go through this transformation // Algorithm algo_d; // end up with this data: // note that each component can have only one output. // String output_name_d; // debug level // static Integral::DEBUG debug_level_d; // 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); // debug methods // setDebug is inherited from base class // bool8 debug(const unichar* msg) const; // destructor/constructor(s) // // method: destructor // ~Component() {} // method: default constructor // Component() {} // method: copy constructor // Component(const Component& arg) { assign(arg); } // method: assign // bool8 assign(const Component& arg) { return (input_names_d.assign(arg.input_names_d) && input_offsets_d.assign(arg.input_offsets_d) && output_name_d.assign(arg.output_name_d) && algo_d.assign(arg.algo_d)); } // 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 Component& arg) const { return (input_names_d.eq(arg.input_names_d) && input_offsets_d.eq(arg.input_offsets_d) && output_name_d.eq(arg.output_name_d) && algo_d.eq(arg.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) { return (input_names_d.clear(ctype) && input_offsets_d.clear(ctype) && output_name_d.clear(ctype) && algo_d.clear(ctype)); } //--------------------------------------------------------------------------- // // class-specific public methods: // set methods // //--------------------------------------------------------------------------- // method: setAlgorithm // bool8 setAlgorithm(const Algorithm& arg) { return algo_d.assign(arg); } // method: setInputName // bool8 setInputName(const String& str); // other methods to set the input name: // bool8 setInputName(int32 index, const String& str); // method: setOutputName // bool8 setOutputName(const String& oname) { return output_name_d.assign(oname); } // method: setSampleFrequency // bool8 setSampleFrequency(float32 sf) { return algo_d.setSampleFrequency(sf); } // method: setFrameDuration // bool8 setFrameDuration(float32 dur) { return algo_d.setFrameDuration(dur); } // method: setLeftoverSamps // bool8 setLeftoverSamps(int32 dur) { return algo_d.setLeftoverSamps(dur); } // method: setFrameIndex // bool8 setFrameIndex(int32 index) { return algo_d.setFrameIndex(index); } // method: setSignalDuration // bool8 setSignalDuration(float32 dur) { return algo_d.setSignalDuration(dur); } // method: setInputFilename // bool8 setInputFilename(Filename& basename) { return algo_d.setInputFilename(basename); } // method: setOutputDirectory // bool8 setOutputDirectory(String& new_dir) { return algo_d.setOutputDirectory(new_dir); } // method: setOutputBasename // bool8 setOutputBasename(String& basename) { return algo_d.setOutputBasename(basename); } // method: setOutputExtension // bool8 setOutputExtension(String& extension) { return algo_d.setOutputExtension(extension); } // method: setOutputPreserve // bool8 setOutputPreserve(int32 new_pres_level) { return algo_d.setOutputPreserve(new_pres_level); } // method: setOutputSuffix // bool8 setOutputSuffix(String& suffix) { return algo_d.setOutputSuffix(suffix); } // method: setOutputType // bool8 setOutputType(File::TYPE& type) { return algo_d.setOutputType(type); } //--------------------------------------------------------------------------- // // class-specific public methods: // get methods // //--------------------------------------------------------------------------- // method: getAlgorithm // const Algorithm& getAlgorithm() const { return algo_d; } // method: getInputName // const String& getInputName(int32 index) const { return input_names_d(index); } // method: getOutputName // const String& getOutputName() const { return output_name_d; } // method: getInputOffset // int32 getInputOffset(int32 index) const { return input_offsets_d(index); } // method: getNumInputs // int32 getNumInputs() const { return input_names_d.length(); } // method: isInput // bool8 isInput(const Component& arg) const { return input_names_d.contains(&(arg.getOutputName())); } // method: isCoefficientLabel // bool8 isCoefficientLabel() const { return (algo_d.getType() == Algorithm::COEFFICIENT_LABEL); } // method: isCoefficientLabel // bool8 isCoefficientLabel(CoefficientLabel::TYPE arg) const { return ((algo_d.getType() == Algorithm::COEFFICIENT_LABEL) && (algo_d.getCLabelType() == arg)); } // method: getGenSampleFrequency // bool8 getGenSampleFrequency(Float& sf) { return algo_d.getGenSampleFrequency(sf); } //--------------------------------------------------------------------------- // // class-specific public methods: // methods related to the algo/AlgorithmBase interface contract // //--------------------------------------------------------------------------- // method: init // bool8 init() { return algo_d.init(); } // method: apply // bool8 apply(Vector& output, const Vector< CircularBuffer >& input) { return algo_d.apply(output, input); } // configuration methods dealing with multiframe computations // // method: getLeadingPad // int32 getLeadingPad() const { return algo_d.getLeadingPad(); } // method: getTrailingPad // int32 getTrailingPad() const { return algo_d.getTrailingPad(); } // special getInputFilename method to get the input filename from // Constant class // // method: getInputFilename // bool8 const getInputFilename(String& filename) const { return algo_d.getInputFilename(filename); } // special getOutputFilename method to get the output filename from // Output or Constant class // // method: getOutputFilename // bool8 const getOutputFilename(String& filename) const { return algo_d.getOutputFilename(filename); } //--------------------------------------------------------------------------- // // private methods // //--------------------------------------------------------------------------- private: // methods to manipulate names // bool8 splitName(String& base_name, Long& offset, const String& str) const; bool8 joinName(String& output) const; }; // end of include file // #endif