Update of /cvsroot/objecthandler/ObjectHandler/oh
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv29781/oh
Modified Files:
object.hpp objecthandler.hpp objhandler.hpp
objhandlerdefines.hpp utilities.cpp utilities.hpp
Log Message:
cleaner processing for object references
Index: utilities.cpp
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/oh/utilities.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** utilities.cpp 6 Jun 2006 14:12:39 -0000 1.5
--- utilities.cpp 9 Jun 2006 18:58:27 -0000 1.6
***************
*** 22,25 ****
--- 22,26 ----
#include <oh/utilities.hpp>
#include <oh/logger.hpp>
+ #include <oh/objecthandler.hpp>
#include <oh/exception.hpp>
#include <sstream>
***************
*** 31,53 ****
}
- DLL_API std::string storeObject(
- const std::string &instanceName,
- const obj_ptr &object) {
- std::string ret =
- ObjectHandler::instance().storeObject(instanceName, object);
- return ret;
- }
-
- DLL_API ObjHandler::obj_ptr retrieveObject(
- const std::string &instanceName) {
- return ObjectHandler::instance().retrieveObject(instanceName);
- }
-
- #ifdef COMPILING_XLL
- DLL_API void resetCaller() {
- ObjectHandler::instance().resetCaller();
- }
- #endif
-
std::string setLogFile(
const std::string &logFileName,
--- 32,35 ----
***************
*** 79,84 ****
void logObject(const std::string &instanceName) {
std::ostringstream msg;
! obj_ptr object =
! ObjectHandler::instance().retrieveObject(instanceName);
if (object) {
msg << "log dump of object with instance name = " << instanceName << std::endl;
--- 61,66 ----
void logObject(const std::string &instanceName) {
std::ostringstream msg;
! boost::shared_ptr<Object> object =
! ObjectHandler::instance().retrieveObjectImpl(instanceName);
if (object) {
msg << "log dump of object with instance name = " << instanceName << std::endl;
Index: object.hpp
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/oh/object.hpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** object.hpp 6 Jun 2006 17:43:10 -0000 1.4
--- object.hpp 9 Jun 2006 18:58:27 -0000 1.5
***************
*** 27,65 ****
#include <boost/any.hpp>
#include <oh/valueobject.hpp>
#include <vector>
- #include <stack>
#include <string>
#include <iostream>
! #define EXPORT_UNDERLYING_OBJECT(CLASS, POINTER) \
! const CLASS& getObject() const { \
! return *boost::dynamic_pointer_cast<CLASS>(POINTER); \
! }
!
! //! ObjectHandler function retrieveObject
! /*! Declare boost shared pointer with name \a NAME and point it to
! Object having class \a CLIENT_CLASS and instance name \a INSTANCENAME.
! */
! #define OH_GET_OBJECT( NAME, INSTANCENAME, CLIENT_CLASS ) \
! boost::shared_ptr < CLIENT_CLASS > NAME = \
! boost::dynamic_pointer_cast< CLIENT_CLASS > \
! (ObjHandler::retrieveObject( INSTANCENAME )); \
! if (!NAME) { \
! std::ostringstream err; \
! err << "Unable to convert instance name " << INSTANCENAME \
! << " to object of class " #CLIENT_CLASS; \
! throw ObjHandler::Exception(err.str()); \
! }
! //! Object function getReference
! /*! Declare a boost shared pointer with name \a NAME and point it
! to object of class \a UNDERLYING_CLASS retrieved from Object
! having class \a CLIENT_CLASS and instance name \a INSTANCENAME.
! */
! #define OH_GET_REFERENCE( NAME, INSTANCENAME, CLIENT_CLASS, UNDERLYING_CLASS ) \
! OH_GET_OBJECT(NAME ## temp, INSTANCENAME, CLIENT_CLASS ) \
! const boost::shared_ptr< UNDERLYING_CLASS > NAME = \
! boost::static_pointer_cast< UNDERLYING_CLASS > \
! ( NAME ## temp->getReference() );
namespace ObjHandler {
--- 27,43 ----
#include <boost/any.hpp>
#include <oh/valueobject.hpp>
+ #include <oh/objhandlerdefines.hpp>
#include <vector>
#include <string>
#include <iostream>
! #define OH_GET_OBJECT( NAME, ID, OBJECT_CLASS ) \
! boost::shared_ptr < OBJECT_CLASS > NAME = \
! ObjHandler::ObjectHandler::instance().retrieveObject< OBJECT_CLASS >(ID);
! #define OH_GET_REFERENCE( NAME, ID, OBJECT_CLASS, LIBRARY_CLASS ) \
! OH_GET_OBJECT(NAME ## temp, ID, OBJECT_CLASS ) \
! const boost::shared_ptr < LIBRARY_CLASS > NAME = \
! NAME ## temp->getLibraryObject < LIBRARY_CLASS >();
namespace ObjHandler {
***************
*** 72,75 ****
--- 50,54 ----
//! \name Constructors & Destructors
//@{
+
//! Default constructor.
/*! Construct an Object.
***************
*** 78,99 ****
*/
Object() {};
//! Default destructor.
virtual ~Object() {};
//@}
//! \name Object interrogation
//@{
! //! Acquire a reference to underlying Object.
! /*! Returns a reference to the client object stored in the Object.
! This is a shared pointer to void which must be recast appropriately.
! */
! virtual boost::shared_ptr<void> getReference() const = 0;
//! Retrieve vector of property names.
/*! Returns empty vector if Object has no properties.
*/
std::vector < std::string > propertyNames() const;
//! Retrieve value of given property.
/*! Throws exception if Object has no property by that name.
*/
boost::any propertyValue(const std::string &propertyName) const;
friend std::ostream &operator<<(std::ostream&, const Object &object);
//@}
--- 57,79 ----
*/
Object() {};
+
//! Default destructor.
virtual ~Object() {};
+
//@}
+
//! \name Object interrogation
//@{
!
//! Retrieve vector of property names.
/*! Returns empty vector if Object has no properties.
*/
std::vector < std::string > propertyNames() const;
+
//! Retrieve value of given property.
/*! Throws exception if Object has no property by that name.
*/
boost::any propertyValue(const std::string &propertyName) const;
+
friend std::ostream &operator<<(std::ostream&, const Object &object);
//@}
***************
*** 116,121 ****
}
}
#endif
-
--- 96,120 ----
}
+ template <class LibraryClass>
+ class LibraryObject : public Object {
+ public:
+ template <class LibraryDerivedClass>
+ const boost::shared_ptr<LibraryDerivedClass> getLibraryObject() const {
+ boost::shared_ptr<LibraryDerivedClass> ret =
+ boost::dynamic_pointer_cast<LibraryDerivedClass>(libraryObject_);
+ if (ret)
+ return ret;
+ else
+ throw Exception("unsuccessful attempt to recast pointer");
+ }
+ template <>
+ const boost::shared_ptr<LibraryClass> getLibraryObject<LibraryClass>() const {
+ return libraryObject_;
+ }
+ protected:
+ boost::shared_ptr<LibraryClass> libraryObject_;
+ };
+
}
#endif
Index: objhandlerdefines.hpp
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/oh/objhandlerdefines.hpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** objhandlerdefines.hpp 19 May 2006 15:12:41 -0000 1.1
--- objhandlerdefines.hpp 9 Jun 2006 18:58:27 -0000 1.2
***************
*** 26,33 ****
#endif
- #if (_MSC_VER == 1200)
- # define OBJHANDLER_PATCH_MSVC6
- #endif
-
//! version string
#ifdef _DEBUG
--- 26,29 ----
***************
*** 63,69 ****
#pragma warning(disable : 4996)
#pragma warning(disable : 4244)
- //#pragma warning(disable:4231)
#endif
#endif
-
--- 59,63 ----
Index: objecthandler.hpp
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/oh/objecthandler.hpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** objecthandler.hpp 6 Jun 2006 09:11:55 -0000 1.3
--- objecthandler.hpp 9 Jun 2006 18:58:27 -0000 1.4
***************
*** 1,5 ****
/*
! Copyright (C) 2004, 2005 Eric Ehlers
This file is part of QuantLib, a free-software/open-source library
--- 1,5 ----
/*
! Copyright (C) 2004, 2005, 2006 Eric Ehlers
This file is part of QuantLib, a free-software/open-source library
***************
*** 17,21 ****
/*! \file
! \brief ObjectHandler class
*/
--- 17,21 ----
/*! \file
! \brief ObjectHandlerclass
*/
***************
*** 23,54 ****
#define oh_objecthandler_hpp
! #include <oh/singleton.hpp>
!
! #ifdef COMPILING_XLL
!
! #include <ohxl/objecthandlerxl.hpp>
namespace ObjHandler {
! class ObjectHandler : public ObjectHandlerXL,
! public Singleton<ObjectHandler> {
! friend class Singleton<ObjectHandler>;
public:
! virtual ~ObjectHandler() {}
! };
! }
! #else
! #include <oh/objecthandlerbase.hpp>
! namespace ObjHandler {
! class ObjectHandler : public ObjectHandlerBase,
! public Singleton<ObjectHandler> {
! friend class Singleton<ObjectHandler>;
! public:
! virtual ~ObjectHandler() {}
};
--- 23,106 ----
#define oh_objecthandler_hpp
! #include <oh/object.hpp>
! #include <oh/objhandlerdefines.hpp>
! #include <map>
+ //! ObjHandler
+ /*! name space for the Object Handler
+ */
namespace ObjHandler {
! //! Global Object repository.
! /*! Maintains a repository of Objects. Objects may be
! created/amended/destroyed by the client application.
! */
! class DLL_API ObjectHandler {
public:
! ObjectHandler();
! ~ObjectHandler();
! static ObjectHandler &instance();
! //! \name storing / retrieving / deleting Objects
! //@{
! //! Store Object with given instance name.
! /*! Any existing Object with that instance name is deleted.
! */
! virtual std::string storeObject(const std::string &instanceName,
! const boost::shared_ptr < Object > &object);
! //! Retrieve Object with given instance name.
! /*! Throws exception if no Object exists with that instance name.
! */
! virtual boost::shared_ptr < Object > retrieveObjectImpl(const std::string &instanceName) const;
! template < typename T >
! boost::shared_ptr < T > retrieveObject(const std::string &id) {
! boost::shared_ptr < Object > object = retrieveObjectImpl(id);
! boost::shared_ptr < T > ret =
! boost::dynamic_pointer_cast < T > (object);
! if (!ret)
! throw Exception("Error retrieving object with id '" + id +
! "' - unsuccessful attempt to recast pointer");
! return ret;
! }
! template <>
! boost::shared_ptr < Object > retrieveObject<Object>(
! const std::string &id) {
! return retrieveObjectImpl(id);
! }
! //! Delete Object with given instance name.
! /*! Does nothing if no Object exists with that instance name.
! */
! virtual void deleteObject(const std::string &instanceName);
!
! //! Delete all Objects in repository.
! /*! Does nothing if repository is already empty.
! */
! virtual void deleteAllObjects();
!
! //@}
! //! \name utilities
! //@{
! //! Log dump of ObjectHandler.
! /*! Write all objects in ObjectHandler
! to output stream.
! */
! virtual void dump(std::ostream&);
!
! //! Count of all Objects in repository.
! virtual const int objectCount();
!
! //! List handles of all Objects in repository.
! /*! Returns empty list if repository is empty.
! */
! virtual const std::vector < std::string > listInstanceNames(
! const std::string regex = "");
! //@}
! protected:
! static ObjectHandler *instance_;
! void checkName(const std::string &instanceNameDerived);
};
***************
*** 57,60 ****
#endif
- #endif
-
--- 109,110 ----
Index: utilities.hpp
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/oh/utilities.hpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** utilities.hpp 6 Jun 2006 17:43:13 -0000 1.5
--- utilities.hpp 9 Jun 2006 18:58:27 -0000 1.6
***************
*** 24,28 ****
#define oh_utilities_hpp
! #include <oh/objecthandler.hpp>
namespace ObjHandler {
--- 24,29 ----
#define oh_utilities_hpp
! #include <oh/objhandlerdefines.hpp>
! #include <string>
namespace ObjHandler {
***************
*** 32,65 ****
//! Retrieve ObjectHandler version string
std::string version();
-
- /** \name ObjectHandler wrappers
- * These functions are a convenience for the ObjectHandler XLL
- by wrapping calls to the ObjectHandler singleton
- e.g. ObjHandler::ObjectHandler::instance().xxx()
- so that the OH class doesn't need to be exported across DLL boundaries.
- */
- //@{
-
- //! Store given Object in repository under given instance name.
- /*! Any existing Object with that instance name is deleted.
- */
- DLL_API std::string storeObject(
- const std::string &instanceName,
- const ObjHandler::obj_ptr &object);
-
- //! Retrieve named Object from repository.
- /*! Throws an exception if no Object exists with given instance name.
- */
- DLL_API obj_ptr retrieveObject(
- const std::string &instanceName);
-
- //! Clear the contents of the calling cell.
- /*! Only required for XLLs.
- */
- #ifdef COMPILING_XLL
- DLL_API void resetCaller();
- #endif
-
- //@}
/** \name Logging framework
--- 33,36 ----
Index: objhandler.hpp
===================================================================
RCS file: /cvsroot/objecthandler/ObjectHandler/oh/objhandler.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** objhandler.hpp 25 May 2006 10:45:35 -0000 1.2
--- objhandler.hpp 9 Jun 2006 18:58:27 -0000 1.3
***************
*** 20,24 ****
#include <oh/objhandlerdefines.hpp>
!
#include <oh/utilities.hpp>
#include <oh/exception.hpp>
--- 20,24 ----
#include <oh/objhandlerdefines.hpp>
! #include <oh/objecthandler.hpp>
#include <oh/utilities.hpp>
#include <oh/exception.hpp>
|