torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LogicElement.hpp
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 TORC_GENERIC_LOGICELEMENT_HPP
17 #define TORC_GENERIC_LOGICELEMENT_HPP
18 
21 #include "torc/generic/Error.hpp"
24 
25 #include <list>
26 #include <vector>
27 
28 namespace torc { namespace generic { class LogicValue; } }
29 namespace torc { namespace generic { class BaseVisitor; } }
30 
31 namespace torc {
32 namespace generic {
33 
34 /**
35  * @brief Represents different logic elements which holds array of logic values.
36  *
37  * The LogicElement class is used to represent different logic elements constructs
38  * in EDIF like logicWaveForm, logicOneOf, logicList, transition, becomes,
39  * ignore and logic value name.
40  */
41 class LogicElement : public LogicValue {
42 
43  friend class FactoryType<LogicElement> ;
44 
45 public:
46  /**
47  * @enum Type
48  * Logic element type
49  */
50  enum Type {
53  };
54 
55  /**
56  * @enum RelationType
57  *
58  * Relation type of the logic elements, is it parent or child.
59  */
60  enum RelationType {
62  };
63 
64  /**
65  * Convenience class to visit a logic element.
66  */
68 
69  /**
70  * Convenience class to create a logic element.
71  */
72  class Factory : public FactoryType<LogicElement> {
73  public:
75  /**
76  * Create a logic element.
77  *
78  * @param[in] inType Type of the logic value.
79  * @param[in] inLogicValue Pointer to the logic value [optional],
80  * needed for single logic element creation.
81  * @param[in] inParentLogicElement Pointer to parent logic element [optional].
82  *
83  * @return Pointer to created permutable.
84  */
86  virtual newLogicElementPtr(const LogicElement::Type& inType,
87  const LogicValueSharedPtr& inLogicValue = LogicValueSharedPtr(),
88  const LogicElementSharedPtr& inParentLogicElement = LogicElementSharedPtr())
89  throw (Error);
90  };
91 
92  /**
93  * @brief Receive a visitor to this class.
94  * The visit method of the visitor is called and a reference to this
95  * object is passed as a parameter. It has to be noted however,
96  * that a dynamic_cast is performed inside this method. If the cast fails,
97  * an appropriate exception is thrown by this method. This situation can arise
98  * when the passed Visitor object does not inherit from the appropriate
99  * visitor specialization. See Visitor documentation for more details.
100  *
101  * @param[in,out] visitor A reference to the visitor object
102  * @exception Error Visitor type inappropriate for visiting this object
103  * or any other error thrown by the Visitor::throw() method.
104  */
105  virtual void accept(BaseVisitor& visitor) throw (Error);
106 
107  /**
108  * Get the Logic element type
109  *
110  * @return Logic element type
111  */
112  inline const Type getType() const;
113 
114  /**
115  * Set the Logic element type
116  *
117  * @param[in] inSource Logic element type
118  */
119  void setType(const Type& inSource);
120 
121  /**
122  * Get the nested logic elements.
123  *
124  * @param[out] outLogicElements Vector of logic element to be appended to
125  */
126  inline void getChildren(std::vector<LogicElementSharedPtr> & outLogicElements) const;
127 
128  /**
129  * Set the nested logic elements.
130  *
131  * @param[in] inSource Vector containing logic elements.
132  * @exception Error Could not add child logic elements because
133  * pointer to the logic elements does not exist
134  */
135  void setChildren(const std::vector<LogicElementSharedPtr> & inSource);
136 
137  /**
138  * Add a logic element to parent logic element
139  *
140  * @param[in] inChildLogicElement Child logic element to be added to parent
141  */
142  bool addChildLogicElement(const LogicElementSharedPtr& inChildLogicElement);
143 
144  /**
145  * Apply action on all children
146  * @param[in] action Action to be applied
147  */
148  template <typename _Action> inline void applyOnAllChildren(const _Action& action) throw (Error);
149 
150  /**
151  * Get the relation type.
152  *
153  * @return RelationType
154  */
155  inline const RelationType getRelationType() const;
156 
157  /**
158  * Set the relation type.
159  *
160  * @param[in] inSource RelationType
161  */
162  void setRelationType(const RelationType& inSource);
163 
164  /**
165  * Get the total number of bits of the composition
166  * @return Number of bits
167  */
168  size_t getSize() const;
169 
170  ~LogicElement() throw ();
171 
172 protected:
173  LogicElement();
174 
175 private:
179 
180 };
181 
182 /**
183  * Get the Logic element type
184  *
185  * @return Logic element type
186  */
187 inline const LogicElement::Type LogicElement::getType() const {
188  return mType;
189 }
190 
191 /**
192  * Get the nested logic elements.
193  *
194  * @param[out] outLogicElements Vector of logic element to be appended to
195  */
196 inline void LogicElement::getChildren(std::vector<LogicElementSharedPtr> & outLogicElements) const {
197  outLogicElements.insert(outLogicElements.end(), mChildren.begin(), mChildren.end());
198 }
199 
200 /**
201  * Apply action on all children
202  * @param[in] action Action to be applied
203  */
204 template <typename _Action> inline void LogicElement::applyOnAllChildren(const _Action& action)
205  throw (Error) {
206  try {
207  std::vector<LogicElementSharedPtr>::iterator it = mChildren.begin();
208  for(; it != mChildren.end(); ++it) {
209  action(*it);
210  }
211  } catch(Error& e) {
212  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
213  throw;
214  }
215 }
216 
217 /**
218  * Get the relation type.
219  *
220  * @return RelationType
221  */
223  return mRelationType;
224 }
225 
226 } // namespace generic
227 } // namespace torc
228 
229 #endif // TORC_GENERIC_LOGICELEMENT_HPP
boost::shared_ptr< LogicValue > LogicValueSharedPtr
An acyclic inoutVisitor implementation.
Definition: VisitorType.hpp:57
boost::shared_ptr< LogicElement > LogicElementSharedPtr
virtual void accept(BaseVisitor &visitor)
Receive a visitor to this class. The visit method of the visitor is called and a reference to this ob...
void setRelationType(const RelationType &inSource)
void setChildren(const std::vector< LogicElementSharedPtr > &inSource)
const RelationType getRelationType() const
This class is used within simulationInfo construct to define a logic value to use for modeling in the...
Definition: LogicValue.hpp:42
The Error object thrown by different methods of EdifOM.
Definition: Error.hpp:41
bool addChildLogicElement(const LogicElementSharedPtr &inChildLogicElement)
A base class for Visitor.
Definition: VisitorType.hpp:31
void applyOnAllChildren(const _Action &action)
void setType(const Type &inSource)
VisitorType< LogicElement > Visitor
void getChildren(std::vector< LogicElementSharedPtr > &outLogicElements) const
Represents different logic elements which holds array of logic values.
std::vector< LogicElementSharedPtr > mChildren
virtual LogicElementSharedPtr newLogicElementPtr(const LogicElement::Type &inType, const LogicValueSharedPtr &inLogicValue=LogicValueSharedPtr(), const LogicElementSharedPtr &inParentLogicElement=LogicElementSharedPtr())
const Type getType() const
A placeholder for a factory method.
Definition: FactoryType.hpp:35
void setCurrentLocation(const std::string &inFunction, const std::string &inFile, uint32_t inLine)
Definition: Error.cpp:73