torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PropertyContainer.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_PROPERTYCONTAINER_HPP
17 #define TORC_GENERIC_PROPERTYCONTAINER_HPP
18 
20 
21 //BOOST
22 #include <boost/shared_ptr.hpp>
23 #ifdef GENOM_SERIALIZATION
24 #include <boost/serialization/access.hpp>
25 #endif //GENOM_SERIALIZATION
26 #include "torc/generic/SymTab.hpp"
27 
28 namespace torc { namespace generic { class Property; } }
29 
30 namespace torc {
31 namespace generic {
32 
33 /**
34  * @brief Represents objects that have properties
35  *
36  * The PropertyContainer interface is generalized by classes tat need to hold one or more
37  * properties. A property is identified by name in the container.
38  */
40 #ifdef GENOM_SERIALIZATION
41  friend class boost::serialization::access;
42 #endif
43 
44 public:
45  /**
46  * Get a property
47  *
48  * @param[in] inName Name of the property to be retreived
49  *
50  * @return Pointer to the property object if present, empty pointer otherwise.
51  */
53 
54  /**
55  * Save the inSource of a property
56  *
57  * @param[in] inName Name of the property to be saved
58  * @param[in] inProperty Pointer to the property object if present, empty pointer otherwise.
59  *
60  * @return bool True if saved, false otherwise.
61  */
62  bool setProperty(const std::string& inName, const PropertySharedPtr& inProperty);
63 
64  /**
65  * Get the map of all properties
66  *
67  * @param[out] outProperties The map of properties
68  */
69  inline void getProperties(std::map<std::string, PropertySharedPtr>& outProperties) const;
70 
71  /**
72  * Set the map of properties
73  *
74  * @param[in] inSource The map of properties
75  */
76  void setProperties(const std::map<std::string, PropertySharedPtr>& inSource);
77 
78  /**
79  * Apply action on all properties.
80  * @param[in] action Action to be applied
81  *
82  */
83  template <typename _Action> inline void applyOnAllProperties(const _Action& action)
84  throw (Error);
85 
86 protected:
88 
89 public:
90  ~PropertyContainer() throw ();
91 
92 private:
93  PropertyContainer(const PropertyContainer& source);
95 
96 #ifdef GENOM_SERIALIZATION
97  template <class Archive> void serialize(Archive& ar, unsigned int);
98 #endif //GENOM_SERIALIZATION
100 };
101 
102 /**
103  * Get the map of all properties
104  *
105  * @return The map of properties
106  */
108  std::map<std::string, PropertySharedPtr>& outProperties) const {
109  mProperties.getValueMap(outProperties);
110  return;
111 }
112 
113 template <typename _Action> inline void PropertyContainer::applyOnAllProperties(
114  const _Action& action) throw (Error) {
115  try {
116  mProperties.applyOnAll(action);
117  } catch(Error& e) {
118  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
119  throw;
120  }
121 }
122 
123 } // namespace generic
124 } // namespace torc
125 
126 #endif // TORC_GENERIC_PROPERTYCONTAINER_HPP
bool setProperty(const std::string &inName, const PropertySharedPtr &inProperty)
Represents objects that have properties.
std::string string
void applyOnAllProperties(const _Action &action)
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
void getProperties(std::map< std::string, PropertySharedPtr > &outProperties) const
void getValueMap(UserMap &outMap) const
Definition: SymTab.hpp:171
void setProperties(const std::map< std::string, PropertySharedPtr > &inSource)
SymTab< std::string, PropertySharedPtr > mProperties
boost::shared_ptr< Property > PropertySharedPtr
PropertySharedPtr getProperty(const std::string &inName)
PropertyContainer & operator=(const PropertyContainer &source)
void setCurrentLocation(const std::string &inFunction, const std::string &inFile, uint32_t inLine)
Definition: Error.cpp:73