torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
torc::generic::_impl::Copier< class View > Class Template Referenceabstract

#include <Cloning.hpp>

+ Inheritance diagram for torc::generic::_impl::Copier< class View >:
+ Collaboration diagram for torc::generic::_impl::Copier< class View >:

Public Types

typedef View Type
 
typedef boost::shared_ptr< TypePointer
 

Public Member Functions

Pointer operator() (const Pointer &inSource, const ObjectFactorySharedPtr &inFactory) throw (Error)
 
void visit (View &inView) throw (Error)
 
void connectNets (const NetSharedPtr &inNet, const NetSharedPtr &outNet, const ViewSharedPtr &inView)
 
void cloneConnection (const NetSharedPtr &inNet, const NetSharedPtr &outNet, const ViewSharedPtr &inView)
 
 Copier ()
 
 ~Copier () throw ()
 
virtual void visit (_Tp &client)=0 throw (Error)
 

Private Attributes

ObjectFactorySharedPtr mFactory
 
Pointer mReturnVal
 

Detailed Description

template<>
class torc::generic::_impl::Copier< class View >

Definition at line 665 of file Cloning.hpp.

Member Typedef Documentation

typedef boost::shared_ptr<Type> torc::generic::_impl::Copier< class View >::Pointer

Definition at line 668 of file Cloning.hpp.

Definition at line 667 of file Cloning.hpp.

Constructor & Destructor Documentation

Definition at line 981 of file Cloning.hpp.

981  : Type::Visitor(), mFactory(), mReturnVal() {
982  }
torc::generic::_impl::Copier< class View >::~Copier ( )
throw (
)
inline

Definition at line 984 of file Cloning.hpp.

984  {
985  }

Member Function Documentation

void torc::generic::_impl::Copier< class View >::cloneConnection ( const NetSharedPtr inNet,
const NetSharedPtr outNet,
const ViewSharedPtr inView 
)
inline

Definition at line 823 of file Cloning.hpp.

