Update of /cvsroot/objecthandler/ObjectHandler/ohxl/Functions
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv3145/ohxl/Functions
Modified Files:
.cvsignore manual.cpp
Log Message:
rename ohParseFields() to ohSplit() and modify behavior:
- no need to specify "DOUBLE/STRING" datatype
- if index omitted, all fields returned as array
Index: .cvsignore
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/ohxl/Functions/.cvsignore,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** .cvsignore 3 Dec 2006 14:35:03 -0000 1.5
--- .cvsignore 3 Dec 2006 21:08:46 -0000 1.6
***************
*** 4,7 ****
garbagecollection.cpp
logging.cpp
! utilities.cpp
valueobjects.cpp
--- 4,7 ----
garbagecollection.cpp
logging.cpp
! ohutils.cpp
valueobjects.cpp
Index: manual.cpp
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/ohxl/Functions/manual.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** manual.cpp 19 Nov 2006 13:08:27 -0000 1.8
--- manual.cpp 3 Dec 2006 21:08:46 -0000 1.9
***************
*** 25,34 ****
#include <ohxl/functioncall.hpp>
#include <ohxl/Functions/functioncount.hpp>
! #include <sstream>
#include <map>
- #include <boost/lexical_cast.hpp>
#define XLL_DEC extern "C"
- #define SET_SESSION_ID
void operToOper(OPER *xTarget, const OPER *xSource) {
--- 25,32 ----
#include <ohxl/functioncall.hpp>
#include <ohxl/Functions/functioncount.hpp>
! //#include <sstream>
#include <map>
#define XLL_DEC extern "C"
void operToOper(OPER *xTarget, const OPER *xSource) {
***************
*** 82,89 ****
return 0;
- // initialize the QuantLib session ID (if enabled)
-
- SET_SESSION_ID
-
// reset the calling cell
--- 80,83 ----
***************
*** 198,212 ****
}
! XLL_DEC OPER *ohParseField(
char *line,
! long *index,
! OPER *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
--- 192,205 ----
}
! XLL_DEC OPER *ohSplit(
char *line,
! OPER *delimOper,
! OPER *index) {
! boost::shared_ptr<ObjHandler::FunctionCall> functionCall;
!
! try {
! functionCall = boost::shared_ptr<ObjHandler::FunctionCall>
! ( new ObjHandler::FunctionCall("ohSplit") );
// reset the calling cell
***************
*** 216,268 ****
// convert the inputs
! std::string typeStr =
! ObjHandler::operToScalar<std::string>(*type, "NUMBER", "type");
!
! std::string delimStr =
! ObjHandler::operToScalar<std::string>(*delim, "[:space:]", "delim");
// 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, 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 OPER xRet;
- 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::scalarToOper(xRet, ret);
- } else if (ObjHandler::uppercase(typeStr) == "STRING") {
ObjHandler::scalarToOper(xRet, fields[i-1]);
} else {
! std::stringstream msg;
! msg << "invalid type specified -"
! << " expected 'NUMBER' or 'STRING' -"
! << " detected '" << type << "'";
! throw ObjHandler::Exception(msg.str());
}
--- 209,243 ----
// convert the inputs
! std::string delim =
! ObjHandler::operToScalar<std::string>(*delimOper, "[:space:]", "delim");
// invoke the utility function
! std::vector<std::string> fields = ObjHandler::split(line, delim);
! static OPER xRet;
! if (index->xltype == xltypeNum) {
! // the user has specified a value for index,
! // so return fields[index] as a scalar string value
!
! OH_REQUIRE(index->val.num > 0, "Error parsing string -" << std::endl
! << line << std::endl << "- index of requested field must be > 0"
! << " - the value supplied was " << index->val.num);
!
! unsigned int i = static_cast<unsigned int>(index->val.num);
!
! OH_REQUIRE(i <= fields.size(),"Error parsing string -" << std::endl
! << line << std::endl << "- requested field index " << i
! << " exceeds #fields (" << fields.size() << ") found in string");
ObjHandler::scalarToOper(xRet, fields[i-1]);
+
} else {
! // the user hasn't specified a valid number for the index,
! // so return all of the fields in the input as a list of strings
!
! ObjHandler::vectorToOper(xRet, fields);
}
|