TTEthernet Model for INET Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
HelperFunctions.cc File Reference
#include "HelperFunctions.h"
#include <sstream>
#include "cmodule.h"

Go to the source code of this file.

Functions

std::vector< std::string > & split (const std::string &string, char delimiter, std::vector< std::string > &elements)
 Splits a string into a vector of strings by using the delimiter character as separator. More...
 
std::string & replaceAll (std::string &string, std::string toFind, std::string replacement)
 Replaces all occurrences of a string by another string. More...
 
void addPath (cPar &parameter, std::string &pathToAdd)
 Adds a path to a parameter that contains paths to elements. More...
 
cGate * gateByFullPath (std::string &path)
 Returns the gate defined by an object path. More...
 
uint64_t ticksToTransparentClock (uint64_t ticks, simtime_t tick)
 Converts value in ticks to the transparent clock unit that is ns*0x10000. More...
 
uint64_t secondsToTransparentClock (simtime_t seconds)
 Converts value in seconds to the transparent clock unit that is ns*0x10000. More...
 
uint64_t transparentClockToTicks (uint64_t transparentClock, simtime_t tick)
 Converts value in the transparent clock unit that is ns*0x10000 to ticks. More...
 

Function Documentation

void addPath ( cPar &  parameter,
std::string &  pathToAdd 
)

Adds a path to a parameter that contains paths to elements.

Parameters
parameterthe parameter object that contains the paths
pathToAdda string with the path that should be added to the parameter

Definition at line 35 of file HelperFunctions.cc.

35  {
36  std::string path = parameter.stdstringValue();
37  if(path.length()>0)
38  path.append(",");
39  path.append(pathToAdd);
40  parameter.setStringValue(path);
41 }
cGate* gateByFullPath ( std::string &  path)

Returns the gate defined by an object path.

Parameters
paththe path to the gate
Returns
reference to the gate defined by path or NULL if no such gate was found

Definition at line 43 of file HelperFunctions.cc.

Referenced by TTEthernetModel::Buffer::handleParameterChange().

43  {
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 }
std::string& replaceAll ( std::string &  string,
std::string  toFind,
std::string  replacement 
)

Replaces all occurrences of a string by another string.

Parameters
stringthe input string where the substrings are replaced
toFindthe substring that should be replaced
replacementthe string that replaces the toFind string
Returns
reference to the the modified string

Definition at line 26 of file HelperFunctions.cc.

26  {
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 }
uint64_t secondsToTransparentClock ( simtime_t  seconds)

Converts value in seconds to the transparent clock unit that is ns*0x10000.

Parameters
secondsnumber of seconds to convert
Returns
transparent clock representation of seconds

Definition at line 60 of file HelperFunctions.cc.

Referenced by TTEthernetModel::TTEOutput::setTransparentClock(), ticksToTransparentClock(), and transparentClockToTicks().

60  {
61  return ((seconds.raw() * 0x10000) / pow10(SIMTIME_NS-seconds.getScaleExp()));
62 }
std::vector<std::string>& split ( const std::string &  string,
char  delimiter,
std::vector< std::string > &  elements 
)

Splits a string into a vector of strings by using the delimiter character as separator.

Parameters
stringthe input string that is splitted
delimiterthe character that is used to split the string
elementsthe vector in which the splitted strings are added
Returns
reference to the the elements vector

Definition at line 13 of file HelperFunctions.cc.

Referenced by TTEthernetModel::TTEOutput::handleParameterChange(), TTEthernetModel::TTEApplicationBase::handleParameterChange(), TTEthernetModel::Buffer::handleParameterChange(), and TTEthernetModel::TTEInput::handleParameterChange().

13  {
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 }
uint64_t ticksToTransparentClock ( uint64_t  ticks,
simtime_t  tick 
)

Converts value in ticks to the transparent clock unit that is ns*0x10000.

Parameters
ticksnumber of ticks
ticklength of one tick in seconds
Returns
transparent clock representation of ticks

Definition at line 56 of file HelperFunctions.cc.

Referenced by TTEthernetModel::TTEOutput::setTransparentClock().

56  {
57  return secondsToTransparentClock(ticks*tick);
58 }
uint64_t transparentClockToTicks ( uint64_t  transparentClock,
simtime_t  tick 
)

Converts value in the transparent clock unit that is ns*0x10000 to ticks.

Parameters
transparentClockvalue in transparentClock
ticklength of one tick in seconds
Returns
ticks representation of transparent clock value

Definition at line 64 of file HelperFunctions.cc.

64  {
65  return transparentClock/secondsToTransparentClock(tick);
66 }