824  {
825  try {
826  std::vector<PortSharedPtr> connectedPorts;
827  inNet->getConnectedPorts(connectedPorts, true);
828  for(std::vector<PortSharedPtr>::iterator it = connectedPorts.begin();
829  it != connectedPorts.end(); ++it) {
830  std::vector < std::string > nestedNames;
831  PortSharedPtr actualPort = *it;
832  PortSharedPtr port = actualPort;
833  while(port) {
834  if(eCompositionTypeVectorBit != port->getCompositionType())
835  nestedNames.push_back(port->getName());
836  port = port->getParentCollection();
837  }
838  std::string portName = *nestedNames.rbegin();
839  PortSharedPtr targetPort = inView->findPort(portName);
840  if(!targetPort) {
841  Error e(eMessageIdErrorPointerToItemDoesNotExist, __FUNCTION__, __FILE__,
842  __LINE__);
843  e.saveContextData("Pointer to the target port does not exist", targetPort);
844  throw e;
845  }
846  if(nestedNames.size() > 1) {
847  findLeafConnectable(nestedNames, targetPort);
848  }
849  std::vector < size_t > indices;
850  if(eCompositionTypeVectorBit == actualPort->getCompositionType()) {
851  indices = IndexFinder<Port, VectorPortBit>()(actualPort);
852  }
853  connectNetToElement(indices, targetPort, outNet);
854  }
855  std::vector<PortReferenceSharedPtr> connectedPortRefs;
856  inNet->getConnectedPortRefs(connectedPortRefs, true);
857  for(std::vector<PortReferenceSharedPtr>::iterator it = connectedPortRefs.begin();
858  it != connectedPortRefs.end(); ++it) {
859  std::vector < std::string > nestedNames;
860  PortReferenceSharedPtr actualPort = *it;
861  PortReferenceSharedPtr port = *it;
862  InstanceSharedPtr instance;
863  while(port) {
864  if(eCompositionTypeVectorBit != port->getCompositionType()) {
865  nestedNames.push_back(port->getName());
866  instance = port->getParent();
867  }
868  port = port->getParentCollection();
869  }
870  std::vector < size_t > indices;
871  if(eCompositionTypeVectorBit == instance->getCompositionType()) {
872  indices = IndexFinder<Instance, InstanceArrayMember>()(instance);
873  instance = instance->getParentCollection();
874  }
875  InstanceSharedPtr targetInst = inView->findInstance(instance->getName());
876  if(!indices.empty()) {
877  targetInst = targetInst->get(indices);
878  }
879  std::string portName = *nestedNames.rbegin();
880  PortReferenceSharedPtr targetPort = targetInst->findPortReference(portName);
881  if(!targetPort) {
882  Error e(eMessageIdErrorPointerToItemDoesNotExist, __FUNCTION__, __FILE__,
883  __LINE__);
884  e.saveContextData("Pointer to the target port does not exist", targetPort);
885  throw e;
886  }
887  if(nestedNames.size() > 1) {
888  findLeafConnectable(nestedNames, targetPort);
889  }
890  std::vector < size_t > portIndices;
891  if(eCompositionTypeVectorBit == actualPort->getCompositionType()) {
892  portIndices = IndexFinder<PortReference, VectorPortBitReference>()(actualPort);
893  }
894  connectNetToElement(portIndices, targetPort, outNet);
895  }
896  std::vector<PortListSharedPtr> connectedPortLists;
897  inNet->getConnectedPortLists(connectedPortLists);
898  for(std::vector<PortListSharedPtr>::iterator it = connectedPortLists.begin();
899  it != connectedPortLists.end(); ++it) {
900  // PortList Clone has not been called directly because, its only
901  // add child port/portRef to portList
902  PortListSharedPtr cloned;
903  mFactory->create(cloned);
904  std::list<PortList::PortListElement> elements;
905  (*it)->getChildren(elements);
906  for(std::list<PortList::PortListElement>::iterator element = elements.begin();
907  element != elements.end(); ++element) {
908  switch((*element).getType()) {
910  std::vector < std::string > nestedNames;
911  PortSharedPtr actualPort = (*element).getPort();
912  PortSharedPtr port = actualPort;
913  while(port) {
914  if(eCompositionTypeVectorBit != port->getCompositionType())
915  nestedNames.push_back(port->getName());
916  port = port->getParentCollection();
917  }
918  std::vector<std::string>::reverse_iterator name = nestedNames.rbegin();
919  std::string portName = *name;
920  PortSharedPtr targetPort = inView->findPort(portName);
921  if(nestedNames.size() > 1) {
922  findLeafConnectable(nestedNames, targetPort);
923  }
924  if(eCompositionTypeVectorBit == actualPort->getCompositionType()) {
925  targetPort = targetPort->get(
926  IndexFinder<Port, VectorPortBit>()(actualPort));
927  }
928  cloned->addChildPort(targetPort);
929  break;
930  }
932  std::vector < std::string > nestedNames;
933  PortReferenceSharedPtr actualPort = (*element).getPortReference();
934  PortReferenceSharedPtr port = actualPort;
935  InstanceSharedPtr instance;
936  while(port) {
937  if(eCompositionTypeVectorBit != port->getCompositionType()) {
938  nestedNames.push_back(port->getName());
939  instance = port->getParent();
940  }
941  port = port->getParentCollection();
942  }
943  std::vector < size_t > indices;
944  if(eCompositionTypeVectorBit == instance->getCompositionType()) {
945  indices = IndexFinder<Instance, InstanceArrayMember>()(instance);
946  instance = instance->getParentCollection();
947  }
948  InstanceSharedPtr targetInst = inView->findInstance(instance->getName());
949  if(!indices.empty()) {
950  targetInst = targetInst->get(indices);
951  }
952  std::string portName = *nestedNames.rbegin();
953  PortReferenceSharedPtr targetPort = targetInst->findPortReference(portName);
954  if(!targetPort) {
955  Error e(eMessageIdErrorPointerToItemDoesNotExist, __FUNCTION__,
956  __FILE__, __LINE__);
957  e.saveContextData("Pointer to the target port does not exist",
958  targetPort);
959  throw e;
960  }
961  if(nestedNames.size() > 1) {
962  findLeafConnectable(nestedNames, targetPort);
963  }
964  if(eCompositionTypeVectorBit == actualPort->getCompositionType()) {
965  targetPort = targetPort->get(
966  IndexFinder<PortReference, VectorPortBitReference>()(actualPort));
967  }
968  cloned->addChildPortReference(targetPort);
969  break;
970  }
971  }
972  }
973  cloned->connect(outNet);
974  }
975  } catch(Error& e) {
976  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
977  throw;
978  }
979  }
boost::shared_ptr< Instance > InstanceSharedPtr
void findLeafConnectable(std::vector< std::string > &nestedNames, boost::shared_ptr< _Connectable > &conn)
void connectNetToElement(const std::vector< size_t > &inIndices, const boost::shared_ptr< _Connectable > &inConn, const NetSharedPtr &inNet)
std::string string
boost::shared_ptr< PortReference > PortReferenceSharedPtr
boost::shared_ptr< PortList > PortListSharedPtr
boost::shared_ptr< Port > PortSharedPtr

