torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ParentedObject.hpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 #ifndef TORC_GENERIC_PARENTEDOBJECT_HPP
17 #define TORC_GENERIC_PARENTEDOBJECT_HPP
18 
19 #include <string>
20 
21 //BOOST
22 #include <boost/shared_ptr.hpp>
23 #include <boost/weak_ptr.hpp>
24 #ifdef GENOM_SERIALIZATION
25 #include <boost/serialization/access.hpp>
26 #include <boost/serialization/weak_ptr.hpp>
27 #endif //GENOM_SERIALIZATION
28 namespace torc {
29 namespace generic {
30 
31 /**
32  * @brief An object that has a parent
33  *
34  * EDIF 2 0 0 defines a nested hierarchy of objects in a design. As such most of the non-root
35  * elements have a corresponding parent object. However, the type of parent depends on the type of
36  * object. The ParentedObject template therefore provides a mechanism for storing a pointer to the
37  * parent object.
38  */
39 template <typename _ParentType>
41 
42 #ifdef GENOM_SERIALIZATION
43  friend class boost::serialization::access;
44 #endif
45 
46 protected:
48 
49 public:
50  virtual
51  ~ParentedObject() throw ();
52 
53 private:
55 
57 
58 public:
59  /**
60  * Get a pointer to the parent object
61  *
62  * @return Pointer to parent
63  */
64  inline const boost::shared_ptr<_ParentType> getParent() const;
65 
66  /**
67  * Set a pointer to the parent
68  *
69  * @param[in] inSource Set a pointer to the parent
70  */
71  virtual void setParent(const boost::shared_ptr<_ParentType>& inSource);
72 
73 private:
74 #ifdef GENOM_SERIALIZATION
75  template <class Archive> void serialize(Archive& ar, unsigned int);
76 #endif //GENOM_SERIALIZATION
77  boost::weak_ptr<_ParentType> mParent;
78 };
79 
80 template <typename _ParentType> ParentedObject<_ParentType>::ParentedObject() : mParent() {}
81 
82 template <typename _ParentType> ParentedObject<_ParentType>::~ParentedObject() throw () {}
83 
84 /**
85  * Get a pointer to the parent object
86  *
87  * @return Pointer to parent
88  */
89 template <typename _ParentType> inline const boost::shared_ptr<_ParentType>
91  return mParent.lock();
92 }
93 
94 /**
95  * Set a pointer to the parent
96  *
97  * @param[in] inSource Set a pointer to the parent
98  */
99 template <typename _ParentType> void ParentedObject<_ParentType>::setParent(
100  const boost::shared_ptr<_ParentType>& inSource) {
101  mParent = inSource;
102 }
103 
104 #ifdef GENOM_SERIALIZATION
105 template <typename _ParentType> template <class Archive> void
106  ParentedObject<_ParentType>::serialize(Archive& ar, unsigned int) {
107  ar & mParent;
108 }
109 #endif //GENOM_SERIALIZATION
110 
111 } // namespace generic
112 } // namespace torc
113 #endif // TORC_GENERIC_PARENTEDOBJECT_HPP
ParentedObject< _ParentType > & operator=(const ParentedObject< _ParentType > &source)
An object that has a parent.
boost::weak_ptr< _ParentType > mParent
const boost::shared_ptr< _ParentType > getParent() const
virtual void setParent(const boost::shared_ptr< _ParentType > &inSource)