torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ScalarNet.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 //BOOST
21 #ifdef GENOM_SERIALIZATION
22 #include <boost/archive/binary_iarchive.hpp>
23 #include <boost/archive/binary_oarchive.hpp>
24 #include <boost/serialization/base_object.hpp>
25 #include <boost/serialization/export.hpp>
26 #endif //GENOM_SERIALIZATION
29 
30 #ifdef GENOM_SERIALIZATION
31 BOOST_CLASS_EXPORT(torc::generic::ScalarNet)
32 #endif //GENOM_SERIALIZATION
33 namespace torc {
34 namespace generic {
35 
36 /**
37  * Create a scalar net.
38  *
39  * @param[in] inName Name of the scalar net to be created.
40  * @param[in] inViewPtr Pointer to parented(View) object.
41  * @param[in] inOriginalName Original name of the scalar net [optional].
42  *
43  * @return Pointer to created scalar net.
44  **/
46  const ViewSharedPtr& inViewPtr, const NetBundleSharedPtr& inParentCollection,
47  const std::string& inOriginalName) throw (Error) {
48  try {
49  ScalarNetSharedPtr newScalarNet;
50  create(newScalarNet);
51  newScalarNet->setName(inName);
52  newScalarNet->setOriginalName(inOriginalName);
53  if(inParentCollection) {
54  inParentCollection->addChild(newScalarNet);
55  } else {
56  inViewPtr->addNet(newScalarNet);
57  }
58  return newScalarNet;
59  } catch(Error& e) {
60  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
61  throw;
62  }
63 }
64 
65 void ScalarNet::accept(BaseVisitor& inoutVisitor) throw (Error) {
66  try {
67  runVisitor(*this, inoutVisitor);
68  } catch(Error& e) {
69  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
70  throw;
71  }
72 }
73 
75  if(!inNet) {
76  Error e(eMessageIdErrorPointerToItemDoesNotExist, __FUNCTION__, __FILE__, __LINE__);
77  e.saveContextData("Pointer to Net", inNet);
78  throw e;
79  }
80  if(inNet->getSize() != getSize()) {
81  Error e(eMessageIdErrorItemSizeMismatch, __FUNCTION__, __FILE__, __LINE__);
82  e.saveContextData("Net Size", inNet->getSize());
83  e.saveContextData("Connectable object Size", getSize());
84  throw e;
85  }
86  return Connectable::connect(inNet);
87 }
88 
89 void ScalarNet::disconnect(const Connection& inConnection) throw (Error) {
90  Connectable::disconnect(inConnection);
91 }
92 
94 
95 ScalarNet::~ScalarNet() throw () {}
96 
97 #ifdef GENOM_SERIALIZATION
98 template <class Archive> void ScalarNet::serialize(Archive& ar, unsigned int) {
99  ar & boost::serialization::base_object< Net >(*this);
100  ar & boost::serialization::base_object< Scalar<Net> >(*this);
101 }
102 
103 //TO SATISFY THE LINKER
104 template void ScalarNet::serialize<boost::archive::binary_iarchive>(
105  boost::archive::binary_iarchive& ar, const unsigned int);
106 
107 template void ScalarNet::serialize<boost::archive::binary_oarchive>(
108  boost::archive::binary_oarchive& ar, const unsigned int);
109 
110 #endif //GENOM_SERIALIZATION
111 }// namespace generic
112 } // namespace torc
virtual Connection connect(const NetSharedPtr &inNet)=0
Definition: Connectable.cpp:60
A single object with no child objects.
Definition: Scalar.hpp:34
virtual Connection connect(const NetSharedPtr &inNet)
Definition: ScalarNet.cpp:74
boost::shared_ptr< ScalarNet > ScalarNetSharedPtr
Represents an EDIF Net.
Definition: generic/Net.hpp:58
std::list< NetSharedPtr >::iterator Connection
Definition: Connectable.hpp:52
void runVisitor(_Tp &inoutVisited, BaseVisitor &inoutVisitor)
Definition: VisitorType.hpp:78
std::string string
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
boost::shared_ptr< Net > NetSharedPtr
A base class for Visitor.
Definition: VisitorType.hpp:31
virtual ScalarNetSharedPtr newScalarNetPtr(const std::string &inName, const ViewSharedPtr &inViewPtr, const NetBundleSharedPtr &inParentCollection=NetBundleSharedPtr(), const std::string &inOriginalName=std::string())
Definition: ScalarNet.cpp:45
Represents a standalone net.
Definition: ScalarNet.hpp:42
virtual void accept(BaseVisitor &inoutVisitor)
Definition: ScalarNet.cpp:65
void saveContextData(const std::string &inName, const boost::any &inSource)
Definition: Error.cpp:79
virtual void disconnect()
boost::shared_ptr< View > ViewSharedPtr
boost::shared_ptr< NetBundle > NetBundleSharedPtr
void setCurrentLocation(const std::string &inFunction, const std::string &inFile, uint32_t inLine)
Definition: Error.cpp:73