+ Here is the call graph for this function:

void torc::generic::_impl::Copier< class View >::connectNets ( const NetSharedPtr inNet,
const NetSharedPtr outNet,
const ViewSharedPtr inView 
)
inline

Definition at line 807 of file Cloning.hpp.

808  {
809  if(eCompositionTypeBundle == inNet->getCompositionType()) {
810  std::vector<NetSharedPtr> inChildren;
811  std::vector<NetSharedPtr> outChildren;
812  inNet->getChildren(inChildren);
813  outNet->getChildren(outChildren);
814  std::vector<NetSharedPtr>::iterator inIt = inChildren.begin();
815  std::vector<NetSharedPtr>::iterator outIt = outChildren.begin();
816  for(; inIt != inChildren.end(); ++inIt, ++outIt) {
817  connectNets(*inIt, *outIt, inView);
818  }
819  }
820  cloneConnection(inNet, outNet, inView);
821  }
void connectNets(const NetSharedPtr &inNet, const NetSharedPtr &outNet, const ViewSharedPtr &inView)
Definition: Cloning.hpp:807
void cloneConnection(const NetSharedPtr &inNet, const NetSharedPtr &outNet, const ViewSharedPtr &inView)
Definition: Cloning.hpp:823
Pointer torc::generic::_impl::Copier< class View >::operator() ( const Pointer inSource,
const ObjectFactorySharedPtr inFactory 
)
throw (Error
)
inline

Definition at line 670 of file Cloning.hpp.

671  {
672  mFactory = inFactory;
673  inSource->accept(*this);
674  return mReturnVal;
675  }
template<typename _Tp >
virtual void torc::generic::VisitorType< _Tp >::visit ( _Tp &  client)
throw (Error
)
pure virtualinherited

Visit the target object. This will typically be a derived leaf type.

Parameters
[in,out]clientA reference to the target object
Exceptions
ErrorException generated by any of the functions called from inside visit()

+ Here is the caller graph for this function:

void torc::generic::_impl::Copier< class View >::visit ( View inView)
throw (Error
)
inline

Definition at line 677 of file Cloning.hpp.

