torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ParameterArray.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/export.hpp>
25 #endif //GENOM_SERIALIZATION
28 
29 #ifdef GENOM_SERIALIZATION
30 BOOST_CLASS_EXPORT(torc::generic::ParameterArray)
31 #endif //GENOM_SERIALIZATION
32 namespace torc {
33 namespace generic {
34 
36  const boost::shared_ptr<BaseVectorType::ChildType>& inCreatedChild) const throw (Error) {
37  inCreatedChild->setName(getName());
38 }
39 
41  ParameterArrayElement::Factory, false>() {}
42 
44 
45 /**
46  * Create a parameter array.
47  *
48  * @param[in] inName Name of the parameter array to be created.
49  * @param[in] inUnit Unit of the parameter array.
50  * @param[in] inFactory Factory for the child.
51  * @param[in] inOriginalName Original name of the parameter array [optional].
52  *
53  * @return Pointer to created parameter array.
54  */
56  const size_t& inSize, const ChildFactorySharedPtr& inFactory, const std::string& inOriginalName)
57  throw (Error) {
58  try {
59  std::vector < size_t > limits;
60  limits.push_back(inSize);
61  return newParameterArrayPtr(inName, limits, inFactory, inOriginalName);
62  } catch(Error& e) {
63  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
64  throw;
65  }
66 }
67 
68 /**
69  * Create a parameter array.
70  *
71  * @param[in] inName Name of the parameter array to be created.
72  * @param[in] inLimits Dimensions of the vector.
73  * @param[in] inValue Value of the parameter array.
74  * @param[in] inUnit Unit of the parameter array.
75  * @param[in] inFactory Factory for the child.
76  * @param[in] inOriginalName Original name of the parameter array [optional].
77  *
78  * @return Pointer to created parameter array.
79  */
81  const std::vector<size_t>& inLimits, const ChildFactorySharedPtr& inFactory,
82  const std::string& inOriginalName) throw (Error) {
83  try {
84  ParameterArraySharedPtr newParameterArray;
85  create(newParameterArray);
86  newParameterArray->setName(inName);
87  newParameterArray->setOriginalName(inOriginalName);
88  newParameterArray->constructChildren(inFactory, inLimits);
89  return newParameterArray;
90  } catch(Error& e) {
91  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
92  throw;
93  }
94 }
95 
96 void ParameterArray::accept(BaseVisitor& inoutVisitor) throw (Error) {
97  try {
98  runVisitor(*this, inoutVisitor);
99  } catch(Error& e) {
100  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
101  throw;
102  }
103 }
104 
105 #ifdef GENOM_SERIALIZATION
106 template <class Archive> void ParameterArray::serialize(Archive& ar, unsigned int) {
107  ar & boost::serialization::base_object< Parameter >(*this);
108  ar & boost::serialization::base_object< BaseVectorType >(*this);
109 }
110 
111 //TO SATISFY THE LINKER
112 template void ParameterArray::serialize<boost::archive::binary_oarchive>(
113  boost::archive::binary_oarchive& ar, const unsigned int);
114 
115 template void ParameterArray::serialize<boost::archive::binary_iarchive>(
116  boost::archive::binary_iarchive& ar, const unsigned int);
117 
118 #endif //GENOM_SERIALIZATION
119 
120 } // namespace generic
121 } // namespace torc
boost::shared_ptr< ParameterArray > ParameterArraySharedPtr
void runVisitor(_Tp &inoutVisited, BaseVisitor &inoutVisitor)
Definition: VisitorType.hpp:78
std::string string
Represents a parameter object in EDIF.
Definition: Parameter.hpp:38
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
Represents a parameter array.
virtual ParameterArraySharedPtr newParameterArrayPtr(const std::string &inName, const size_t &inSize, const ChildFactorySharedPtr &inFactory=BaseVectorType::ChildFactorySharedPtr(new BaseVectorType::ChildFactory()), const std::string &inOriginalName=std::string())
A base class for Visitor.
Definition: VisitorType.hpp:31
virtual void onChildCreate(const boost::shared_ptr< BaseVectorType::ChildType > &inCreatedChild) const
An array of objects.
Definition: Vector.hpp:50
virtual void accept(BaseVisitor &inoutVisitor)
void setCurrentLocation(const std::string &inFunction, const std::string &inFile, uint32_t inLine)
Definition: Error.cpp:73