RINASim  October 2016
Documentation of framework for OMNeT++
Utils.h
Go to the documentation of this file.
1 // The MIT License (MIT)
2 //
3 // Copyright (c) 2014-2016 Brno University of Technology, PRISTINE project
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // THE SOFTWARE.
22 
23 /*
24  * Utils.h
25  *
26  * Created on: Mar 5, 2015
27  * Author: gaixas1
28  */
29 
30 #ifndef UTILS_H_
31 #define UTILS_H_
32 
33 #include <string>
34 #include <sstream>
35 #include <vector>
36 
37 #include "omnetpp.h"
38 
39 /*
40  * Explode a string into a vector of strings, given a delimiter
41  *
42  */
43 std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems);
44 std::vector<std::string> split(const std::string &s, char delim);
45 
46 /*
47  * Implode the first n values of a vector of string into a strings, separated by a delimiter
48  *
49  */
50 std::string join(const std::vector<std::string> &elems, const unsigned int n, const char delim);
51 
52 
53 /*
54  * Check if the first value is a prefix of the second
55  *
56  */
57 bool isPrefix(std::string prefix, std::string s);
58 
64 void setPolicyDisplayString(cModule* mod, const char* str = nullptr);
65 
74 void interconnectModules(cModule* m1, cModule* m2, std::string n1, std::string n2);
75 
76 
90 template<typename modType>
91 modType getRINAModule( cModule* curMod,
92  int parentLevel,
93  std::initializer_list<const char*> modPath,
94  bool nullCheck = true)
95 {
96  std::ostringstream modulePath;
97  while (parentLevel--) { modulePath << ".^"; }
98  for (auto elem : modPath) { modulePath << "." << elem; }
99  cModule* mod = curMod->getModuleByPath(modulePath.str().c_str());
100  return (nullCheck ? check_and_cast<modType>(mod) : dynamic_cast<modType>(mod));
101 }
102 
103 
104 #endif /* UTILS_H_ */
std::string join(const std::vector< std::string > &elems, const unsigned int n, const char delim)
Definition: Utils.cc:48
modType getRINAModule(cModule *curMod, int parentLevel, std::initializer_list< const char * > modPath, bool nullCheck=true)
Definition: Utils.h:91
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
Definition: Utils.cc:33
void interconnectModules(cModule *m1, cModule *m2, std::string n1, std::string n2)
Definition: Utils.cc:79
bool isPrefix(std::string prefix, std::string s)
Definition: Utils.cc:62
void setPolicyDisplayString(cModule *mod, const char *str=nullptr)
Definition: Utils.cc:69