RINASim  October 2016
Documentation of framework for OMNeT++
Address.cc
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 #include <Address.h>
24 
26 
27 Address::Address() : ipcAddress(APN()), difName(""), apname(APN())
28 {
29 }
30 
31 Address::Address(std::string composite)
32 {
33  std::string delimiter = "_";
34 
35  size_t pos = 0;
36  std::vector<std::string> tokens;
37  while ((pos = composite.find(delimiter)) != std::string::npos) {
38  tokens.push_back(composite.substr(0, pos));
39  composite.erase(0, pos + delimiter.length());
40  }
41  tokens.push_back(composite);
42 
43  if (tokens.size() == 2) {
44  ipcAddress = APN(tokens.front());
45  difName = DAP(tokens.back());
46  std::ostringstream os;
47  os << ipcAddress << "_" << difName;
48  apname = APN(os.str().c_str());
49  }
50 
51  if (tokens.size() == 1) {
52  apname = APN(composite);
53  }
54 
55 
56 }
57 
58 Address::Address(const char* ipcaddr, const char* difnam) :
59  ipcAddress(APN(ipcaddr)), difName(DAP(difnam))
60 {
61  std::ostringstream os;
62  os << ipcaddr << "_" << difnam;
63  apname = APN(os.str().c_str());
64 }
65 
67 {
68  ipcAddress = APN();
69  difName = DAP();
70  apname = APN();
71 }
72 
73 const DAP& Address::getDifName() const
74 {
75  return difName;
76 }
77 
78 void Address::setDifName(const DAP& difName)
79 {
80  this->difName = difName;
81 }
82 
84 {
85  return ipcAddress;
86 }
87 
88 bool Address::operator ==(const Address& other) const
89 {
90  return ipcAddress == other.ipcAddress
91  && difName == other.difName
92  && apname == other.apname;
93 }
94 
95 bool Address::operator <(const Address& other) const
96 {
97  if(!(ipcAddress == other.ipcAddress)){
98  return ipcAddress.getName() < other.ipcAddress.getName();
99  } else if(!(difName == other.difName)){
100  return difName.getName() < other.difName.getName();
101  } else {
102  return apname.getName() < other.apname.getName();
103  }
104 }
105 
106 std::string Address::info() const
107 {
108  std::ostringstream os;
109  if (!ipcAddress.getName().empty() && !difName.getName().empty())
110  os << ipcAddress << "(" << difName << ")";
111  return os.str();
112 }
113 
115 {
116  return ipcAddress.getName().empty() && difName.getName().empty();
117 }
118 
119 const APN& Address::getApn() const
120 {
121  return apname;
122 }
123 
124 void Address::setIpcAddress(const APN& ipcAddress)
125 {
126  this->ipcAddress = ipcAddress;
127 }
128 
129 std::ostream& operator <<(std::ostream& os, const Address& addr)
130 {
131  return os << addr.info();
132 }
133 
134 std::ostream& operator <<(std::ostream& os, const Addresses& dims)
135 {
136  for (AddrCItem it = dims.begin(); it != dims.end(); ++it)
137  os << it->info() << endl;
138  return os;
139 }
140 
141 Address::Address(APN apname) : Address(apname.getName())
142 {
143 }
const DAP & getDifName() const
Getter of common DIF name.
Definition: Address.cc:73
void setDifName(const DAP &difName)
Setter of common DIF name.
Definition: Address.cc:78
std::list< Address > Addresses
Definition: Address.h:146
void setIpcAddress(const APN &ipcAddress)
Setter of IPC Process address which should be unambiguous within DIF.
Definition: Address.cc:124
bool operator==(const Address &other) const
Definition: Address.cc:88
DAP difName
Commong DIF name represented by DAP.
Definition: Address.h:138
Application Process Name class.
Definition: APN.h:36
virtual ~Address()
Destructor assigning default values.
Definition: Address.cc:66
APN ipcAddress
IPC Process address represented by APN.
Definition: Address.h:133
const APN & getIpcAddress() const
Getter of IPC Process address which should be unambiguous within DIF.
Definition: Address.cc:83
static const Address UNSPECIFIED_ADDRESS
Definition: Address.h:44
std::string info() const
Info text output suitable for << string streams and WATCH.
Definition: Address.cc:106
Addresses::const_iterator AddrCItem
Definition: Address.h:147
bool operator<(const Address &other) const
Definition: Address.cc:95
const std::string & getName() const
Gets DAP string name representation.
Definition: DAP.cc:49
bool isUnspecified() const
Checks whether a given Address is unspecified which means that it has empty attributes.
Definition: Address.cc:114
APN apname
Concatenation of IPC Process address and DIF name represented as APN.
Definition: Address.h:143
const APN & getApn() const
Getter of unique APN which is initialized during object construction.
Definition: Address.cc:119
const std::string & getName() const
Gets APN string name representation.
Definition: APN.cc:40
Address()
Constructor of blank Address.
Definition: Address.cc:27
Address class holds IPC Process identification.
Definition: Address.h:42
Distributed Application Process name a.k.a. DAP class.
Definition: DAP.h:34
std::ostream & operator<<(std::ostream &os, const Address &addr)
<< operator overload that calls Address.info() method
Definition: Address.cc:129