torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
torc::generic::Permutable Class Reference

Permutable is used to describe a relationship in which ports are interchangeable. More...

#include <Permutable.hpp>

+ Inheritance diagram for torc::generic::Permutable:
+ Collaboration diagram for torc::generic::Permutable:

Data Structures

class  Factory
 

Public Types

enum  PermutableType { ePermutableParent = 0, ePermutableChild }
 
typedef VisitorType< PermutableVisitor
 
typedef Permutable Type
 
typedef boost::shared_ptr< TypePointer
 
typedef boost::weak_ptr< TypeWeakPointer
 

Public Member Functions

void getPorts (std::vector< PortSharedPtr > &outPorts) const
 
void setPorts (const std::vector< PortSharedPtr > &inSource) throw (Error)
 
void addPort (const PortSharedPtr &inPort) throw (Error)
 
void getChildren (std::vector< PermutableSharedPtr > &outPermutables) const
 
template<typename _Action >
void applyOnAllChildren (const _Action &action) throw (Error)
 
void setChildren (const std::vector< PermutableSharedPtr > &inSource) throw (Error)
 
bool addChildPermutable (const PermutableSharedPtr &inPermutable) throw (Error)
 
const bool getIsNonPermutable () const
 
void setIsNonPermutable (const bool &value)
 
const PermutableType getPermutableType () const
 
void setPermutableType (const PermutableType &inSource)
 
size_t getSize () const
 
virtual ~Permutable () throw ()
 
virtual void accept (BaseVisitor &visitor) throw (Error)
 
void setWeakThis (const WeakPointer &inWeakThis)
 
Pointer getSharedThis () const
 

Protected Member Functions

 Permutable ()
 

Private Attributes

std::vector< PortSharedPtrmPorts
 
std::vector< PermutableSharedPtrmChildren
 
bool mIsNonPermutable
 
PermutableType mPermutableType
 

Friends

class FactoryType< Permutable >
 

Detailed Description

Permutable is used to describe a relationship in which ports are interchangeable.

It may reference individual ports, arrayed ports, bundled ports, permutable and nonpermutable statements.

Definition at line 40 of file Permutable.hpp.

Member Typedef Documentation

typedef boost::shared_ptr<Type> torc::generic::SelfReferencing< Permutable >::Pointer
inherited

Definition at line 36 of file SelfReferencing.hpp.

Definition at line 35 of file SelfReferencing.hpp.

Convenience class to visit a permutable.

Definition at line 58 of file Permutable.hpp.

typedef boost::weak_ptr<Type> torc::generic::SelfReferencing< Permutable >::WeakPointer
inherited

Definition at line 37 of file SelfReferencing.hpp.

Member Enumeration Documentation

Type of the permutable, Is it parent or child.

Enumerator
ePermutableParent 
ePermutableChild 

Definition at line 51 of file Permutable.hpp.

Constructor & Destructor Documentation

torc::generic::Permutable::~Permutable ( )
throw (
)
virtual

Definition at line 200 of file Permutable.cpp.

200 {}
torc::generic::Permutable::Permutable ( )
protected

Definition at line 197 of file Permutable.cpp.

197  : Visitable(), SelfReferencing<Permutable>(), mPorts(), mChildren(),
198  mIsNonPermutable(false), mPermutableType() {}
std::vector< PermutableSharedPtr > mChildren
Definition: Permutable.hpp:183
PermutableType mPermutableType
Definition: Permutable.hpp:185
std::vector< PortSharedPtr > mPorts
Definition: Permutable.hpp:182

Member Function Documentation

void torc::generic::Permutable::accept ( BaseVisitor visitor)
throw (Error
)
virtual

Receive a visitor to this class. The visit method of the visitor is called and a reference to this object is passed as a parameter. It has to be noted however, that a dynamic_cast is performed inside this method. If the cast fails, an appropriate exception is thrown by this method. This situation can arise when the passed Visitor object does not inherit from the appropriate visitor specialization. See Visitor documentation for more details.

Parameters
[in,out]visitorA reference to the visitor object
Exceptions
ErrorVisitor type inappropriate for visiting this object or any other error thrown by the Visitor::throw() method.

Implements torc::generic::Visitable.

Definition at line 132 of file Permutable.cpp.

132  {
133  try {
134  runVisitor(*this, visitor);
135  } catch(Error& e) {
136  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
137  throw;
138  }
139 }
void runVisitor(_Tp &inoutVisited, BaseVisitor &inoutVisitor)
Definition: VisitorType.hpp:78

+ Here is the call graph for this function:

bool torc::generic::Permutable::addChildPermutable ( const PermutableSharedPtr inPermutable)
throw (Error
)

Add a nested permutable/nonpermutable to parent permutable.

Parameters
[in]inPermutableNested permutable/nonpermutable

