handleimpl.hpp
Go to the documentation of this file.
1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 /*
4  Copyright (C) 2006, 2007 Eric Ehlers
5 
6  This file is part of QuantLib, a free-software/open-source library
7  for financial quantitative analysts and developers - http://quantlib.org/
8 
9  QuantLib is free software: you can redistribute it and/or modify it
10  under the terms of the QuantLib license. You should have received a
11  copy of the license along with this program; if not, please email
12  <quantlib-dev@lists.sf.net>. The license is also available online at
13  <http://quantlib.org/license.shtml>.
14 
15  This program is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  FOR A PARTICULAR PURPOSE. See the license for more details.
18 */
19 
20 #ifndef qla_handleimpl_hpp
21 #define qla_handleimpl_hpp
22 
23 #include <qlo/handle.hpp>
24 #include <oh/repository.hpp>
25 #include <ql/handle.hpp>
26 
27 namespace QuantLibAddin {
28 
29  template <class ObjectClass, class LibraryClass>
31 
32  public:
33 
34  RelinkableHandleImpl(const boost::shared_ptr<ObjectHandler::ValueObject> &properties,
35  const std::string &objectId,
36  bool permanent) : RelinkableHandle(properties, objectId, permanent) {
37 
38  linkTo(objectId);
39  }
40 
41  const boost::shared_ptr<ObjectClass> &object() const {
42  OH_REQUIRE(object_, "Attempt to retrieve null object reference");
43  return object_;
44  }
45 
46  const QuantLib::RelinkableHandle<LibraryClass> &handle() const {
47  return handle_;
48  }
49 
50  private:
51 
52  void linkTo(const std::string &objectId) {
53 
54  if (!objectId.empty()) {
55  ObjectHandler::Repository::instance().retrieveObject(object_, objectId);
56  boost::shared_ptr<LibraryClass> observable;
57  object_->getLibraryObject(observable);
58  handle_.linkTo(observable);
59  }
60 
61  properties()->setProperty("CurrentLink", objectId);
62  }
63 
64  bool empty() const { return handle_.empty(); }
65 
66  boost::shared_ptr<ObjectClass> object_;
67  QuantLib::RelinkableHandle<LibraryClass> handle_;
68  };
69 
70 }
71 
72 #endif
const QuantLib::RelinkableHandle< LibraryClass > & handle() const
Definition: handleimpl.hpp:46
Definition: handle.hpp:39
const boost::shared_ptr< ObjectClass > & object() const
Definition: handleimpl.hpp:41
RelinkableHandleImpl(const boost::shared_ptr< ObjectHandler::ValueObject > &properties, const std::string &objectId, bool permanent)
Definition: handleimpl.hpp:34
Definition: abcd.hpp:38
Definition: handleimpl.hpp:30