torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Property.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 #include <boost/serialization/base_object.hpp>
24 #include <boost/serialization/is_abstract.hpp>
25 #include <boost/serialization/string.hpp>
26 #endif //GENOM_SERIALIZATION
28 
29 namespace torc {
30 namespace generic {
31 
32 void Property::accept(BaseVisitor& inoutVisitor) throw (Error) {
33  try {
34  runVisitor(*this, inoutVisitor);
35  } catch(Error& e) {
36  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
37  throw;
38  }
39 }
40 
42 
43 Property::~Property() throw () {}
44 
45 /**
46  * Set the Property inSource.
47  *
48  * @param[in] inSource Value of property.
49  */
50 void Property::setValue(const Value& inSource) {
51  mValue = inSource;
52 }
53 
54 /**
55  * Set the Property inSource unit.
56  *
57  * @param[in] inSource Unit of property.
58  */
59 void Property::setUnit(const Unit& inSource) {
60  mUnit = inSource;
61 }
62 
63 /**
64  * Set the owner/source of this property.
65  *
66  * @param[in] inSource Owner of this property
67  */
68 void Property::setOwner(const std::string& inSource) {
69  mOwner = inSource;
70 }
71 
72 /**
73  * Set the nested properties.
74  *
75  * @param[in] inSource Map containing properties
76  */
77 void Property::setChildren(const std::map<std::string, PropertySharedPtr>& inSource) {
78  std::map<std::string, PropertySharedPtr>::const_iterator entry = inSource.begin();
79  std::map<std::string, PropertySharedPtr>::const_iterator end = inSource.end();
80  for(; entry != end; ++entry) {
81  addChildProperty((*entry).first, (*entry).second);
82  }
83 }
84 
85 /**
86  * Add a nested property to this property
87  *
88  * @param[in] inName Nested property name
89  * @param[in] inProperty Nested property
90  */
91 bool Property::addChildProperty(const std::string& inName, const PropertySharedPtr& inProperty) {
92  if(!inName.empty()) {
93  return mChildren.set(inName, inProperty);
94  }
95  return false;
96 }
97 
98 #ifdef GENOM_SERIALIZATION
99 
100 template <class Archive> void Property::serialize(Archive& ar, unsigned int) {
101  ar & boost::serialization::base_object<Commentable>(*this);
102  ar & boost::serialization::base_object<Nameable>(*this);
103  ar & boost::serialization::base_object<Renamable>(*this);
104  ar & boost::serialization::base_object< SelfReferencing<Property> >(*this);
105  ar & boost::serialization::base_object< Visitable >(*this);
106  ar & mOwner;
107  ar & mUnit;
108  ar & mValue;
109  ar & mChildren;
110 }
111 
112 //TO SATISFY THE LINKER
113 template void Property::serialize<boost::archive::binary_iarchive>(
114  boost::archive::binary_iarchive& ar, const unsigned int);
115 
116 template void Property::serialize<boost::archive::binary_oarchive>(
117  boost::archive::binary_oarchive& ar, const unsigned int);
118 
119 #endif //GENOM_SERIALIZATION
120 
121 } // namespace generic
122 } // namespace torc
SymTab< std::string, PropertySharedPtr > mChildren
Definition: Property.hpp:168
Represents all classes that can hold user comments.
Definition: Commentable.hpp:36
virtual void accept(BaseVisitor &inoutVisitor)
Definition: Property.cpp:32
bool set(const KeyType &inKey, const ValueType &inValue)
Definition: SymTab.hpp:132
void runVisitor(_Tp &inoutVisited, BaseVisitor &inoutVisitor)
Definition: VisitorType.hpp:78
std::string string
bool addChildProperty(const std::string &inName, const PropertySharedPtr &inProperty)
Definition: Property.cpp:91
void setValue(const Value &inSource)
Definition: Property.cpp:50
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
A base class for Visitor.
Definition: VisitorType.hpp:31
void setChildren(const std::map< std::string, PropertySharedPtr > &inSource)
Definition: Property.cpp:77
void setOwner(const std::string &inSource)
Definition: Property.cpp:68
void setUnit(const Unit &inSource)
Definition: Property.cpp:59
boost::shared_ptr< Property > PropertySharedPtr
Represents objects that can be renamed.
An object that receives an inoutVisitor.
Definition: Visitable.hpp:38
void setCurrentLocation(const std::string &inFunction, const std::string &inFile, uint32_t inLine)
Definition: Error.cpp:73