Add a nested permutable/nonpermutable to this permutable.

Parameters
[in]inPermutableNested permutable/nonpermutable
Exceptions
ErrorCould not add permutable because pointer to the permutable does not exist

Definition at line 114 of file Permutable.cpp.

114  {
115  if(!inPermutable) {
116  Error e(eMessageIdErrorPointerToItemDoesNotExist, __FUNCTION__, __FILE__, __LINE__);
117  e.saveContextData("Pointer to the permutable object does not exist", inPermutable);
118  throw e;
119  }
120  if(inPermutable) {
121  mChildren.push_back(inPermutable);
122  return true;
123  } else {
124  return false;
125  }
126 }
std::vector< PermutableSharedPtr > mChildren
Definition: Permutable.hpp:183

+ Here is the call graph for this function:

void torc::generic::Permutable::addPort ( const PortSharedPtr inPort)
throw (Error
)

Add a port to the list of ports. Empty pointer is ignored.

Parameters
[in]inPortPointer to port to be added.
Exceptions
ErrorCould not add port, because Port name is empty

Definition at line 76 of file Permutable.cpp.

76  {
77  if(!inPort) {
78  return;
79  }
80  std::string name = inPort->getName();
81  if(name.empty()) {
82  Error e(eMessageIdErrorEmptyItemName, __FUNCTION__, __FILE__, __LINE__);
83  e.saveContextData("Port name", name);
84  throw e;
85  }
86  mPorts.push_back(inPort);
87 }
std::string string
std::vector< PortSharedPtr > mPorts
Definition: Permutable.hpp:182

+ Here is the call graph for this function:

template<typename _Action >
void torc::generic::Permutable::applyOnAllChildren ( const _Action &  action)
throw (Error
)
inline

Apply action on all children.

Parameters
[in]actionAction to be applied

Definition at line 212 of file Permutable.hpp.

213  {
214  try {
215  std::vector<PermutableSharedPtr>::iterator it = mChildren.begin();
216  for(; it != mChildren.end(); ++it) {
217  action(*it);
218  }
219  } catch(Error& e) {
220  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
221  throw;
222  }
223 }
std::vector< PermutableSharedPtr > mChildren
Definition: Permutable.hpp:183

+ Here is the call graph for this function:

void torc::generic::Permutable::getChildren ( std::vector< PermutableSharedPtr > &  outPermutables) const
inline

Get the nested permutable.

Parameters
[out]outPermutablesVector of permutable to be appended to

Definition at line 203 of file Permutable.hpp.

203  {
204  outPermutables.insert(outPermutables.end(), mChildren.begin(), mChildren.end());
205 }
std::vector< PermutableSharedPtr > mChildren
Definition: Permutable.hpp:183

+ Here is the caller graph for this function:

const bool torc::generic::Permutable::getIsNonPermutable ( ) const
inline

Get the boolean flag whether the current object is permutable/nonpermutable.

Returns
Boolean flag

Definition at line 229 of file Permutable.hpp.

229  {
230  return mIsNonPermutable;
231 }
const Permutable::PermutableType torc::generic::Permutable::getPermutableType ( ) const
inline

Get the permutable type.

Returns
PermutableType

Definition at line 238 of file Permutable.hpp.

238  {
239  return mPermutableType;
240 }
PermutableType mPermutableType
Definition: Permutable.hpp:185

+ Here is the caller graph for this function:

void torc::generic::Permutable::getPorts ( std::vector< PortSharedPtr > &  outValues) const
inline

Get the list of ports for this permutable.

Parameters
[out]outPortsVector of ports to be appended to

Definition at line 194 of file Permutable.hpp.

194  {
195  outValues.insert(outValues.end(), mPorts.begin(), mPorts.end());
196 }
std::vector< PortSharedPtr > mPorts
Definition: Permutable.hpp:182

+ Here is the caller graph for this function:

Pointer torc::generic::SelfReferencing< Permutable >::getSharedThis ( ) const
inlineinherited

Get a shared pointer to this object. A valid pointer is returned if weakThis was set. Otherwise this returns a NULL pointer. For Vector types, the second scenario is an exception condition and should be treated as such.

Returns
A shared pointer to this object

Get a shared pointer to this object. A valid pointer is returned if weakThis was set. Otherwise this returns a NULL pointer. For Vector types, the second scenario is an exception condition and should be treated as such.

Parameters
[out]ptrSet to a shared pointer to this object
size_t torc::generic::Permutable::getSize ( void  ) const

Get the total number of bits of the composition

Returns
Number of bits

Definition at line 145 of file Permutable.cpp.

