Update of /cvsroot/objecthandler/ObjectHandler/ohxl
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv22074/ohxl
Modified Files:
callingrange.cpp callingrange.hpp objecthandlerxl.cpp
objecthandlerxl.hpp
Log Message:
1) case-preserving ObjectID behaviour implemented with just
one map using the case insensitive comparison functor iless
2) use iterator post-increment to deal with erase invalidation effect
3) clearPermanent() and clearAll() merged into clearResidentObjects(bool deletePermanent)
Index: objecthandlerxl.cpp
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/ohxl/objecthandlerxl.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** objecthandlerxl.cpp 16 Nov 2006 12:38:40 -0000 1.22
--- objecthandlerxl.cpp 2 Jan 2007 16:36:19 -0000 1.23
***************
*** 1,4 ****
--- 1,5 ----
/*
+ Copyright (C) 2007 Ferdinando Ametrano
Copyright (C) 2005, 2006 Eric Ehlers
***************
*** 34,37 ****
--- 35,40 ----
#include <limits.h>
+ using std::string;
+
namespace ObjHandler {
***************
*** 40,45 ****
// std::map cannot be exported across DLL boundaries
// so instead we use a static variable
! std::map<std::string, boost::shared_ptr<CallingRange> > callingRanges_;
! typedef std::map<std::string, boost::shared_ptr<CallingRange> >::const_iterator rangeMapIter;
ObjectHandlerXL &ObjectHandlerXL::instance() {
--- 43,48 ----
// std::map cannot be exported across DLL boundaries
// so instead we use a static variable
! typedef std::map<string, boost::shared_ptr<CallingRange> > rangeMap;
! rangeMap callingRanges_;
ObjectHandlerXL &ObjectHandlerXL::instance() {
***************
*** 67,74 ****
if (xOldName.xltype == xltypeStr) {
! std::string oldKey;
operToScalar(oldKey, xOldName);
Excel(xlFree, 0, 1, &xOldName);
! rangeMapIter i = callingRanges_.find(oldKey);
if (i == callingRanges_.end()) {
std::ostringstream msg;
--- 70,77 ----
if (xOldName.xltype == xltypeStr) {
! string oldKey;
operToScalar(oldKey, xOldName);
Excel(xlFree, 0, 1, &xOldName);
! rangeMap::const_iterator i = callingRanges_.find(oldKey);
if (i == callingRanges_.end()) {
std::ostringstream msg;
***************
*** 109,117 ****
}
! std::string ObjectHandlerXL::storeObject(
! const std::string &objectIDOrig,
const boost::shared_ptr<Object> &object) {
! std::string objectID;
if (objectIDOrig.empty()) {
objectID = generateObjectID();
--- 112,120 ----
}
! string ObjectHandlerXL::storeObject(
! const string &objectIDOrig,
const boost::shared_ptr<Object> &object) {
! string objectID;
if (objectIDOrig.empty()) {
objectID = generateObjectID();
***************
*** 128,132 ****
callingRange->registerObject(objectID, object);
! std::string objectIDCounter =
ObjectHandler::storeObject(objectID, object);
return objectIDCounter + "#" +
--- 131,135 ----
callingRange->registerObject(objectID, object);
! string objectIDCounter =
ObjectHandler::storeObject(objectID, object);
return objectIDCounter + "#" +
***************
*** 137,141 ****
}
}
! std::string ObjectHandlerXL::getStub(const std::string &objectID) const {
int counterOffset = objectID.length() - 5;
if (counterOffset >= 0 && objectID[counterOffset] == '#')
--- 140,144 ----
}
}
! string ObjectHandlerXL::getStub(const string &objectID) const {
int counterOffset = objectID.length() - 5;
if (counterOffset >= 0 && objectID[counterOffset] == '#')
***************
*** 145,153 ****
}
! boost::shared_ptr<Object> ObjectHandlerXL::retrieveObjectImpl(const std::string &objectID) const {
! return ObjectHandler::retrieveObjectImpl(getStub(objectID));
! }
!
! std::string ObjectHandlerXL::generateObjectID() {
/*
The user has provided a null string as the object ID so generate a name automatically.
--- 148,152 ----
}
! string ObjectHandlerXL::generateObjectID() {
/*
The user has provided a null string as the object ID so generate a name automatically.
***************
*** 173,197 ****
void ObjectHandlerXL::collectGarbage(const bool &deletePermanent) {
! rangeMapIter iter_current, iter_previous;
! iter_current = callingRanges_.begin();
! while (iter_current != callingRanges_.end()) {
! iter_previous = iter_current;
! iter_current++;
! std::string key = iter_previous->first;
! boost::shared_ptr<CallingRange> callingRange = iter_previous->second;
! if (!callingRange->isValid()) {
! if (deletePermanent) {
! callingRange->clearAll();
! callingRanges_.erase(key);
! } else {
! callingRange->clearNonPermanent();
! if (callingRange->empty())
! callingRanges_.erase(key);
! }
}
}
}
! void ObjectHandlerXL::deleteObject(const std::string &objectID) {
ObjectHandler::deleteObject(getStub(objectID));
}
--- 172,192 ----
void ObjectHandlerXL::collectGarbage(const bool &deletePermanent) {
! rangeMap::iterator i = callingRanges_.begin();
! while (i != callingRanges_.end()) {
! boost::shared_ptr<CallingRange> callingRange = i->second;
! if (callingRange->isValid())
! ++i;
! else {
! callingRange->clearResidentObjects(deletePermanent);
! if (callingRange->empty())
! // post-increment the iterator!!
! callingRanges_.erase(i++);
! else
! ++i;
}
}
}
! void ObjectHandlerXL::deleteObject(const string &objectID) {
ObjectHandler::deleteObject(getStub(objectID));
}
***************
*** 213,217 ****
} else {
out << std::endl << std::endl;
! for (rangeMapIter i = callingRanges_.begin(); i != callingRanges_.end(); i++) {
boost::shared_ptr<CallingRange> callingRange = i->second;
out << *callingRange.get();
--- 208,214 ----
} else {
out << std::endl << std::endl;
! for (rangeMap::const_iterator i = callingRanges_.begin();
! i != callingRanges_.end();
! ++i) {
boost::shared_ptr<CallingRange> callingRange = i->second;
out << *callingRange.get();
***************
*** 220,224 ****
}
! void ObjectHandlerXL::logError(const std::string& message, const bool &append) {
std::ostringstream msgLog;
if (FunctionCall::instance().getCallerType() == Cell) {
--- 217,221 ----
}
! void ObjectHandlerXL::logError(const string& message, const bool &append) {
std::ostringstream msgLog;
if (FunctionCall::instance().getCallerType() == Cell) {
***************
*** 234,238 ****
}
! std::string ObjectHandlerXL::retrieveError(const XLOPER *xRangeRef) {
// XLOPER which might need freeing in the event of an exception
--- 231,235 ----
}
! string ObjectHandlerXL::retrieveError(const XLOPER *xRangeRef) {
// XLOPER which might need freeing in the event of an exception
***************
*** 245,254 ****
}
Excel(xlfReftext, &xRangeText, 1, xRangeRef);
! std::string rangeStr;
operToScalar(rangeStr, xRangeText);
Excel(xlFree, 0, 1, &xRangeText);
RangeReference selectionReference(rangeStr);
! for (rangeMapIter i = callingRanges_.begin(); i != callingRanges_.end(); i++) {
boost::shared_ptr<CallingRange> callingRange = i->second;
if (callingRange->contains(selectionReference))
--- 242,253 ----
}
Excel(xlfReftext, &xRangeText, 1, xRangeRef);
! string rangeStr;
operToScalar(rangeStr, xRangeText);
Excel(xlFree, 0, 1, &xRangeText);
RangeReference selectionReference(rangeStr);
! for (rangeMap::const_iterator i = callingRanges_.begin();
! i != callingRanges_.end();
! ++i) {
boost::shared_ptr<CallingRange> callingRange = i->second;
if (callingRange->contains(selectionReference))
Index: objecthandlerxl.hpp
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/ohxl/objecthandlerxl.hpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** objecthandlerxl.hpp 29 Oct 2006 16:13:44 -0000 1.18
--- objecthandlerxl.hpp 2 Jan 2007 16:36:19 -0000 1.19
***************
*** 57,61 ****
virtual std::string storeObject(const std::string &objectID,
const boost::shared_ptr<Object> &object);
! virtual boost::shared_ptr<Object> retrieveObjectImpl(const std::string &objectID) const;
virtual void collectGarbage(const bool &deletePermanent = false);
virtual void deleteObject(const std::string &objectID);
--- 57,64 ----
virtual std::string storeObject(const std::string &objectID,
const boost::shared_ptr<Object> &object);
! virtual boost::shared_ptr<Object> retrieveObjectImpl(
! const std::string &objectID) const {
! return ObjectHandler::retrieveObjectImpl(getStub(objectID));
! }
virtual void collectGarbage(const bool &deletePermanent = false);
virtual void deleteObject(const std::string &objectID);
Index: callingrange.cpp
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/ohxl/callingrange.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** callingrange.cpp 16 Nov 2006 12:38:40 -0000 1.12
--- callingrange.cpp 2 Jan 2007 16:36:19 -0000 1.13
***************
*** 1,4 ****
--- 1,5 ----
/*
+ Copyright (C) 2007 Ferdinando Ametrano
Copyright (C) 2006 Eric Ehlers
***************
*** 26,33 ****
#include <cmath>
namespace ObjHandler {
// FIXME this value needs to be configured at runtime
! const std::string libFunctionSignature = "ql";
int CallingRange::keyCount_ = 0;
--- 27,36 ----
#include <cmath>
+ using std::string;
+
namespace ObjHandler {
// FIXME this value needs to be configured at runtime
! const string libFunctionSignature = "ql";
int CallingRange::keyCount_ = 0;
***************
*** 52,56 ****
}
! std::string CallingRange::getKeyCount() {
static const int KEY_WIDTH = 5;
static const int KEY_BASE = 16;
--- 55,59 ----
}
! string CallingRange::getKeyCount() {
static const int KEY_WIDTH = 5;
static const int KEY_BASE = 16;
***************
*** 64,101 ****
}
! void CallingRange::clearNonPermanent() {
! std::map<std::string, boost::shared_ptr<Object> >::const_iterator iter_current, iter_previous;
! iter_current = residentObjects_.begin();
! while (iter_current != residentObjects_.end()) {
! iter_previous = iter_current;
! iter_current++;
! if (!iter_previous->second->permanent()) {
! ObjectHandler::instance().deleteObject(iter_previous->first);
! residentObjects_.erase(iter_previous->first);
}
}
}
! void CallingRange::clearAll() {
! std::map<std::string, boost::shared_ptr<Object> >::const_iterator i;
! for (i = residentObjects_.begin(); i != residentObjects_.end(); i++)
! ObjectHandler::instance().deleteObject(i->first);
! residentObjects_.clear();
! }
!
! void CallingRange::deleteObject(
! const std::string &objectID,
! boost::shared_ptr<Object> object) {
! std::map<std::string, boost::shared_ptr<Object> >::const_iterator i;
! i = residentObjects_.find(objectID);
if (i != residentObjects_.end()) {
ObjectHandler::instance().deleteObject(i->first);
! residentObjects_.erase(i->first);
}
}
! void CallingRange::registerObject(
! const std::string &objectID,
! boost::shared_ptr<Object> object) {
residentObjects_[objectID] = object;
}
--- 67,104 ----
}
! typedef std::map<string, boost::shared_ptr<Object>, my_iless> OhRepository;
!
! void CallingRange::clearResidentObjects(bool deletePermanent) {
! if (deletePermanent) {
! for (OhRepository::iterator i = residentObjects_.begin();
! i != residentObjects_.end();
! ++i)
! ObjectHandler::instance().deleteObject(i->first);
! residentObjects_.clear();
! } else {
! OhRepository::iterator i = residentObjects_.begin();
! while (i != residentObjects_.end()) {
! if (i->second->permanent())
! ++i;
! else {
! ObjectHandler::instance().deleteObject(i->first);
! // post-increment the iterator!!
! residentObjects_.erase(i++);
! }
}
}
}
! void CallingRange::deleteObject(const string &objectID,
! boost::shared_ptr<Object> object) {
! OhRepository::iterator i = residentObjects_.find(objectID);
if (i != residentObjects_.end()) {
ObjectHandler::instance().deleteObject(i->first);
! residentObjects_.erase(i);
}
}
! void CallingRange::registerObject(const string &objectID,
! boost::shared_ptr<Object> object) {
residentObjects_[objectID] = object;
}
***************
*** 112,116 ****
Excel(xlfGetName, &xDef, 1, TempStrStl(key_));
! std::string address;
operToScalar(address, xDef);
Excel(xlfTextref, &xRef, 1, TempStrStl(address.substr(1)));
--- 115,119 ----
Excel(xlfGetName, &xDef, 1, TempStrStl(key_));
! string address;
operToScalar(address, xDef);
Excel(xlfTextref, &xRef, 1, TempStrStl(address.substr(1)));
***************
*** 136,140 ****
// FIXME cache this value
! std::string CallingRange::getAddressString() const {
// XLOPER which might need freeing in the event of an exception
--- 139,143 ----
// FIXME cache this value
! string CallingRange::getAddressString() const {
// XLOPER which might need freeing in the event of an exception
***************
*** 146,150 ****
Excel(xlfGetName, &xDef, 1, TempStrStl(key_));
! std::string address;
operToScalar(address, xDef);
Excel(xlFree, 0, 1, &xDef);
--- 149,153 ----
Excel(xlfGetName, &xDef, 1, TempStrStl(key_));
! string address;
operToScalar(address, xDef);
Excel(xlFree, 0, 1, &xDef);
***************
*** 173,177 ****
}
! void CallingRange::setErrorMessage(const std::string &errorMessage, const bool &append) {
if (append) {
std::ostringstream err;
--- 176,180 ----
}
! void CallingRange::setErrorMessage(const string &errorMessage, const bool &append) {
if (append) {
std::ostringstream err;
***************
*** 185,194 ****
// FIXME use boost::regex here
void CallingRange::setInvocationCount() {
! std::string formula = FunctionCall::instance().getFormula();
invocationCount_ = -1;
unsigned int index = 0;
while (index < formula.length()) {
index = formula.find(libFunctionSignature, index);
! if (index == std::string::npos) {
return;
} else {
--- 188,197 ----
// FIXME use boost::regex here
void CallingRange::setInvocationCount() {
! string formula = FunctionCall::instance().getFormula();
invocationCount_ = -1;
unsigned int index = 0;
while (index < formula.length()) {
index = formula.find(libFunctionSignature, index);
! if (index == string::npos) {
return;
} else {
***************
*** 215,223 ****
if (invocationCount_)
busy_ = true;
! clearNonPermanent();
}
}
! std::string CallingRange::updateCount() {
if (updateCount_ > 9999) updateCount_ = 0;
std::ostringstream s;
--- 218,226 ----
if (invocationCount_)
busy_ = true;
! clearResidentObjects(false);
}
}
! string CallingRange::updateCount() {
if (updateCount_ > 9999) updateCount_ = 0;
std::ostringstream s;
***************
*** 246,252 ****
out << std::setw(COL_WIDTH) << "resident objects: "
<< callingRange.residentObjects_.size() << std::endl;
! std::map<std::string, boost::shared_ptr<Object> >::const_iterator i;
for (i = callingRange.residentObjects_.begin();
! i != callingRange.residentObjects_.end(); i++)
out << std::setw(COL_WIDTH) << " object ID: "
<< i->first << std::endl;
--- 249,256 ----
out << std::setw(COL_WIDTH) << "resident objects: "
<< callingRange.residentObjects_.size() << std::endl;
! OhRepository::const_iterator i;
for (i = callingRange.residentObjects_.begin();
! i != callingRange.residentObjects_.end();
! ++i)
out << std::setw(COL_WIDTH) << " object ID: "
<< i->first << std::endl;
Index: callingrange.hpp
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/ohxl/callingrange.hpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** callingrange.hpp 20 Sep 2006 20:17:07 -0000 1.9
--- callingrange.hpp 2 Jan 2007 16:36:19 -0000 1.10
***************
*** 24,27 ****
--- 24,28 ----
#include <oh/object.hpp>
+ #include <oh/iless.hpp>
#include <ohxl/rangereference.hpp>
#include <map>
***************
*** 38,46 ****
}
void deleteObject(const std::string &objectID,
! boost::shared_ptr<Object> object);
void registerObject(const std::string &objectID,
! boost::shared_ptr<Object> object);
! void clearNonPermanent();
! void clearAll();
void update();
std::string updateCount();
--- 39,46 ----
}
void deleteObject(const std::string &objectID,
! boost::shared_ptr<Object> object);
void registerObject(const std::string &objectID,
! boost::shared_ptr<Object> object);
! void clearResidentObjects(bool deletePermanent);
void update();
std::string updateCount();
***************
*** 67,71 ****
void setInvocationCount();
int invocationCount_;
! std::map<std::string, boost::shared_ptr<Object> > residentObjects_;
boost::shared_ptr<RangeReference> rangeReference_;
};
--- 67,71 ----
void setInvocationCount();
int invocationCount_;
! std::map<std::string, boost::shared_ptr<Object>, my_iless > residentObjects_;
boost::shared_ptr<RangeReference> rangeReference_;
};
|