From: jerome l. <jle...@us...> - 2002-05-12 01:12:51
|
Update of /cvsroot/xlw/xlw/xlw In directory usw-pr-cvs1:/tmp/cvs-serv16659 Modified Files: XlfOper.h XlfOper.cpp Log Message: When buffer is full, don't throw any exception, sets lpxloper_ to 0 instead. Changed other method to check for xloper_ Index: XlfOper.h =================================================================== RCS file: /cvsroot/xlw/xlw/xlw/XlfOper.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -r1.6 -r1.7 *** XlfOper.h 5 May 2002 22:44:25 -0000 1.6 --- XlfOper.h 12 May 2002 01:12:48 -0000 1.7 *************** *** 177,181 **** //! Reserves memory in XLL buffer (garbage collected). ! void Allocate(); //! Anticipates deallocation if possible. --- 177,181 ---- //! Reserves memory in XLL buffer (garbage collected). ! int Allocate(); //! Anticipates deallocation if possible. Index: XlfOper.cpp =================================================================== RCS file: /cvsroot/xlw/xlw/xlw/XlfOper.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -r1.7 -r1.8 *** XlfOper.cpp 7 May 2002 02:29:30 -0000 1.7 --- XlfOper.cpp 12 May 2002 01:12:48 -0000 1.8 *************** *** 57,62 **** XlfOper::XlfOper(LPXLOPER lpxloper, bool isExcelData): lpxloper_(lpxloper) { ! if (isExcelData && lpxloper->xltype == xltypeStr) lpxloper_->xltype&=xlbitCallFreeAuxMem; return; } --- 57,70 ---- XlfOper::XlfOper(LPXLOPER lpxloper, bool isExcelData): lpxloper_(lpxloper) { ! if (lpxloper_ == 0) ! return; ! ! int type = lpxloper_->xltype; ! bool isAuxType = (type == xltypeStr || type == xltypeRef || ! type == xltypeMulti || type == xltypeBigData); ! if (isExcelData && isAuxType) ! { lpxloper_->xltype&=xlbitCallFreeAuxMem; + } return; } *************** *** 72,75 **** --- 80,86 ---- XlfOper::~XlfOper() { + if (! lpxloper_) + return; + if (lpxloper_->xltype & xlbitCallFreeAuxMem) { *************** *** 86,90 **** stored by XlfExcel with a call to XlfExcel::GetMemory(). ! \bug Each XlfOper allocation causes a call to Allocate which in turn reserve the necessary number of bytes in the internal buffer. The problem is that even temporary XlfOper used inside the xll function use --- 97,101 ---- stored by XlfExcel with a call to XlfExcel::GetMemory(). ! \warning Each XlfOper allocation causes a call to Allocate which in turn reserve the necessary number of bytes in the internal buffer. The problem is that even temporary XlfOper used inside the xll function use *************** *** 93,104 **** causes a bottleneck if the function uses many temporary XlfOper (see Deallocate()). */ ! void XlfOper::Allocate() { lpxloper_ = (LPXLOPER)XlfExcel::Instance().GetMemory(sizeof(XLOPER)); if (!lpxloper_) ! return; lpxloper_->xltype = xltypeNil; ! return; } --- 104,118 ---- causes a bottleneck if the function uses many temporary XlfOper (see Deallocate()). + + \return \c xlretSuccess or \c xlretInvXloper if no memory is could + be allocated. */ ! int XlfOper::Allocate() { lpxloper_ = (LPXLOPER)XlfExcel::Instance().GetMemory(sizeof(XLOPER)); if (!lpxloper_) ! return xlretInvXloper; lpxloper_->xltype = xltypeNil; ! return xlretSuccess; } *************** *** 134,137 **** --- 148,155 ---- { int xlret; + + if (lpxloper_ == 0) + return xlretInvXloper; + if (lpxloper_->xltype == xltypeInt) { *************** *** 169,172 **** --- 187,194 ---- { int xlret; + + if (lpxloper_ == 0) + return xlretInvXloper; + if (lpxloper_->xltype == xltypeNum) { *************** *** 200,203 **** --- 222,229 ---- { int xlret; + + if (lpxloper_ == 0) + return xlretInvXloper; + if (lpxloper_->xltype == xltypeBool) { *************** *** 234,237 **** --- 260,267 ---- { int xlret; + + if (lpxloper_ == 0) + return xlretInvXloper; + if (lpxloper_->xltype == xltypeStr) { *************** *** 267,270 **** --- 297,304 ---- { int xlret; + + if (lpxloper_ == 0) + return xlretInvXloper; + if (lpxloper_->xltype == xltypeRef) { *************** *** 301,306 **** XlfOper& XlfOper::Set(double value) { ! lpxloper_->xltype = xltypeNum; ! lpxloper_->val.num = value; return *this; } --- 335,343 ---- XlfOper& XlfOper::Set(double value) { ! if (lpxloper_) ! { ! lpxloper_->xltype = xltypeNum; ! lpxloper_->val.num = value; ! } return *this; } *************** *** 308,313 **** XlfOper& XlfOper::Set(short value) { ! lpxloper_->xltype = xltypeInt; ! lpxloper_->val.w = value; return *this; } --- 345,353 ---- XlfOper& XlfOper::Set(short value) { ! if (lpxloper_) ! { ! lpxloper_->xltype = xltypeInt; ! lpxloper_->val.w = value; ! } return *this; } *************** *** 315,352 **** XlfOper& XlfOper::Set(bool value) { ! lpxloper_->xltype = xltypeBool; ! lpxloper_->val.boolean = value; return *this; } XlfOper& XlfOper::Set(const XlfRef& range) { ! lpxloper_->xltype = xltypeRef; ! XLMREF * pmRef = reinterpret_cast<XLMREF *>(XlfExcel::Instance().GetMemory(sizeof(XLMREF))); ! pmRef->count=1; ! pmRef->reftbl[0].rwFirst = range.GetRowBegin(); ! pmRef->reftbl[0].rwLast = range.GetRowEnd()-1; ! pmRef->reftbl[0].colFirst = range.GetColBegin(); ! pmRef->reftbl[0].colLast = range.GetColEnd()-1; ! lpxloper_->val.mref.lpmref = pmRef; ! lpxloper_->val.mref.idSheet = range.GetSheetId(); return *this; } /*! ! \bug String longer than 255 characters are truncated. A warning is issued in debug mode. */ XlfOper& XlfOper::Set(const char *value) { ! lpxloper_->xltype = xltypeStr; ! int n = strlen(value); ! ERR_CHECKW2(n<256,"String too long will be truncated"); ! // One byte more for NULL terminal char (allow use of strcpy) ! // and one for the std::string size (convention used by Excel) ! lpxloper_->val.str = (LPSTR)XlfExcel::Instance().GetMemory(n + 2); ! strcpy(lpxloper_->val.str + 1, value); ! // the number of character include the final \0 or not ? ! lpxloper_->val.str[0] = (BYTE)(n + 1); return *this; } --- 355,425 ---- XlfOper& XlfOper::Set(bool value) { ! if (lpxloper_) ! { ! lpxloper_->xltype = xltypeBool; ! lpxloper_->val.boolean = value; ! } return *this; } + /*! + If no memory can be allocated on xlw internal buffer, the XlfOper is set + to an invalid state and the XlfRef is not copied. + */ XlfOper& XlfOper::Set(const XlfRef& range) { ! if (lpxloper_) ! { ! lpxloper_->xltype = xltypeRef; ! XLMREF * pmRef = reinterpret_cast<XLMREF *>(XlfExcel::Instance().GetMemory(sizeof(XLMREF))); ! // if no memory is available ! if (pmRef == 0) ! { ! // set XlfOper to an invalid state ! lpxloper_=0; ! } ! else ! { ! pmRef->count=1; ! pmRef->reftbl[0].rwFirst = range.GetRowBegin(); ! pmRef->reftbl[0].rwLast = range.GetRowEnd()-1; ! pmRef->reftbl[0].colFirst = range.GetColBegin(); ! pmRef->reftbl[0].colLast = range.GetColEnd()-1; ! lpxloper_->val.mref.lpmref = pmRef; ! lpxloper_->val.mref.idSheet = range.GetSheetId(); ! } ! } return *this; } /*! ! If no memory can be allocated on xlw internal buffer, the XlfOper is set ! to an invalid state and the string is not copied. ! ! \note String longer than 255 characters are truncated. A warning is issued in debug mode. */ XlfOper& XlfOper::Set(const char *value) { ! if (lpxloper_) ! { ! lpxloper_->xltype = xltypeStr; ! int n = strlen(value); ! ERR_CHECKW2(n<256,"String too long will be truncated"); ! // One byte more for NULL terminal char (allow use of strcpy) ! // and one for the std::string size (convention used by Excel) ! LPSTR str = reinterpret_cast<LPSTR>(XlfExcel::Instance().GetMemory(n + 2)); ! if (str == 0) ! { ! lpxloper_=0; ! } ! else ! { ! strcpy(str + 1, value); ! // the number of character include the final \0 or not ? ! lpxloper_->val.str = str; ! lpxloper_->val.str[0] = (BYTE)(n + 1); ! } ! } return *this; } *************** *** 354,359 **** XlfOper& XlfOper::SetError(WORD error) { ! lpxloper_->xltype = xltypeErr; ! lpxloper_->val.err = error; return *this; } --- 427,435 ---- XlfOper& XlfOper::SetError(WORD error) { ! if (lpxloper_) ! { ! lpxloper_->xltype = xltypeErr; ! lpxloper_->val.err = error; ! } return *this; } |