torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SimulationInfo.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 
18 #include "torc/generic/Library.hpp"
19 
20 namespace torc {
21 namespace generic {
22 
23 /**
24  * Create a simulation info.
25  *
26  * @param[in] inLogicValues Vector of logic values to be appended to
27  * @param[in] inLibraryPtr Pointer to parented(Library) object.
28  *
29  * @return Pointer to simulation info.
30  **/
32  const std::vector<LogicValueSharedPtr>& inLogicValues, const LibrarySharedPtr& inLibraryPtr)
33  throw (Error) {
34  try {
35  SimulationInfoSharedPtr newSimulationInfo;
36  create(newSimulationInfo);
37  newSimulationInfo->setLogicValues(inLogicValues);
38  inLibraryPtr->setSimulationInfo(newSimulationInfo);
39  return newSimulationInfo;
40  } catch(Error& e) {
41  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
42  throw;
43  }
44 }
45 
46 void SimulationInfo::accept(BaseVisitor& inoutVisitor) throw (Error) {
47  try {
48  runVisitor(*this, inoutVisitor);
49  } catch(Error& e) {
50  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
51  throw;
52  }
53 }
54 
55 /**
56  * Set the list of logic values.
57  *
58  * @param[in] inLogicValues Vector of logic values to be appended to
59  */
60 void SimulationInfo::setLogicValues(const std::vector<LogicValueSharedPtr>& inLogicValues)
61  throw (Error) {
62  std::vector<LogicValueSharedPtr>::const_iterator it = inLogicValues.begin();
63  for(; it != inLogicValues.end(); it++) {
64  try {
65  addLogicValue(*it);
66  } catch(Error& e) {
67  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
68  throw;
69  }
70  }
71 }
72 
73 /**
74  * Add a logic value to the list of logic values. If an empty pointer is supplied,
75  * it returns without doing anything.
76  *
77  * @param[in] inLogicValue A pointer to a logic value object.
78  *
79  * @exception Error Logic value could not be added.
80  */
81 void SimulationInfo::addLogicValue(const LogicValueSharedPtr& inLogicValue) throw (Error) {
82  if(!inLogicValue) {
83  return;
84  }
85  std::string name = inLogicValue->getName();
86  if(name.empty()) {
87  Error e(eMessageIdErrorEmptyItemName, __FUNCTION__, __FILE__, __LINE__);
88  e.saveContextData("Empty logic value name ", name);
89  throw e;
90  }
91  if(false == mLogicValueSymTab.set(name, inLogicValue)) {
92  Error e(eMessageIdErrorItemAlreadyExists, __FUNCTION__, __FILE__, __LINE__);
93  e.saveContextData("Logic value name", name);
94  throw e;
95  }
96  inLogicValue->setParent(getSharedThis());
97 }
98 
99 /**
100  * Find a logic value by name, in the list of logic values in simulationInfo.
101  *
102  * @param[in] name String value specifying the name of the logic value.
103  *
104  * @return A pointer to the logic value if found, an empty pointer otherwise.
105  */
107  if(inName.empty()) {
108  Error e(eMessageIdErrorEmptyItemName, __FUNCTION__, __FILE__, __LINE__);
109  e.saveContextData("Empty logic value name", inName);
110  throw e;
111  }
112  LogicValueSharedPtr logicValue;
113  mLogicValueSymTab.get(inName, logicValue);
114  return logicValue;
115 }
116 
117 /**
118  * Remove the specified logic value from the list of logic values.
119  * If an empty pointer is passed, it returns without doing anything
120  *
121  * @param[in] inName name of the object to be removed
122  *
123  * @exception Error Logic Value not preset in collection.
124  */
126  if(inName.empty()) {
127  Error e(eMessageIdErrorEmptyItemName, __FUNCTION__, __FILE__, __LINE__);
128  e.saveContextData("Logic value name", inName);
129  throw e;
130  }
131  if(false == mLogicValueSymTab.remove(inName)) {
132  Error e(eMessageIdErrorItemNotFound, __FUNCTION__, __FILE__, __LINE__);
133  e.saveContextData("Logic value name", inName);
134  throw e;
135  }
136  return;
137 }
138 
140  SelfReferencing<SimulationInfo>(), UserDataContainer(), mLogicValueSymTab() {}
141 
143 
144 } // namespace generic
145 } // namespace torc
boost::shared_ptr< LogicValue > LogicValueSharedPtr
An object that has a parent.
void removeLogicValue(const std::string &inName)
An EDIF cell library.
Definition: Library.hpp:60
Represents all classes that can hold user comments.
Definition: Commentable.hpp:36
This class is used to hold all information about the logic values used within a library.
Represents class that can hold userData.
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
void addLogicValue(const LogicValueSharedPtr &inLogicValue)
boost::shared_ptr< Library > LibrarySharedPtr
A base class for Visitor.
Definition: VisitorType.hpp:31
boost::shared_ptr< SimulationInfo > SimulationInfoSharedPtr
bool get(const KeyType &inKey, ValueType &outValue) const
Definition: SymTab.hpp:121
void saveContextData(const std::string &inName, const boost::any &inSource)
Definition: Error.cpp:79
virtual void accept(BaseVisitor &inoutVisitor)
void setLogicValues(const std::vector< LogicValueSharedPtr > &inLogicValues)
virtual SimulationInfoSharedPtr newSimulationInfoPtr(const std::vector< LogicValueSharedPtr > &inLogicValues, const LibrarySharedPtr &inLibraryPtr)
LogicValueSharedPtr findLogicValue(const std::string &inName)
SymTab< std::string, LogicValueSharedPtr > mLogicValueSymTab
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