TTEthernet Model for INET Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
HelperFunctions.cc
Go to the documentation of this file.
1 /*
2  * HelperFunctions.cc
3  *
4  * Created on: Dec 7, 2011
5  * Author: tillsteinbach
6  */
7 
8 #include "HelperFunctions.h"
9 
10 #include <sstream>
11 #include "cmodule.h"
12 
13 std::vector<std::string>& split(const std::string &string, char delimiter, std::vector<std::string> &elements){
14  std::stringstream stringStream(string);
15  std::string item;
16 
17  while(std::getline(stringStream, item, delimiter)){
18  std::stringstream trimmer;
19  trimmer << item;
20  trimmer >> item;
21  elements.push_back(item);
22  }
23  return elements;
24 }
25 
26 std::string& replaceAll(std::string &string, std::string toFind, std::string replacement){
27  size_t pos = string.find(toFind);
28  while(pos!=std::string::npos){
29  string.replace(pos,toFind.length(),replacement);
30  pos = string.find(toFind);
31  }
32  return string;
33 }
34 
35 void addPath(cPar &parameter, std::string &pathToAdd){
36  std::string path = parameter.stdstringValue();
37  if(path.length()>0)
38  path.append(",");
39  path.append(pathToAdd);
40  parameter.setStringValue(path);
41 }
42 
43 cGate* gateByFullPath(std::string &path){
44  std::size_t pos = path.rfind('.');
45  if(pos!=std::string::npos){
46  std::string modulePath = path.substr(0,pos);
47  std::string gateName = path.substr(pos+1);
48  cModule* module = cSimulation::getActiveSimulation()->getModuleByPath(modulePath.c_str());
49  if(module){
50  return module->gate(gateName.c_str());
51  }
52  }
53  return NULL;
54 }
55 
56 uint64_t ticksToTransparentClock(uint64_t ticks, simtime_t tick){
57  return secondsToTransparentClock(ticks*tick);
58 }
59 
60 uint64_t secondsToTransparentClock(simtime_t seconds){
61  return ((seconds.raw() * 0x10000) / pow10(SIMTIME_NS-seconds.getScaleExp()));
62 }
63 
64 uint64_t transparentClockToTicks(uint64_t transparentClock, simtime_t tick){
65  return transparentClock/secondsToTransparentClock(tick);
66 }