145  {
146  size_t size = 0;
147  size_t pSize = 0;
148  size_t cSize = 0;
150 
151  std::vector<PermutableSharedPtr> outPermutables;
152  getChildren(outPermutables);
153  std::vector<PermutableSharedPtr>::iterator permutableIt = outPermutables.begin();
154 
155  std::vector<PortSharedPtr> outPorts;
156  getPorts(outPorts);
157  std::vector<PortSharedPtr>::iterator portIt = outPorts.begin();
158 
159  if(Permutable::ePermutableParent == pType) {
160  if(!outPorts.empty()) {
161  pSize = (*portIt)->getSize();
162  } else if(!outPermutables.empty()) {
163  for(; permutableIt != outPermutables.end(); permutableIt++) {
164  pSize += (*permutableIt)->getSize();
165  for(; portIt != outPorts.end(); portIt++) {
166  pSize += (*portIt)->getSize();
167  }
168  }
169  } else {
170  pSize = 0;
171  }
172  } else {
173  if(!outPorts.empty()) {
174  for(; portIt != outPorts.end(); portIt++) {
175  cSize += (*portIt)->getSize();
176  }
177  }
178  if(!outPermutables.empty()) {
179  for(; permutableIt != outPermutables.end(); permutableIt++) {
180  cSize += (*permutableIt)->getSize();
181  }
182  }
183  }
184  size = pSize + cSize;
185  return size;
186 }
const PermutableType getPermutableType() const
Definition: Permutable.hpp:238
void getChildren(std::vector< PermutableSharedPtr > &outPermutables) const
Definition: Permutable.hpp:203
void getPorts(std::vector< PortSharedPtr > &outPorts) const
Definition: Permutable.hpp:194

+ Here is the call graph for this function:

void torc::generic::Permutable::setChildren ( const std::vector< PermutableSharedPtr > &  inSource)
throw (Error
)

Set the nested permutable.

Parameters
[in]inSourceVector containing permutables

Set the nested permutable.

Parameters
[in]inSourceVector containing permutables
Exceptions
ErrorCould not add permutable because pointer to the permutable does not exist

Definition at line 95 of file Permutable.cpp.

95  {
96  std::vector<PermutableSharedPtr>::const_iterator entry = inSource.begin();
97  std::vector<PermutableSharedPtr>::const_iterator end = inSource.end();
98  for(; entry != end; ++entry) {
99  try {
100  addChildPermutable(*entry);
101  } catch(Error& e) {
102  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
103  throw;
104  }
105  }
106 }
bool addChildPermutable(const PermutableSharedPtr &inPermutable)
Definition: Permutable.cpp:114

+ Here is the call graph for this function:

void torc::generic::Permutable::setIsNonPermutable ( const bool &  value)

Definition at line 128 of file Permutable.cpp.

128  {
129  mIsNonPermutable = value;
130 }
void torc::generic::Permutable::setPermutableType ( const PermutableType inSource)

Set the permutable type.

Parameters
[in]inSourcePermutableType

Definition at line 193 of file Permutable.cpp.

193  {
194  mPermutableType = inSource;
195 }
PermutableType mPermutableType
Definition: Permutable.hpp:185
void torc::generic::Permutable::setPorts ( const std::vector< PortSharedPtr > &  inSource)
throw (Error
)

Set the list of ports to this permutable. It will lead to a linear traversal on the list. So usage of this API is not recommended.

Parameters
[in]inSourceVector of ports

Definition at line 56 of file Permutable.cpp.

56  {
57  std::vector<PortSharedPtr>::const_iterator port = inSource.begin();
58  std::vector<PortSharedPtr>::const_iterator end = inSource.end();
59  for(; port != end; ++port) {
60  try {
61  addPort(*port);
62  } catch(Error& e) {
63  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
64  throw;
65  }
66  }
67 }
void addPort(const PortSharedPtr &inPort)
Definition: Permutable.cpp:76

+ Here is the call graph for this function:

void torc::generic::SelfReferencing< Permutable >::setWeakThis ( const WeakPointer inWeakThis)
inlineinherited

Set a weak pointer to this object. This will be used later to get a shared pointer to this object from within other member methods if required. This should be called by the Factory creating the object.

Parameters
[in]weakThisA weak pointer to this object

Friends And Related Function Documentation

friend class FactoryType< Permutable >
friend

Definition at line 42 of file Permutable.hpp.

Field Documentation

std::vector<PermutableSharedPtr> torc::generic::Permutable::mChildren
private

Definition at line 183 of file Permutable.hpp.

bool torc::generic::Permutable::mIsNonPermutable
private

Definition at line 184 of file Permutable.hpp.

PermutableType torc::generic::Permutable::mPermutableType
private

Definition at line 185 of file Permutable.hpp.

std::vector<PortSharedPtr> torc::generic::Permutable::mPorts
private

Definition at line 182 of file Permutable.hpp.


The documentation for this class was generated from the following files: