Update of /cvsroot/objecthandler/ObjectHandler/gensrc/stubs
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv31124/gensrc/stubs
Modified Files:
stub.excel.exports stub.excel.includes stub.excel.xladdin
Log Message:
cleaner implementation for ohPack/ohParseFields
Index: stub.excel.exports
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/gensrc/stubs/stub.excel.exports,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** stub.excel.exports 3 Jul 2006 08:19:26 -0000 1.3
--- stub.excel.exports 3 Oct 2006 09:32:37 -0000 1.4
***************
*** 3,6 ****
--- 3,8 ----
#define ohxl_export_hpp
+ #pragma comment (linker, "/export:_ohDependsOn")
+ #pragma comment (linker, "/export:_ohFunctionCount")
#pragma comment (linker, "/export:_ohPack")
#pragma comment (linker, "/export:_ohParseField")
Index: stub.excel.includes
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/gensrc/stubs/stub.excel.includes,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** stub.excel.includes 12 Jul 2006 14:02:22 -0000 1.5
--- stub.excel.includes 3 Oct 2006 09:32:37 -0000 1.6
***************
*** 5,180 ****
#include <ohxl/functioncall.hpp>
#include <sstream>
- #include <map>
- #include <boost/lexical_cast.hpp>
#define XLL_DEC extern "C"
-
- // FIXME some temporary workarounds for shortcomings in gensrc
-
- namespace ObjHandler {
-
- long dependsOn() {
- static std::map < std::string, long > iterators;
- return iterators[ObjHandler::FunctionCall::instance().getAddressString()]++;
- }
-
- }
-
#define SET_SESSION_ID
- int countValidRows(const XLOPER &xMulti) {
- for (int numValidRows=xMulti.val.array.rows; numValidRows; numValidRows--) {
- for (int i=0; i<xMulti.val.array.columns; i++) {
- int index = (numValidRows - 1) * xMulti.val.array.columns + i;
- if (!(xMulti.val.array.lparray[index].xltype & (xltypeErr | xltypeNil)))
- return numValidRows;
- }
- }
- return 1;
- }
-
- int countValidCols(const XLOPER &xMulti) {
- for (int numValidCols=xMulti.val.array.columns; numValidCols; numValidCols--) {
- for (int i=0; i<xMulti.val.array.rows; i++) {
- int index = (numValidCols - 1) + i * xMulti.val.array.columns;
- if (!(xMulti.val.array.lparray[index].xltype & (xltypeErr | xltypeNil)))
- return numValidCols;
- }
- }
- return 1;
- }
-
- XLL_DEC XLOPER *ohPack(OPER *xInputRange) {
-
- boost::shared_ptr < ObjHandler::FunctionCall > functionCall;
- XLOPER xMulti;
- static XLOPER xRet;
- xRet.val.array.lparray = 0;
-
- try {
- functionCall = boost::shared_ptr < ObjHandler::FunctionCall >
- ( new ObjHandler::FunctionCall("ohPack") );
-
- Excel(xlCoerce, &xMulti, 2, xInputRange, TempInt(xltypeMulti));
-
- int numValidRows = countValidRows(xMulti);
- int numValidCols = countValidCols(xMulti);
-
- xRet.val.array.rows = numValidRows;
- xRet.val.array.columns = numValidCols;
- xRet.val.array.lparray = new XLOPER[numValidRows * numValidCols];
- if (!xRet.val.array.lparray)
- throw ObjHandler::Exception("ohPack: error on call to new");
- xRet.xltype = xltypeMulti | xlbitDLLFree;
-
- for (int i=0; i<numValidRows; i++) {
- for (int j=0; j<numValidCols; j++) {
- int indexSource = i * xMulti.val.array.columns + j;
- int indexTarget = i * numValidCols + j;
- ObjHandler::operToOper(&xRet.val.array.lparray[indexTarget],
- &xMulti.val.array.lparray[indexSource]);
- }
- }
-
- Excel(xlFree, 0, 1, &xMulti);
- return &xRet;
- } catch (const std::exception &e) {
-
- // free any memory that may have been allocated
-
- Excel(xlFree, 0, 1, &xMulti);
-
- if (xRet.xltype & xltypeMulti && xRet.val.array.lparray) {
- for (int i=0; i<xRet.val.array.columns * xRet.val.array.rows; i++) {
- if (xRet.val.array.lparray[i].xltype & xltypeStr && xRet.val.array.lparray[i].val.str)
- delete [] xRet.val.array.lparray[i].val.str;
- }
- delete [] xRet.val.array.lparray;
- }
-
- // log the exception and return a null pointer (#NUM!) to Excel
-
- std::ostringstream err;
- err << "ohPack - ";
- if (functionCall) err << functionCall->getAddressString() << " - ";
- err << e.what();
- ObjHandler::logMessage(err.str(), 2);
- return 0;
- }
- }
-
- XLL_DEC XLOPER *ohParseField(
- char *line,
- long *index,
- char *type,
- OPER *delim) {
- boost::shared_ptr < ObjHandler::FunctionCall > functionCall;
- try {
- functionCall = boost::shared_ptr < ObjHandler::FunctionCall >
- ( new ObjHandler::FunctionCall("ohParseField") );
-
- SET_SESSION_ID
-
- // reset the calling cell
-
- ObjHandler::ObjectHandlerXL::instance().resetCaller();
-
- // invoke the utility function
-
- std::string delimStr;
- ObjHandler::operToScalar(delimStr, *delim, "[:space:]");
-
- if (*index<1) {
- std::stringstream msg;
- msg << "the index of the requested field - " << *index
- << " - is invalid - minimum value is 1.";
- throw ObjHandler::Exception(msg.str());
- }
- unsigned int i = static_cast<unsigned int>(*index);
-
- std::vector<std::string> fields = ObjHandler::split(line, i, delimStr);
-
- if (i>fields.size()) {
- std::stringstream msg;
- msg << "Error parsing string -" << std::endl
- << line << std::endl << "- requested field index " << i
- << " exceeds #fields (" << fields.size() << ") found in string";
- throw ObjHandler::Exception(msg.str());
- }
-
- static XLOPER xRet;
- std::string typeStr(type);
- if (typeStr.empty() || ObjHandler::uppercase(typeStr) == "NUMBER") {
- double ret;
- try {
- ret = boost::lexical_cast<double>(fields[i-1]);
- } catch (boost::bad_lexical_cast &) {
- std::stringstream msg;
- msg << "Error parsing string -" << std::endl
- << line << std::endl << "- the requested field #" << i
- << " comprising text '" << fields[i-1]
- << "' could not be converted to a number";
- throw ObjHandler::Exception(msg.str());
- }
- ObjHandler::scalarToXloper(xRet, ret);
- } else if (ObjHandler::uppercase(typeStr) == "STRING") {
- ObjHandler::scalarToXloper(xRet, fields[i-1]);
- } else {
- std::stringstream msg;
- msg << "invalid type specified -"
- << " expected 'NUMBER' or 'STRING' -"
- << " detected '" << type << "'";
- throw ObjHandler::Exception(msg.str());
- }
-
- return &xRet;
-
- } catch (const std::exception &e) {
- std::ostringstream err;
- err << "ohParseField - ";
- if (functionCall) err << functionCall->getAddressString() << " - ";
- err << e.what();
- ObjHandler::logMessage(err.str(), 2);
- return 0;
- }
- }
--- 5,10 ----
Index: stub.excel.xladdin
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/gensrc/stubs/stub.excel.xladdin,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** stub.excel.xladdin 2 Oct 2006 15:39:04 -0000 1.1
--- stub.excel.xladdin 3 Oct 2006 09:32:37 -0000 1.2
***************
*** 16,46 ****
%(registerFunctions)s
- Excel(xlfRegister, 0, 11, &xDll,
- TempStrNoSize("\x06""ohPack"), // function code name
- TempStrNoSize("\x03""RP#"), // parameter codes
- TempStrNoSize("\x06""ohPack"), // function display name
- TempStrNoSize("\x10""inputRange"), // comma-delimited list of parameter names
- TempStrNoSize("\x01""1"), // function type (1 = worksheet function)
- TempStrNoSize("\x0D""ObjectHandler"), // function category
- TempStrNoSize("\x00"""), // shortcut text (command macros only)
- TempStrNoSize("\x00"""), // path to help file
- TempStrNoSize("\x3D""trim #ERR/empty values from bottom/right edges of input range"), // function description
- TempStrNoSize("\x1D""range of cells to be packed ")); // description of parameter 1
-
- Excel(xlfRegister, 0, 14, &xDll,
- TempStrNoSize("\x0C""ohParseField"), // function code name
- TempStrNoSize("\x06""RCNCP#"), // parameter codes
- TempStrNoSize("\x0C""ohParseField"), // function display name
- TempStrNoSize("\x19""line,index,type,delimiter"), // comma-delimited list of parameter names
- TempStrNoSize("\x01""1"), // function type (1 = worksheet function)
- TempStrNoSize("\x0D""ObjectHandler"), // function category
- TempStrNoSize("\x00"""), // shortcut text (command macros only)
- TempStrNoSize("\x00"""), // path to help file
- TempStrNoSize("\x41""Extract the ith number from a whitespace-delimited list of fields"), // function description
- TempStrNoSize("\x11""text to be parsed"), // description of parameter 1
- TempStrNoSize("\x20""index (1-based) of desired field"), // description of parameter 2
- TempStrNoSize("\x21""required datatype (string/number)"), // description of parameter 3
- TempStrNoSize("\x29""field delimiter (default is whitespace) ")); // description of parameter 3
-
Excel(xlFree, 0, 1, &xDll);
return 1;
--- 16,19 ----
***************
*** 70,110 ****
%(registerFunctions)s
- Excel(xlfRegister, 0, 11, &xDll,
- TempStrNoSize("\x06""ohPack"), // function code name
- TempStrNoSize("\x03""RP#"), // parameter codes
- TempStrNoSize("\x06""ohPack"), // function display name
- TempStrNoSize("\x10""inputRange"), // comma-delimited list of parameter names
- TempStrNoSize("\x01""0"), // function type (0 = hidden function)
- TempStrNoSize("\x0D""ObjectHandler"), // function category
- TempStrNoSize("\x00"""), // shortcut text (command macros only)
- TempStrNoSize("\x00"""), // path to help file
- TempStrNoSize("\x3D""trim #ERR/empty values from bottom/right edges of input range"), // function description
- TempStrNoSize("\x1D""range of cells to be packed ")); // description of parameter 1
-
- Excel4(xlfRegisterId, &xlRegID, 2, &xDll,
- TempStrNoSize("\x06""ohPack")); // function code name
-
- Excel4(xlfUnregister, 0, 1, &xlRegID);
-
- Excel(xlfRegister, 0, 14, &xDll,
- TempStrNoSize("\x0C""ohParseField"), // function code name
- TempStrNoSize("\x06""RCNCP#"), // parameter codes
- TempStrNoSize("\x0C""ohParseField"), // function display name
- TempStrNoSize("\x19""line,index,type,delimiter"), // comma-delimited list of parameter names
- TempStrNoSize("\x01""0"), // function type (0 = hidden function)
- TempStrNoSize("\x0D""ObjectHandler"), // function category
- TempStrNoSize("\x00"""), // shortcut text (command macros only)
- TempStrNoSize("\x00"""), // path to help file
- TempStrNoSize("\x41""Extract the ith number from a whitespace-delimited list of fields"), // function description
- TempStrNoSize("\x11""text to be parsed"), // description of parameter 1
- TempStrNoSize("\x20""index (1-based) of desired field"), // description of parameter 2
- TempStrNoSize("\x21""required datatype (string/number)"), // description of parameter 3
- TempStrNoSize("\x29""field delimiter (default is whitespace) ")); // description of parameter 3
-
- Excel4(xlfRegisterId, &xlRegID, 2, &xDll,
- TempStrNoSize("\x0C""ohParseField")); // function code name
-
- Excel4(xlfUnregister, 0, 1, &xlRegID);
-
Excel(xlFree, 0, 1, &xDll);
--- 43,46 ----
|