📄 circulardelayline.h
字号:
}//---------------------------------------------------------------------//// required debug methods////----------------------------------------------------------------------// method: debug//// arguments:// const unichar* message: (input) information message//// return: a boolean value indicating status//// this method dumps the contents of an object to the console// template<class TObject>boolean CircularDelayLine<TObject>::debug(const unichar* message_a) const { // local variables // String output; String value; String param; // output the current position // value.assign(index_d); output.debugStr(name(), message_a, L"index_d", value); Console::put(output); // output the debug level // value.assign(debug_level_d); output.debugStr(name(), message_a, L"debug_level_d", value); Console::put(output); // output a label // output.assign(L"delay line:"); Console::put(output); // increment the indention level in the console // Console::increaseIndention(); // output the delay line // v_d.debug(L"v_d"); // decrement the indention level in the console // Console::decreaseIndention(); // exit gracefully // return true;}//-----------------------------------------------------------------------//// default constructor////-----------------------------------------------------------------------// method: default constructor//// arguments:// long length: (input) the length of the buffer//// return: none//// note that the "capacity" and length are the same for this class.//template<class TObject>CircularDelayLine<TObject>::CircularDelayLine(long length_a) { // initialize the stored item // v_d.setLength(length_a); // initialize the position indices // index_d = DEF_INDEX; // exit gracefully //}//-----------------------------------------------------------------------//// required assign method(s)////-----------------------------------------------------------------------// method: assign//// arguments:// const CircularDelayLine<TObject>& arg: (input) the object to copy//// return: a boolean value indicating status//template<class TObject>booleanCircularDelayLine<TObject>::assign(const CircularDelayLine<TObject>& arg_a) { // assign the scalar data // index_d = arg_a.index_d; // assign the vector data // return v_d.assign(arg_a.v_d);}//-----------------------------------------------------------------------//// required i/o methods////-----------------------------------------------------------------------// method: read//// arguments:// Sof& sof: (input) sof file object// long tag: (input) sof object instance tag// const String& name: (input) sof object instance name//// return: a boolean value indicating status//// this method has the object read itself from an Sof file//template<class TObject>boolean CircularDelayLine<TObject>::read(Sof& sof_a, long tag_a, const String& name_a) { // get the instance of the object from the Sof file // if (!sof_a.find(name_a, tag_a)) { return false; } // read the actual data from the sof file // if (!readData(sof_a)) { return false; } // exit gracefully // return true;}// method: write//// arguments:// Sof& sof: (input) sof file object// long tag: (input) sof object instance tag// const String& name: (input) sof object instance name//// return: a boolean value indicating status//// this method has the object write itself to an Sof file//template<class TObject>boolean CircularDelayLine<TObject>::write(Sof& sof_a, long tag_a, const String& name_a) const { // declare a temporary size variable // long obj_size; // switch on ascii or binary mode // if (sof_a.isText()) { // set the size to be dynamic // obj_size = Sof::ANY_SIZE; } else { // the size of the binary data to write // obj_size = sofSize(); } // put the object into the sof file's index // if (!sof_a.put(name_a, tag_a, obj_size)) { return false; } // exit gracefully // return writeData(sof_a);}// method: readData//// arguments:// Sof& sof: (input) sof file object// const String& pname: (input) parameter name// long size: (input) size of the object// boolean param: (input) is the parameter specified?// boolean nested: (input) is this nested?//// return: a boolean value indicating status//// this method has the object read itself from an Sof file. it assumes// that the Sof file is already positioned correctly.//template<class TObject>boolean CircularDelayLine<TObject>::readData(Sof& sof_a, const String& pname_a, long size_a, boolean param_a, boolean nested_a) { // declare local variable // SofParser parser; parser.setDebug(debug_level_d); // ignore implicit parameter setting // // configure the parser to read a nested object // if (nested_a) { parser.setNest(); } // load the parse // if (!parser.load(sof_a, size_a)) { return Error::handle(name(), L"readData", Error::READ, __FILE__, __LINE__, Error::WARNING); } // get the index // if (parser.isPresent(sof_a, PARAM_INDEX)) { if (!index_d.readData(sof_a, PARAM_INDEX, parser.getEntry(sof_a, PARAM_INDEX), false, false)) { return Error::handle(name(), L"readData", Error::READ, __FILE__, __LINE__, Error::WARNING); } } else { index_d = DEF_INDEX; } // get the buffer // if (parser.isPresent(sof_a, PARAM_BUFFER)) { if (!v_d.readData(sof_a, PARAM_BUFFER, parser.getEntry(sof_a, PARAM_BUFFER), false, false)) { return Error::handle(name(), L"readData", Error::READ, __FILE__, __LINE__, Error::WARNING); } } else { v_d.clear(); } // exit gracefully // return true;}// method: writeData//// arguments:// Sof& sof: (input) sof file object// const String& pname: (input) parameter name//// return: a boolean value indicating status//// this method writes the object to the Sof file. it assumes that the// Sof file is already positioned correctly.//template<class TObject>boolean CircularDelayLine<TObject>::writeData(Sof& sof_a, const String& pname_a) const { // write a start string if necessary // sof_a.writeLabelPrefix(pname_a); // write the index // index_d.writeData(sof_a, PARAM_INDEX); // write the buffer // v_d.writeData(sof_a, PARAM_BUFFER); // put an end string if necessary // sof_a.writeLabelSuffix(pname_a); // exit gracefully // return true;}//------------------------------------------------------------------------//// required equality methods////------------------------------------------------------------------------// method: eq//// arguments:// const CircularDelayLine<TObject>& arg: (input) the object to compare//// return: boolean value indicating status//// this method compares two CircularDelayLines for equivalence. two// CircularDelayLines are equivalent if all corresponding valid items are// equivalent//template<class TObject>booleanCircularDelayLine<TObject>::eq(const CircularDelayLine<TObject>& arg_a) const { // compare positions // if (index_d != arg_a.index_d) { return false; } // loop over all elements // long i_end = v_d.length(); for (long i = 0; i < i_end; i++) { if (v_d(i) != arg_a.v_d(i)) { return false; } } // equal, exit gracefully // return true;}//---------------------------------------------------------------------------//// private methods////---------------------------------------------------------------------------// method: wrap//// arguments:// long value: (input) unwrapped location//// return: a long value containing the wrapped pointer//// this method limits a location to the range [0, length]// template<class TObject>long CircularDelayLine<TObject>::wrap(const long value_a) const { // fetch the length // long len = v_d.length(); // compute the modulus // long tmp = value_a % len; // also wrap negative values // if (tmp < 0) { tmp += len; } // exit gracefully // return tmp;}// end of include file//#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -