Jpp  master_rocky-37-gf0c5bc59d
the software that should make you happy
Public Member Functions | Public Attributes | Static Public Attributes | Friends | List of all members
JNET::JHostname Struct Reference

Auxiliary data structure for hostname and port number. More...

#include <JHostname.hh>

Inheritance diagram for JNET::JHostname:
JLANG::JEquals< JHostname > KM3NETDAQ::JDAQProcess

Public Member Functions

 JHostname ()
 Default constructor. More...
 
 JHostname (const std::string &buffer)
 Constructor. More...
 
 JHostname (const std::string &hostname, const int port)
 Constructor. More...
 
bool equals (const JHostname &hostname) const
 Equal method. More...
 
void set (const std::string &buffer)
 Set hostname and port number. More...
 

Public Attributes

std::string hostname
 
int port
 

Static Public Attributes

static const char SEPARATOR = ':'
 Separation character between hostname and port number. More...
 

Friends

std::istream & operator>> (std::istream &in, JHostname &object)
 Read hostname from input stream. More...
 
std::ostream & operator<< (std::ostream &out, const JHostname &object)
 Write hostname to output stream. More...
 

Detailed Description

Auxiliary data structure for hostname and port number.

Definition at line 33 of file JHostname.hh.

Constructor & Destructor Documentation

◆ JHostname() [1/3]

JNET::JHostname::JHostname ( )
inline

Default constructor.

Definition at line 45 of file JHostname.hh.

45  :
46  hostname(""),
47  port(-1)
48  {}
std::string hostname
Definition: JHostname.hh:171

◆ JHostname() [2/3]

JNET::JHostname::JHostname ( const std::string &  buffer)
inline

Constructor.

The argument correponds to the hostname and an optional port number of the server. The syntax is hostname[:port]. The default port number is DISPATCH_PORT. If the complete buffer corresponds to an integer value, it is interpreted as the port number.

Parameters
bufferhost name and optional port number

Definition at line 61 of file JHostname.hh.

62  {
63  set(buffer);
64  }
void set(const std::string &buffer)
Set hostname and port number.
Definition: JHostname.hh:104

◆ JHostname() [3/3]

JNET::JHostname::JHostname ( const std::string &  hostname,
const int  port 
)
inline

Constructor.

Parameters
hostnamehostname
portport number

Definition at line 73 of file JHostname.hh.

75  {
76  this->hostname = hostname;
77  this->port = port;
78  }

Member Function Documentation

◆ equals()

bool JNET::JHostname::equals ( const JHostname hostname) const
inline

Equal method.

Parameters
hostnamehost name and port
Returns
true if this host name and port is equal to given host name and port; else false

Definition at line 87 of file JHostname.hh.

88  {
89  return (this->hostname == hostname.hostname &&
90  this->port == hostname.port);
91  }

◆ set()

void JNET::JHostname::set ( const std::string &  buffer)
inline

Set hostname and port number.

The argument correponds to the hostname and an optional port number of the server.
The syntax is hostname[:port]. The default port number is DISPATCH_PORT.
If the complete buffer corresponds to an integer value, it is interpreted as the port number.

Parameters
bufferhost name and optional port number

Definition at line 104 of file JHostname.hh.

105  {
106  using namespace std;
107 
108  const string::size_type pos = buffer.find(SEPARATOR);
109 
110  if (pos != string::npos) {
111 
112  this->hostname = buffer.substr(0, pos);
113 
114  istringstream(buffer.substr(pos + 1)) >> this->port;
115 
116  } else {
117 
118  bool is_number = true;
119 
120  for (string::const_iterator i = buffer.begin(); is_number && i != buffer.end(); ++i) {
121  is_number &= isdigit(*i);
122  }
123 
124  if (is_number) {
125 
126  this->hostname = "";
127 
128  istringstream(buffer) >> this->port;
129 
130  } else {
131 
132  this->hostname = buffer;
133  this->port = DISPATCH_PORT;
134  }
135  }
136  }
static const int DISPATCH_PORT
Default ControlHost port.
Definition: JHostname.hh:27
Definition: JSTDTypes.hh:14
static const char SEPARATOR
Separation character between hostname and port number.
Definition: JHostname.hh:39

Friends And Related Function Documentation

◆ operator>>

std::istream& operator>> ( std::istream &  in,
JHostname object 
)
friend

Read hostname from input stream.

Parameters
ininput stream
objecthostname
Returns
input stream

Definition at line 146 of file JHostname.hh.

147  {
148  std::string buffer;
149 
150  if (in >> buffer) {
151  object.set(buffer);
152  }
153 
154  return in;
155  }

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const JHostname object 
)
friend

Write hostname to output stream.

Parameters
outoutput stream
objecthostname
Returns
output stream

Definition at line 165 of file JHostname.hh.

166  {
167  return out << object.hostname << SEPARATOR << object.port;
168  }

Member Data Documentation

◆ SEPARATOR

const char JNET::JHostname::SEPARATOR = ':'
static

Separation character between hostname and port number.

Definition at line 39 of file JHostname.hh.

◆ hostname

std::string JNET::JHostname::hostname

Definition at line 171 of file JHostname.hh.

◆ port

int JNET::JHostname::port

Definition at line 172 of file JHostname.hh.


The documentation for this struct was generated from the following file: