ANNA Suite  2020b
Multipurpose development suite for Telco applications
INetAddress.hpp
Go to the documentation of this file.
1 // ANNA - Anna is Not Nothingness Anymore //
2 // //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
4 // //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7 
8 
9 #ifndef anna_comm_INetAddress_hpp
10 #define anna_comm_INetAddress_hpp
11 
12 #include <sys/types.h>
13 #include <sys/socket.h>
14 #include <netinet/in.h>
15 #include <arpa/inet.h>
16 
17 #include <string>
18 
20 
21 namespace anna {
22 
23 namespace xml {
24 class Node;
25 }
26 
27 namespace comm {
28 
29 class Device;
30 
34 class INetAddress {
35 public:
39  INetAddress() : a_device(NULL), a_port(-1) {}
40 
46  INetAddress(const Device* device, const int port = -1) : a_device(device), a_port(port) {;}
47 
52  INetAddress(const INetAddress& other) : a_device(other.a_device) , a_port(other.a_port) {;}
53 
59  const Device* getDevice(const bool exceptionWhenNull = true) const noexcept(false);
60 
65  int getPort() const { return a_port; }
66 
71  void setAddress(const Device* device) { a_device = device; }
72 
77  void setPort(const int port) { a_port = port; }
78 
83  INetAddress& operator = (const INetAddress& right) { a_device = right.a_device; a_port = right.a_port; return *this; }
84 
90  bool operator == (const INetAddress& right) const { return a_device == right.a_device && a_port == right.a_port; }
91 
96  bool isNull() const { return (a_device == NULL || a_port == -1); }
97 
101  void clear() { a_device = NULL; a_port = -1; }
102 
107  std::string asString() const ;
108 
113  std::string serialize() const ;
114 
120  xml::Node* asXML(xml::Node* parent) const noexcept(false);
121 
122 private:
123  const Device* a_device;
124  int a_port;
125 };
126 
127 }
128 }
129 
130 #endif
131 
132 
133 
Definition: INetAddress.hpp:34
INetAddress()
Definition: INetAddress.hpp:39
Definition: Node.hpp:56
Definition: Device.hpp:37
INetAddress(const INetAddress &other)
Definition: INetAddress.hpp:52
void setAddress(const Device *device)
Definition: INetAddress.hpp:71
void clear()
Definition: INetAddress.hpp:101
bool isNull() const
Definition: INetAddress.hpp:96
xml::Node Node
Definition: Node.hpp:21
Definition: app.hpp:12
INetAddress(const Device *device, const int port=-1)
Definition: INetAddress.hpp:46
int getPort() const
Definition: INetAddress.hpp:65
void setPort(const int port)
Definition: INetAddress.hpp:77