Update of /cvsroot/objecthandler/ObjectHandler/oh
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv20729/oh
Modified Files:
object.hpp objecthandler.hpp
Added Files:
objecthandler.cpp
Removed Files:
objecthandlerbase.cpp objecthandlerbase.hpp
Log Message:
- allow nesting of QL & non-QL functions
- support for permanent objects
--- objecthandlerbase.cpp DELETED ---
Index: object.hpp
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/oh/object.hpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** object.hpp 9 Jun 2006 18:58:27 -0000 1.5
--- object.hpp 11 Jun 2006 12:38:21 -0000 1.6
***************
*** 56,60 ****
ObjectHandler::instance().storeObject(instanceName, object);
*/
! Object() {};
//! Default destructor.
--- 56,60 ----
ObjectHandler::instance().storeObject(instanceName, object);
*/
! Object() : anonymous_(false) {};
//! Default destructor.
***************
*** 82,89 ****
--- 82,105 ----
mProps = p;
}
+
+ const bool &anonymous() {
+ return anonymous_;
+ }
+ void setAnonymous(const bool &anonymous) {
+ anonymous_ = anonymous;
+ }
+
+ const bool &permanent() {
+ return permanent_;
+ }
+ void setPermanent(const bool &permanent) {
+ permanent_ = permanent;
+ }
private:
boost::shared_ptr<ValueObject> mProps;
Object& operator= (const Object&);
Object(const Object&);
+ bool anonymous_;
+ bool permanent_;
};
--- objecthandlerbase.hpp DELETED ---
Index: objecthandler.hpp
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/oh/objecthandler.hpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** objecthandler.hpp 9 Jun 2006 18:58:27 -0000 1.4
--- objecthandler.hpp 11 Jun 2006 12:38:21 -0000 1.5
***************
*** 53,57 ****
/*! Throws exception if no Object exists with that instance name.
*/
! virtual boost::shared_ptr < Object > retrieveObjectImpl(const std::string &instanceName) const;
template < typename T >
--- 53,57 ----
/*! Throws exception if no Object exists with that instance name.
*/
! virtual boost::shared_ptr<Object> retrieveObjectImpl(const std::string &instanceName) const;
template < typename T >
***************
*** 80,84 ****
/*! Does nothing if repository is already empty.
*/
! virtual void deleteAllObjects();
//@}
--- 80,84 ----
/*! Does nothing if repository is already empty.
*/
! virtual void deleteAllObjects(const bool &deletePermanent = false);
//@}
***************
*** 102,106 ****
protected:
static ObjectHandler *instance_;
! void checkName(const std::string &instanceNameDerived);
};
--- 102,106 ----
protected:
static ObjectHandler *instance_;
! void checkName(const std::string &instanceName);
};
--- NEW FILE: objecthandler.cpp ---
/*
Copyright (C) 2005 Ferdinando Ametrano
Copyright (C) 2004, 2005, 2006 Eric Ehlers
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/
QuantLib is free software: you can redistribute it and/or modify it under the
terms of the QuantLib license. You should have received a copy of the
license along with this program; if not, please email qua...@li...
The license is also available online at http://quantlib.org/html/license.html
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/
#if defined(HAVE_CONFIG_H) // Dynamically created by configure
#include <oh/config.hpp>
#endif
#include <oh/objecthandler.hpp>
#include <oh/exception.hpp>
#include <ostream>
#include <sstream>
#include <boost/regex.hpp>
#include <algorithm>
namespace ObjHandler {
ObjectHandler *ObjectHandler::instance_;
// std::map cannot be exported across DLL boundaries
// so instead we use a static variable
std::map<std::string, boost::shared_ptr<Object> > repository_;
ObjectHandler::ObjectHandler() {
instance_ = this;
}
ObjectHandler::~ObjectHandler() {
instance_ = 0;
}
ObjectHandler &ObjectHandler::instance() {
if (instance_) {
return *instance_;
} else
throw Exception("Attempt to reference uninitialized ObjectHandler object");
}
std::string ObjectHandler::storeObject(const std::string &instanceName,
const boost::shared_ptr<Object> &object) {
repository_[instanceName] = object;
return instanceName;
}
boost::shared_ptr<Object> ObjectHandler::retrieveObjectImpl(const std::string &instanceName) const {
std::map<std::string, boost::shared_ptr<Object> >::const_iterator result = repository_.find(instanceName);
if (result == repository_.end()) {
std::ostringstream msg;
msg << "ObjectHandler error: attempt to retrieve object "
<< "with unknown instance name '" << instanceName << "'";
throw Exception(msg.str());
} else
return result->second;
}
void ObjectHandler::deleteObject(const std::string &instanceName) {
repository_.erase(instanceName);
}
void ObjectHandler::deleteAllObjects(const bool &deletePermanent) {
if (deletePermanent) {
repository_.clear();
} else {
std::map < std::string, boost::shared_ptr < Object > >::const_iterator iter_current, iter_previous;
iter_current = repository_.begin();
while (iter_current != repository_.end()) {
iter_previous = iter_current;
iter_current++;
std::string key = iter_previous->first;
boost::shared_ptr < Object > object = iter_previous->second;
if (!object->permanent()) {
repository_.erase(key);
}
}
}
}
void ObjectHandler::dump(std::ostream& out) {
out << "dump of all objects in ObjectHandler:" << std::endl << std::endl;
for (std::map<std::string, boost::shared_ptr<Object> >::const_iterator i=repository_.begin();
i!=repository_.end(); i++) {
boost::shared_ptr<Object> object = i->second;
out << "Object with instanceName = " << i->first << ":" << std::endl << *object.get();
}
}
const int ObjectHandler::objectCount() {
return repository_.size();
}
const std::vector < std::string > ObjectHandler::listInstanceNames(const std::string regex) {
std::vector < std::string > instanceNames;
if (regex.empty()) {
for (std::map<std::string, boost::shared_ptr<Object> >::const_iterator i=repository_.begin(); i!=repository_.end(); i++)
instanceNames.push_back(i->first);
} else {
boost::regex r(regex);
for (std::map<std::string, boost::shared_ptr<Object> >::const_iterator i=repository_.begin(); i!=repository_.end(); i++) {
std::string instanceName = i->first;
if (regex_match(instanceName, r)) instanceNames.push_back(instanceName);
}
}
std::sort(instanceNames.begin(), instanceNames.end());
return instanceNames;
}
void ObjectHandler::checkName(const std::string &instanceName) {
std::map<std::string, boost::shared_ptr<Object> >::const_iterator result =
repository_.find(instanceName);
if (result != repository_.end()) {
std::ostringstream msg;
msg << "ObjectHandler error: cannot create object "
"with instance name '" << instanceName <<
"' because an object with that name already exists";
throw Exception(msg.str());
}
}
}
|