Login  Register

Re: Tutorial to use ObjectHandler outside of QuantLibXL

Posted by Lisa Ann on Aug 14, 2015; 11:05am
URL: http://quantlib.414.s1.nabble.com/Tutorial-to-use-ObjectHandler-outside-of-QuantLibXL-tp16776p16780.html

Thank you for the hint, Eric.

I've already given a look at:

    account.hpp
    addindynamic1.cpp
    addindynamic2.cpp
    addinstatic.cpp
    example.cpp

I'm currently trying to understand which are the "basic" blocks that I need to build my first experiments with ObjectHandler. Wandering through classes, for example, I see several classes that might be good candidates to inherit generic objects from (e.g. should a financial instrument to be cached inherit either from Object and from Observable?), but I am not still able to grasp the basic structure.

If you had to write a very simple main to cache an object and retrieve its ID via ObjectHandler, how much would your code be different than this?
__________________________________________________________________

#include <oh/objecthandler.hpp>

class MyObject : public ObjectHandler::Object
{
public:
  MyObject();
  virtual ~MyObject();
private:
  // ...
}

main()
{
  boost::shared_ptr< ObjectHandler::Object> myObject(new MyObject());
  ObjectHandler::Repository::instance().storeObject("Lisa", myObject, false);
  boost::shared_ptr< ObjectHandler::Object> anotherObj(new MyObject());
  ObjectHandler::Repository::instance().retrieveObject(anotherObj, "Lisa");

  return 0;
}
__________________________________________________________________

Examples are so full of many methods and classes that I'm afraid of being missing some pieces along the path...

Thanks