torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PropertyContainer.cpp
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 HAVE_CONFIG_H
17 #include "torc/generic/config.h"
18 #endif
19 
20 #ifdef GENOM_SERIALIZATION
21 #include <boost/archive/binary_iarchive.hpp>
22 #include <boost/archive/binary_oarchive.hpp>
23 #endif //GENOM_SERIALIZATION
26 
27 namespace torc {
28 namespace generic {
29 
30 /**
31  * Get a property
32  *
33  * @param[in] name Name of the property to be retreived
34  *
35  * @return Pointer to the property object if present, empty pointer otherwise.
36  */
38  PropertySharedPtr property;
39  if(!inName.empty()) {
40  mProperties.get(inName, property);
41  }
42  return property;
43 }
44 
45 /**
46  * Save the inSource of a property
47  *
48  * @param[in] inName Name of the property to be saved
49  * @param[in] inPoperty Pointer to the property object if present, empty pointer otherwise.
50  *
51  * @return bool True if saved, false otherwise.
52  */
54  const PropertySharedPtr& inProperty) {
55  if(!inName.empty()) {
56  return mProperties.set(inName, inProperty);
57  }
58  return false;
59 }
60 
61 /**
62  * Set the map of properties
63  *
64  * @param[in] inSource The map of properties
65  */
66 void PropertyContainer::setProperties(const std::map<std::string, PropertySharedPtr>& inSource) {
67  std::map<std::string, PropertySharedPtr>::const_iterator it = inSource.begin();
68  for(; it != inSource.end(); it++) {
69  setProperty((*it).first, (*it).second);
70  }
71 }
72 
74 
76 
77 #ifdef GENOM_SERIALIZATION
78 template <class Archive> void PropertyContainer::serialize(Archive& ar, unsigned int) {
79  ar & mProperties;
80 }
81 
82 //TO SATISFY THE LINKER
83 template void PropertyContainer::serialize<boost::archive::binary_iarchive>(
84  boost::archive::binary_iarchive& ar, const unsigned int);
85 
86 template void PropertyContainer::serialize<boost::archive::binary_oarchive>(
87  boost::archive::binary_oarchive& ar, const unsigned int);
88 
89 #endif //GENOM_SERIALIZATION
90 }
91 
92 // namespace generic
93 }// namespace torc
bool setProperty(const std::string &inName, const PropertySharedPtr &inProperty)
bool set(const KeyType &inKey, const ValueType &inValue)
Definition: SymTab.hpp:132
std::string string
bool get(const KeyType &inKey, ValueType &outValue) const
Definition: SymTab.hpp:121
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)