// file: $isip/class/algo/Math/math_04.cc // version: $Id: math_04.cc 6907 2001-05-02 16:43:54Z duncan $ // // isip include files // #include "Math.h" // method: sofSize // // arguments: none // // return: size of object // // this method return the size of the object // int32 Math::sofSize() const { // start with enough space for the type // int32 bytes = 0; // add the size of the algorithm and function // bytes += ALGO_MAP.elementSofSize(); // add the size of num, specification vector, constant and debug // level // bytes += num_operands_d.sofSize(); bytes += function_d.sofSize(); bytes += operation_d.sofSize(); bytes += weight_d.sofSize(); bytes += const_d.sofSize(); bytes += debug_level_d.sofSize(); // add the space required for the implementation name // bytes += IMPL_MAP.elementSofSize(); // return the size // return bytes; } // method: write // // arguments: // Sof& sof: (input) sof file object // int32 tag: (input) sof object instance tag // const String& name: (input) sof object instance name // // return: a bool8 value indicating status // // this method has the object write itself to an Sof file // bool8 Math::write(Sof& sof_a, int32 tag_a, const String& name_a) const { // declare local variables // int32 obj_size = 0; // write the instance of the object into the Sof file // if (sof_a.isText()) { obj_size = Sof::ANY_SIZE; } else { 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: writeData // // arguments: // Sof& sof: (input) sof file object // const String& pname: (input) parameter name // // return: a bool8 value indicating status // // this method has the object writes itself from an Sof file. it assumes // that the Sof file is already positioned correctly. // bool8 Math::writeData(Sof& sof_a, const String& pname_a) const { // declare local variables // bool8 status = false; // write a start string if necessary // sof_a.writeLabelPrefix(pname_a); // write the algorithm type // ALGO_MAP.writeElementData(sof_a, PARAM_ALGORITHM, (int32)algorithm_d); // check known algorithms // if (algorithm_d == FUNCTION_CALCULATOR) { status = writeDataCommon(sof_a, pname_a); } else { return Error::handle(name(), L"writeData", ERR_UNKALG, __FILE__, __LINE__); } // put an end string if necessary // sof_a.writeLabelSuffix(pname_a); // exit gracefully // return status; } // method: writeDataCommon // // arguments: // Sof& sof: (input) sof file object // const String& pname: (input) parameter name // // return: a bool8 value indicating status // // this method has been implemented for FUNCTION_CALCULATOR algorithm // and writes data to a file for several algorithms that share the // same parameters. // bool8 Math::writeDataCommon(Sof& sof_a, const String& pname_a) const { // write the implementation type // IMPL_MAP.writeElementData(sof_a, PARAM_IMPLEMENTATION, (int32)implementation_d); // write the number of combinations // num_operands_d.writeData(sof_a, PARAM_NUMBER); // write the constant // const_d.writeData(sof_a, PARAM_CONST); // write function and operation. for text mode, we create and write // out a String. for binary mode we stay with the VectorLong // if (sof_a.isText()) { String str; getFunction(str); str.writeData(sof_a, PARAM_FUNCTION); getOperation(str); str.writeData(sof_a, PARAM_OPERATION); } else { function_d.writeData(sof_a, PARAM_FUNCTION); operation_d.writeData(sof_a, PARAM_OPERATION); } // write weight // weight_d.writeData(sof_a, PARAM_WEIGHT); // write the debug level // debug_level_d.writeData(sof_a, PARAM_DBGL); // exit gracefully // return true; }