Update of /cvsroot/objecthandler/ObjectHandler/gensrc/stubs
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv4318/gensrc/stubs
Modified Files:
stub.excel.exports stub.excel.includes stub.excel.register
stub.excel.unregister
Log Message:
revised processing for ohParseFields()
Index: stub.excel.exports
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/gensrc/stubs/stub.excel.exports,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** stub.excel.exports 14 Jun 2006 13:15:25 -0000 1.2
--- stub.excel.exports 3 Jul 2006 08:19:26 -0000 1.3
***************
*** 4,7 ****
--- 4,8 ----
#pragma comment (linker, "/export:_ohPack")
+ #pragma comment (linker, "/export:_ohParseField")
%s
Index: stub.excel.register
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/gensrc/stubs/stub.excel.register,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** stub.excel.register 16 Jun 2006 16:15:31 -0000 1.3
--- stub.excel.register 3 Jul 2006 08:19:26 -0000 1.4
***************
*** 17,20 ****
--- 17,34 ----
TempStrNoSize("\x1D""range of cells to be packed ")); // description of parameter 1
+ Excel(xlfRegister, 0, 13, &xDll,
+ TempStrNoSize("\x0C""ohParseField"), // function code name
+ TempStrNoSize("\x05""RCNC#"), // parameter codes
+ TempStrNoSize("\x0C""ohParseField"), // function display name
+ TempStrNoSize("\x0F""line,index,type"), // 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("\x23""required datatype (string/number) ")); // description of parameter 3
+
}
Index: stub.excel.unregister
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/gensrc/stubs/stub.excel.unregister,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** stub.excel.unregister 16 Jun 2006 16:15:31 -0000 1.3
--- stub.excel.unregister 3 Jul 2006 08:19:26 -0000 1.4
***************
*** 9,14 ****
XLOPER xlRegID;
- %(xlunregister)s
-
Excel(xlfRegister, 0, 11, &xDll,
TempStrNoSize("\x06""ohPack"), // function code name
--- 9,12 ----
***************
*** 26,29 ****
--- 24,50 ----
TempStrNoSize("\x06""ohPack")); // function code name
+ Excel4(xlfUnregister, 0, 1, &xlRegID);
+
+ Excel(xlfRegister, 0, 13, &xDll,
+ TempStrNoSize("\x0C""ohParseField"), // function code name
+ TempStrNoSize("\x05""RCNC#"), // parameter codes
+ TempStrNoSize("\x0C""ohParseField"), // function display name
+ TempStrNoSize("\x0F""line,index,type"), // 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("\x23""required datatype (string/number) ")); // description of parameter 3
+
+ Excel4(xlfRegisterId, &xlRegID, 2, &xDll,
+ TempStrNoSize("\x0C""ohParseField")); // function code name
+
+ Excel4(xlfUnregister, 0, 1, &xlRegID);
+
+ %(xlunregister)s
+
}
Index: stub.excel.includes
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/gensrc/stubs/stub.excel.includes,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** stub.excel.includes 14 Jun 2006 13:15:25 -0000 1.3
--- stub.excel.includes 3 Jul 2006 08:19:26 -0000 1.4
***************
*** 6,9 ****
--- 6,10 ----
#include <sstream>
#include <map>
+ #include <boost/lexical_cast.hpp>
#define XLL_DEC extern "C"
***************
*** 11,16 ****
// FIXME some temporary workarounds for shortcomings in gensrc
- #define SET_SESSION_ID
-
namespace ObjHandler {
--- 12,15 ----
***************
*** 22,25 ****
--- 21,26 ----
}
+ #define SET_SESSION_ID
+
int countValidRows(const XLOPER &xMulti) {
for (int numValidRows=xMulti.val.array.rows; numValidRows; numValidRows--) {
***************
*** 103,104 ****
--- 104,174 ----
}
+ XLL_DEC XLOPER *ohParseField(
+ char *line,
+ long *index,
+ char *type) {
+ 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
+
+ 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);
+ 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;
+ }
+ }
|