C++ IP API  9.5.8
TCP & UDP for virtual user scripts
IpEndPoint.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "fc.h"
4 
5 #include <string>
6 #include "Address.h"
7 using namespace std;
8 
9 namespace Facilita
10 {
20  class FC_API IpEndPoint
21  {
22  public:
29  static const IpEndPoint Any;
39  static const IpEndPoint None;
46  static const IpEndPoint Local;
56  static const IpEndPoint All;
57  static const IpEndPoint Broadcast;
58 
60  enum AddressType {
62  ANY,
64  ALL,
65  BROADCAST
66  };
67 
69  IpEndPoint();
72  IpEndPoint(int port);
74  IpEndPoint(const IpEndPoint&);
79  IpEndPoint(const string& host, int port=0, AddressType addressType=STANDARD);
81  IpEndPoint(SOCKADDR_IN& addr);
84  IpEndPoint& operator=(const IpEndPoint& other);
88 
90  const string& host() const { return _host; }
92  int port() const { return _port; }
94  AddressType addressType() const { return _addressType;}
96  bool isLegal() const;
98  bool isAll() const;
100  bool isBroadcast() const;
102  bool isStandard() const;
104 
105  bool IpEndPoint::isIPV4() const;
106  bool IpEndPoint::isIPV6() const;
107 
109  string toString() const;
113  IpEndPoint withPort(int port) const;
114  private:
115 #pragma warning(disable:4251)
116  string _host;
117 #pragma warning(default:4251)
118  int _port;
119  AddressType _addressType;
120  };
121 
122  inline ostream& operator<<(ostream& out, const IpEndPoint& addr) { out << addr.toString(); return out; }
123 
124  inline bool operator<(const IpEndPoint& left, const IpEndPoint& right) {
125  if (left.host()==right.host())
126  {
127  return left.port()<right.port();
128  }
129  return left.host()<right.host();
130  }
131  inline bool operator==(const IpEndPoint& left, const IpEndPoint& right) {
132  return left.port()==right.port() &&
133  left.host()==right.host() &&
134  left.addressType()==right.addressType()
135  ;
136  }
137 
138 }
bool operator==(const IpEndPoint &left, const IpEndPoint &right)
Definition: IpEndPoint.h:131
static const IpEndPoint Local
Definition: IpEndPoint.h:46
Definition: IpEndPoint.h:61
const string & host() const
The host string (IP address).
Definition: IpEndPoint.h:90
string toString() const
The string describing this object.
STL namespace.
This class encapsulates IP address and port. Static member instances represent common patterns and ad...
Definition: IpEndPoint.h:20
Definition: IpEndPoint.h:63
static const IpEndPoint All
This object and is used in server scripts as in the example.
Definition: IpEndPoint.h:56
AddressType addressType() const
The AddressType of this object.
Definition: IpEndPoint.h:94
Definition: IpEndPoint.h:62
static const IpEndPoint Broadcast
Definition: IpEndPoint.h:57
Definition: IpEndPoint.h:64
static const IpEndPoint None
This object is the value given to for to an uninitialized variable.
Definition: IpEndPoint.h:39
ostream & operator<<(ostream &out, const IpEndPoint &addr)
Definition: IpEndPoint.h:122
Definition: IpEndPoint.h:9
int port() const
The port (IP port).
Definition: IpEndPoint.h:92
static const IpEndPoint Any
This object is a "wild card" and used to represent an IP address and port where the actual values use...
Definition: IpEndPoint.h:29
AddressType
A low level enumeration used internally.
Definition: IpEndPoint.h:60
bool operator<(const IpEndPoint &left, const IpEndPoint &right)
Definition: IpEndPoint.h:124