[ObjectHandler-cvs] ObjectHandler/ohxl conversions.hpp,1.10,1.11
Brought to you by:
ericehlers,
nando
From: Eric E. <eri...@us...> - 2006-09-11 19:50:28
|
Update of /cvsroot/objecthandler/ObjectHandler/ohxl In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv31810/ohxl Modified Files: conversions.hpp Log Message: consolidate conversion code (precursor to loop template changes) Index: conversions.hpp =================================================================== RCS file: /cvsroot/objecthandler/ObjectHandler/ohxl/conversions.hpp,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** conversions.hpp 13 Jul 2006 10:35:39 -0000 1.10 --- conversions.hpp 11 Sep 2006 19:50:23 -0000 1.11 *************** *** 43,48 **** const bool &expandVectors = true); ! template < class T > ! void vectorToXloper(XLOPER &xVector, const std::vector < T > &v) { if (v.empty()) { //xVector.xltype = xltypeNum; --- 43,48 ---- const bool &expandVectors = true); ! template <class T> ! void vectorToXloper(XLOPER &xVector, const std::vector<T> &v) { if (v.empty()) { //xVector.xltype = xltypeNum; *************** *** 68,101 **** } ! template < class T > ! void vectorToXloper(XLOPER &xVector, const std::vector < T > &v, const XLOPER *xInput) { ! // set xVector with contents of v and dimensions of xInput ! ! if (v.empty()) { ! //xVector.xltype = xltypeNum; ! //xVector.val.num = 0; ! xVector.xltype = xltypeErr; ! xVector.val.err = xlerrNA; ! return; ! } ! if (!xInput || xInput->xltype != xltypeMulti) ! throw Exception("vectorToXloper: input parameter is not an array"); ! ! xVector.val.array.columns = xInput->val.array.columns; ! xVector.val.array.rows = xInput->val.array.rows; ! int inputSize = xVector.val.array.columns * xVector.val.array.rows; ! if (inputSize != v.size()) ! throw Exception("vectorToXloper: input array dimensions incompatible with data"); ! xVector.val.array.lparray = new XLOPER[inputSize]; ! if (!xVector.val.array.lparray) ! throw Exception("vectorToXloper: error on call to new"); ! xVector.xltype = xltypeMulti | xlbitDLLFree; ! ! for (unsigned int i=0; i<v.size(); i++) ! scalarToXloper(xVector.val.array.lparray[i], v[i]); ! } ! ! template < class T > ! void matrixToXloper(XLOPER &xMatrix, const std::vector < std::vector < T > > &vv) { if (vv.empty() || vv[0].empty()) { //xMatrix.xltype = xltypeNum; --- 68,73 ---- } ! template <class T> ! void matrixToXloper(XLOPER &xMatrix, const std::vector<std::vector<T> > &vv) { if (vv.empty() || vv[0].empty()) { //xMatrix.xltype = xltypeNum; *************** *** 112,116 **** xMatrix.xltype = xltypeMulti | xlbitDLLFree; for (unsigned int i=0; i<vv.size(); i++) { ! std::vector < T > v = vv[i]; for (unsigned int j=0; j<v.size(); j++) scalarToXloper(xMatrix.val.array.lparray[i * v.size() + j], v[j]); --- 84,88 ---- xMatrix.xltype = xltypeMulti | xlbitDLLFree; for (unsigned int i=0; i<vv.size(); i++) { ! std::vector<T> v = vv[i]; for (unsigned int j=0; j<v.size(); j++) scalarToXloper(xMatrix.val.array.lparray[i * v.size() + j], v[j]); *************** *** 121,132 **** DLL_API void operToScalar(long &ret, const OPER &xScalar, const long &defaultValue = 0); ! DLL_API void operToScalar(double &ret, const OPER &xScalar, const double &defaultValue = 0); DLL_API void operToScalar(bool &ret, const OPER &xScalar, const bool &defaultValue = false); DLL_API void operToScalar(std::string &ret, const OPER &xScalar, const std::string &defaultValue = ""); DLL_API void operToScalar(boost::any &ret, const OPER &xScalar); ! template < class T > ! std::vector < T > fpToVector(const FP &fpVector) { ! std::vector < T > ret; for (int i=0; i<fpVector.rows * fpVector.columns; i++) ret.push_back(fpVector.array[i]); --- 93,104 ---- DLL_API void operToScalar(long &ret, const OPER &xScalar, const long &defaultValue = 0); ! DLL_API void operToScalar(double &ret, const OPER &xScalar, const double &defaultValue = 0.); DLL_API void operToScalar(bool &ret, const OPER &xScalar, const bool &defaultValue = false); DLL_API void operToScalar(std::string &ret, const OPER &xScalar, const std::string &defaultValue = ""); DLL_API void operToScalar(boost::any &ret, const OPER &xScalar); ! template <class T> ! std::vector<T> fpToVector(const FP &fpVector) { ! std::vector<T> ret; for (int i=0; i<fpVector.rows * fpVector.columns; i++) ret.push_back(fpVector.array[i]); *************** *** 134,143 **** } ! template < class T > ! std::vector < T > operToVector(const OPER &xVector) { OPER xTemp; bool needToFree = false; try { ! std::vector < T > ret; if (xVector.xltype & xltypeErr) throw Exception("input value is #NULL (xltypeErr)"); --- 106,115 ---- } ! template <class T> ! std::vector<T> operToVector(const OPER &xVector) { OPER xTemp; bool needToFree = false; try { ! std::vector<T> ret; if (xVector.xltype & xltypeErr) throw Exception("input value is #NULL (xltypeErr)"); *************** *** 174,182 **** } ! template < class T > ! std::vector < std::vector < T > > fpToMatrix(const FP &fpMatrix) { ! std::vector < std::vector < T > > ret; for (int i=0; i<fpMatrix.rows; i++) { ! std::vector < T > row; for (int j=0; j<fpMatrix.columns; j++) row.push_back(fpMatrix.array[i * fpMatrix.columns + j]); --- 146,154 ---- } ! template <class T> ! std::vector<std::vector<T> > fpToMatrix(const FP &fpMatrix) { ! std::vector<std::vector<T> > ret; for (int i=0; i<fpMatrix.rows; i++) { ! std::vector<T> row; for (int j=0; j<fpMatrix.columns; j++) row.push_back(fpMatrix.array[i * fpMatrix.columns + j]); *************** *** 186,195 **** } ! template < class T > ! std::vector < std::vector < T > > operToMatrix(const OPER &xMatrix) { OPER xTemp; bool needToFree = false; try { ! std::vector < std::vector < T > > ret; if (xMatrix.xltype & xltypeErr) throw Exception("input value is #NULL (xltypeErr)"); --- 158,167 ---- } ! template <class T> ! std::vector<std::vector<T> > operToMatrix(const OPER &xMatrix) { OPER xTemp; bool needToFree = false; try { ! std::vector<std::vector<T> > ret; if (xMatrix.xltype & xltypeErr) throw Exception("input value is #NULL (xltypeErr)"); *************** *** 208,212 **** for (int i=0; i<xMulti->val.array.rows; i++) { ! std::vector < T > row; for (int j=0; j<xMulti->val.array.columns; j++) { T value; --- 180,184 ---- for (int i=0; i<xMulti->val.array.rows; i++) { ! std::vector<T> row; for (int j=0; j<xMulti->val.array.columns; j++) { T value; *************** *** 230,346 **** } - // convert excel datatypes to datatypes of underlying library - - template < typename T > - T operToScalarLibrary(const long &arg) { - if (arg) - return T(arg); - else - return T(); - } - - template < typename T > - T operToScalarLibrary(const std::string &arg) { - return T(arg); - } - - template < class T > - T operToScalarLibrary(const OPER &xArg, const long &defaultValue=0) { - long arg; - operToScalar(arg, xArg, defaultValue); - return operToScalarLibrary<T>(arg); - } - - template < class T > - std::vector < T > operToVectorLibrary(const OPER &xVector) { - OPER xTemp; - bool needToFree = false; - try { - std::vector < T > ret; - if (xVector.xltype & xltypeErr) - throw Exception("input value is #NULL (xltypeErr)"); - if (xVector.xltype & (xltypeMissing | xltypeNil)) - return ret; - - const OPER *xMulti; - - if (xVector.xltype == xltypeMulti) - xMulti = &xVector; - else { - Excel(xlCoerce, &xTemp, 2, &xVector, TempInt(xltypeMulti)); - xMulti = &xTemp; - needToFree = true; - } - - for (int i=0; i<xMulti->val.array.rows * xMulti->val.array.columns; i++) - ret.push_back(operToScalarLibrary<T>(xMulti->val.array.lparray[i])); - - if (needToFree) - Excel(xlFree, 0, 1, &xTemp); - - return ret; - } catch (const std::exception &e) { - if (needToFree) - Excel(xlFree, 0, 1, &xTemp); - std::ostringstream msg; - msg << "operToVectorLibrary: " << e.what(); - throw Exception(msg.str()); - } - } - - template < class T > - std::vector < T > operToVectorLibrary(const FP &fpVector) { - std::vector < T > ret; - for (int i=0; i<fpVector.rows * fpVector.columns; i++) - ret.push_back(operToScalarLibrary<T>(fpVector.array[i])); - return ret; - } - - // convert excel types to enumerations - - template < typename T, typename EnumRegistry > - T operToScalarEnum(const OPER &xScalar, const std::string &defaultValue="") { - std::string id; - operToScalar(id, xScalar, defaultValue); - return EnumRegistry()(id); - } - - template < typename T, typename EnumRegistry > - std::vector < T > operToVectorEnum(const OPER &xVector) { - std::vector < T > ret; - OPER xTemp; - bool needToFree = false; - try { - if (xVector.xltype & xltypeErr) - throw Exception("input value is #NULL (xltypeErr)"); - if (xVector.xltype & (xltypeMissing | xltypeNil)) - return ret; - - const OPER *xMulti; - - if (xVector.xltype == xltypeMulti) - xMulti = &xVector; - else { - Excel(xlCoerce, &xTemp, 2, &xVector, TempInt(xltypeMulti)); - xMulti = &xTemp; - needToFree = true; - } - - for (int i=0; i<xMulti->val.array.rows * xMulti->val.array.columns; i++) - ret.push_back(operToScalarEnum<T, EnumRegistry>(xMulti->val.array.lparray[i])); - - if (needToFree) - Excel(xlFree, 0, 1, &xTemp); - - return ret; - } catch (const std::exception &e) { - if (needToFree) - Excel(xlFree, 0, 1, &xTemp); - std::ostringstream msg; - msg << "operToVector: " << e.what(); - throw Exception(msg.str()); - } - } - } --- 202,205 ---- |