MimmoNamespace.cpp
1 #include "MimmoNamespace.hpp"
2 #include "BaseManipulation.hpp"
3 
4 std::string mimmo::MIMMO_LOG_FILE = "mimmo";
5 std::string mimmo::MIMMO_LOG_DIR = ".";
6 bool mimmo::MIMMO_EXPERT = false;
17 
18  buffer >> var.ftype;
19  buffer >> var.fdir;
20  buffer >> var.fname;
21 
22  return buffer;
23 };
24 
32 
33  buffer<<var.ftype;
34  buffer<<var.fdir;
35  buffer<<var.fname;
36 
37  return buffer;
38 };
39 
40 
41 namespace mimmo{
42 
47  ftype = 0;
48 };
49 
54 
55 
56 namespace pin{
57 
67 bool
68 addPin(BaseManipulation* objSend, BaseManipulation* objRec, PortID portS, PortID portR, bool forced){
69  bitpit::Logger* log = &bitpit::log::cout(MIMMO_LOG_FILE);
70  bool done = false;
71  if (!objSend->arePortsBuilt()){
72  objSend->buildPorts();
73  if (!objSend->arePortsBuilt()){
74  (*log) << "error: " << objSend->m_name << " cannot build ports -> exit! " << std::endl;
75  throw std::runtime_error (objSend->m_name + " cannot build ports");
76  }
77  }
78  if (!objRec->arePortsBuilt()){
79  objRec->buildPorts();
80  if (!objRec->arePortsBuilt()){
81  (*log) << "error: " << objRec->m_name << " cannot build ports -> exit! " << std::endl;
82  throw std::runtime_error (objRec->m_name + " cannot build ports");
83  }
84  }
86  if (objSend->m_portOut.count(portS) != 0 && objRec->m_portIn.count(portR) != 0){
87  if (forced || checkCompatibility(objSend, objRec, portS, portR)){
88  objSend->addPinOut(objRec, portS, portR);
89  objRec->addPinIn(objSend, portR);
90  objSend->addChild(objRec);
91  objRec->addParent(objSend);
92  done = true;
93  }
94  }
95  }
96  log->setPriority(bitpit::log::NORMAL);
97  if (!done) (*log)<<"warning: pin connection " << objSend->getName() << "[" << portS << "] --> " << objRec->getName() << "[" << portR << "] NOT linked. "<< std::endl;
98  log->setPriority(bitpit::log::DEBUG);
99  return done;
100 }
101 
107 void
109 
110  std::unordered_map<PortID, PortOut*> pinsOut = objSend->getPortsOut();
111  for (std::unordered_map<PortID, PortOut*>::iterator i = pinsOut.begin(); i != pinsOut.end(); i++){
112  if (i->second != nullptr){
113  std::vector<BaseManipulation*> linked = i->second->getLink();
114  for (int j=0; j<(int)linked.size(); j++){
115  if (linked[j] == objRec){
116  objSend->removePinOut(i->first,j);
117  objSend->unsetChild(objRec);
118  }
119  }
120  }
121  }
122 
123  std::unordered_map<PortID, PortIn*> pinsIn = objRec->getPortsIn();
124  for (std::unordered_map<PortID, PortIn*>::iterator i = pinsIn.begin(); i != pinsIn.end(); i++){
125  std::vector<BaseManipulation*> linked = i->second->getLink();
126  if (i->second != nullptr){
127  for (int j=0; j<(int)linked.size(); j++){
128  if (linked[j] == objSend){
129  objRec->removePinIn(i->first,j);
130  objRec->unsetParent(objSend);
131  }
132  }
133  }
134  }
135 
136 }
137 
146 void
147 removePin(BaseManipulation* objSend, BaseManipulation* objRec, PortID portS, PortID portR){
148 
149  objSend->removePinOut(objRec, portS);
150  objRec->removePinIn(objSend, portR);
151  objSend->unsetChild(objRec);
152  objRec->unsetParent(objSend);
153 
154 }
155 
164 bool
166  bool check = false;
167  PortIn* pinin = objRec->getPortsIn()[portR];
168  PortOut* pinout = objSend->getPortsOut()[portS];
169  DataType typeR = pinin->getDataType();
170  DataType typeS = pinout->getDataType();
171  check = (typeS == typeR);
172  return(check);
173 }
174 
175 }//end pin namespace
176 
185 void setLogger(std::string log){
187  bitpit::Logger* log = &bitpit::log::cout(MIMMO_LOG_FILE);
188  (*log) << "warning: logger already set -> cannot change logger name " << std::endl;
189  return;
190  }
191  MIMMO_LOG_FILE = log;
192 }
193 
198 void setLoggerDirectory(std::string dir){
200  bitpit::Logger* log = &bitpit::log::cout(MIMMO_LOG_FILE);
201  (*log) << "warning: logger already set -> cannot change logger directory " << std::endl;
202  return;
203  }
204  MIMMO_LOG_DIR = dir;
205 }
206 
211 void warningXML(bitpit::Logger* log, std::string name){
212  (*log)<<"warning in custom xml " << name << " constructor. No valid xml data found"<<std::endl;
213 }
214 
219 void setExpertMode(bool flag){
220  MIMMO_EXPERT = flag;
221 }
222 
228 }//end mimmo namespace
DataType getDataType()
Definition: InOut.cpp:234
Class DataType defines the container and the type of data communicated by ports.
Definition: InOut.hpp:53
void setLogger(std::string log)
void addPinOut(BaseManipulation *objOut, PortID portS, PortID portR)
void removePin(BaseManipulation *objSend, BaseManipulation *objRec, PortID portS, PortID portR)
FileDataInfo is a struct to stock data relative to names of external files.
ConnectionType getConnectionType()
bool checkCompatibility(BaseManipulation *objSend, BaseManipulation *objRec, PortID portS, PortID portR)
mimmo::IBinaryStream & operator>>(mimmo::IBinaryStream &buffer, mimmo::FileDataInfo &var)
void addParent(BaseManipulation *parent)
mimmo custom derivation of bitpit OBinaryStream (see relative doc)
mimmo::OBinaryStream & operator<<(mimmo::OBinaryStream &buf, const std::string &element)
void removePinIn(BaseManipulation *objIn, PortID portR)
std::unordered_map< PortID, PortOut * > getPortsOut()
void warningXML(bitpit::Logger *log, std::string name)
DataType getDataType()
Definition: InOut.cpp:129
BaseManipulation is the base class of any manipulation object of the library.
void addPinIn(BaseManipulation *objIn, PortID portR)
void unsetChild(BaseManipulation *child)
PortIn is the abstract PIN base class dedicated to carry data to a target class from other ones (inpu...
Definition: InOut.hpp:201
PortOut is the abstract PIN base class dedicated to exchange data from a target class to other ones (...
Definition: InOut.hpp:96
void addChild(BaseManipulation *child)
bool addPin(BaseManipulation *objSend, BaseManipulation *objRec, PortID portS, PortID portR, bool forced)
virtual void buildPorts()=0
std::unordered_map< PortID, PortOut * > m_portOut
std::string PortID
void removePinOut(BaseManipulation *objOut, PortID portS)
mimmo custom derivation of bitpit IBinaryStream (see relative doc)
std::unordered_map< PortID, PortIn * > m_portIn
void setExpertMode(bool flag)
std::unordered_map< PortID, PortIn * > getPortsIn()
void removeAllPins(BaseManipulation *objSend, BaseManipulation *objRec)
void setLoggerDirectory(std::string dir)
void unsetParent(BaseManipulation *parent)