RINASim  October 2016
Documentation of framework for OMNeT++
DCAddr.cc
Go to the documentation of this file.
1 
2 #include "DCAddr.h"
3 #include "Utils.h"
4 
5 namespace NSPSimpleDC {
6 
7  using namespace std;
8 
9  DCAddr::DCAddr(): type(-1), a(0), b(0){}
10 
11  DCAddr::DCAddr(const int & _type, const int & _a, const int & _b):
12  type(_type), a(_a), b(_b){}
13 
14  DCAddr::DCAddr(const string & s_addr) {
15  vector<string> s_vec = split(s_addr, '.');
16  if(s_vec.size() != 3) {
17  type = -1;
18  } else {
19  type = atoi(s_vec[0].c_str());
20  a = atoi(s_vec[1].c_str());
21  b = atoi(s_vec[2].c_str());
22  }
23  }
24 
25  bool DCAddr::operator<( const DCAddr & o ) const {
26  if(type < o.type) { return true; }
27  if(type > o.type) { return false;}
28 
29  if(a < o.a) { return true; }
30  if(a > o.a) { return false;}
31 
32  if(b < o.b) { return true; }
33 
34  return false;
35  }
36 
37  bool DCAddr::operator==( const DCAddr & o ) const {
38  return (type == o.type && a == o.a && b == o.b);
39  }
40 
41  bool DCAddr::operator!=( const DCAddr & o ) const {
42  return (type != o.type || a != o.a || b != o.b);
43  }
44 
45  string DCAddr::toString() {
46  return to_string (type) + "." +to_string (a) + "." +to_string (b);
47  }
48 
49  std::ostream& operator << (std::ostream &o, const DCAddr &a) {
50  o << a.type << "." << a.a << "."<<a.b;
51  return o;
52  }
53 }
bool operator!=(const DCAddr &n) const
Definition: DCAddr.cc:41
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
Definition: Utils.cc:33
bool operator==(const DCAddr &n) const
Definition: DCAddr.cc:37
bool operator<(const DCAddr &n) const
Definition: DCAddr.cc:25
string toString()
Definition: DCAddr.cc:45
std::ostream & operator<<(std::ostream &o, const DCAddr &a)
Definition: DCAddr.cc:49