677  {
678  try {
679  ViewSharedPtr viewPtr;
680  mFactory->create(viewPtr);
681  viewPtr->setComments(inView.getComments());
682 
683  std::list < std::string > userData;
684  inView.getUserData(userData);
685  viewPtr->setUserData(userData);
686 
687  std::vector<StatusSharedPtr> outStatus;
688  inView.getStatuses(outStatus);
689  for(std::vector<StatusSharedPtr>::iterator it = outStatus.begin();
690  it != outStatus.end(); ++it) {
691  StatusSharedPtr clonedStatus = clone(*it, mFactory);
692  viewPtr->addStatus(clonedStatus);
693  }
694 
695  viewPtr->setIsExtern(inView.getIsExtern());
696  viewPtr->setName(inView.getName());
697  viewPtr->setParent(inView.getParent());
698  viewPtr->setType(inView.getType());
699 
700  std::map<std::string, PropertySharedPtr> outProperties;
701  std::vector<PropertySharedPtr> properties;
702  inView.getProperties(outProperties);
703  for(std::map<std::string, PropertySharedPtr>::iterator it = outProperties.begin();
704  it != outProperties.end(); ++it) {
705  PropertySharedPtr clonedProperty = clone((*it).second, mFactory);
706  properties.push_back(clonedProperty);
707  }
708  for(std::vector<PropertySharedPtr>::iterator it = properties.begin();
709  it != properties.end(); ++it) {
710  viewPtr->setProperty((*it)->getName(), *it);
711  }
712 
713  viewPtr->setOriginalName(inView.getOriginalName());
714 
715  ParameterMapSharedPtr oldParams = inView.getParameters();
716  ParameterMapSharedPtr newParams = viewPtr->getParameters();
717  ParameterContext oldCtx = inView.getParameterContext();
718  ParameterContext newCtx = viewPtr->getParameterContext();
719  std::map<std::string, ParameterSharedPtr> params;
720  oldParams->getAllParameters(oldCtx, params);
721  for(std::map<std::string, ParameterSharedPtr>::iterator it = params.begin();
722  it != params.end(); ++it) {
723  ParameterSharedPtr clonedParam = clone((*it).second, mFactory);
724  newParams->set(newCtx, (*it).first, clonedParam);
725  }
726 
727  std::vector<InstanceSharedPtr> outInstances;
728  inView.getInstances(outInstances);
729  std::vector<InstanceSharedPtr>::iterator instIt = outInstances.begin();
730  for(; instIt != outInstances.end(); ++instIt) {
731  InstanceSharedPtr newInst = clone(*instIt, mFactory);
732  viewPtr->addInstance(newInst);
733  }
734 
735  std::vector<PortSharedPtr> outPorts;
736  inView.getPorts(outPorts);
737  std::vector<PortSharedPtr>::iterator portIt = outPorts.begin();
738  for(; portIt != outPorts.end(); ++portIt) {
739  PortSharedPtr newPort = clone(*portIt, mFactory);
740  viewPtr->addPort(newPort);
741  }
742 
743  std::vector<PermutableSharedPtr> outPermutables;
744  inView.getPermutables(outPermutables);
745  for(std::vector<PermutableSharedPtr>::iterator it = outPermutables.begin();
746  it != outPermutables.end(); ++it) {
747  PermutableSharedPtr clonedPermutable = clonePermutable(*it, mFactory, viewPtr);
748  viewPtr->addPermutable(clonedPermutable);
749  }
750 
751  std::vector<InterfaceJoinedInfoSharedPtr> outJoinedInfos;
752  inView.getInterfaceJoinedInfos(outJoinedInfos);
753  for(std::vector<InterfaceJoinedInfoSharedPtr>::iterator it = outJoinedInfos.begin();
754  it != outJoinedInfos.end(); ++it) {
755  InterfaceJoinedInfoSharedPtr clonedJoinedInfo = cloneJoinedInfo(*it, mFactory,
756  viewPtr);
757  viewPtr->addInterfaceJoinedInfo(clonedJoinedInfo);
758  }
759 
760  std::vector<NetSharedPtr> outNets;
761  inView.getNets(outNets);
762  std::vector<NetSharedPtr>::iterator netIt = outNets.begin();
763  for(; netIt != outNets.end(); ++netIt) {
764  NetSharedPtr netPtr = clone(*netIt, mFactory);
765  viewPtr->addNet(netPtr);
766  connectNets(*netIt, netPtr, viewPtr);
767  }
768  if(NULL != inView.getTiming()) {
769  TimingSharedPtr clonedTiming = clone(inView.getTiming(), mFactory);
770  viewPtr->setTiming(clonedTiming);
771  }
772  if(NULL != inView.getInterfaceAttributes()) {
773  InterfaceAttributesSharedPtr attrib = inView.getInterfaceAttributes();
774  InterfaceAttributesSharedPtr newAttrib(new InterfaceAttributes());
775  if(!attrib->getDesignator().empty()) {
776  newAttrib->setDesignator(attrib->getDesignator());
777  }
778  if(NULL != attrib->getSimulate()) {
779  SimulateSharedPtr clonedSimulate = clone(attrib->getSimulate(), mFactory);
780  newAttrib->setSimulate(clonedSimulate);
781  }
782  if(NULL != attrib->getTiming()) {
783  TimingSharedPtr clonedTiming = clone(attrib->getTiming(), mFactory);
784  newAttrib->setTiming(clonedTiming);
785  }
786  newAttrib->setComments(attrib->getComments());
787 
788  std::list < std::string > userData;
789  attrib->getUserData(userData);
790  newAttrib->setUserData(userData);
791 
792  viewPtr->setInterfaceAttributes(newAttrib);
793  }
794 
795  if(NULL != inView.getSimulate()) {
796  SimulateSharedPtr clonedSimulate = clone(inView.getSimulate(), mFactory);
797  viewPtr->setSimulate(clonedSimulate);
798  }
799 
800  mReturnVal = viewPtr;
801  } catch(Error& e) {
802  e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
803  throw;
804  }
805  }
boost::shared_ptr< Instance > InstanceSharedPtr
void connectNets(const NetSharedPtr &inNet, const NetSharedPtr &outNet, const ViewSharedPtr &inView)
Definition: Cloning.hpp:807
boost::shared_ptr< Permutable > PermutableSharedPtr
boost::shared_ptr< Parameter > ParameterSharedPtr
boost::shared_ptr< _Tp > clonePermutable(const boost::shared_ptr< _Tp > &inPointer, const ObjectFactorySharedPtr &inFactory, const ViewSharedPtr &inView)
Definition: Cloning.hpp:84
boost::shared_ptr< Simulate > SimulateSharedPtr
boost::shared_ptr< _Tp > clone(const boost::shared_ptr< _Tp > &inPointer, const ObjectFactorySharedPtr &inFactory)
Definition: Cloning.hpp:63
boost::shared_ptr< Net > NetSharedPtr
boost::shared_ptr< _Tp > cloneJoinedInfo(const boost::shared_ptr< _Tp > &inPointer, const ObjectFactorySharedPtr &inFactory, const ViewSharedPtr &inView)
Definition: Cloning.hpp:73
boost::shared_ptr< InterfaceAttributes > InterfaceAttributesSharedPtr
boost::shared_ptr< View > ViewSharedPtr
boost::shared_ptr< InterfaceJoinedInfo > InterfaceJoinedInfoSharedPtr
boost::shared_ptr< Port > PortSharedPtr
boost::shared_ptr< Property > PropertySharedPtr
boost::shared_ptr< Timing > TimingSharedPtr
boost::shared_ptr< Status > StatusSharedPtr
boost::shared_ptr< ParameterMap > ParameterMapSharedPtr

+ Here is the call graph for this function:

Field Documentation

Definition at line 988 of file Cloning.hpp.

Pointer torc::generic::_impl::Copier< class View >::mReturnVal
private

Definition at line 989 of file Cloning.hpp.


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