Jpp  18.0.1-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Attributes | List of all members
JNET::JPrefix Class Reference

ControlHost prefix. More...

#include <JPrefix.hh>

Inheritance diagram for JNET::JPrefix:
JNET::JTag JNET::JDispatch

Public Member Functions

 JPrefix ()
 Default constructor. More...
 
 JPrefix (const JTag &tag, const long long int length)
 Constructor. More...
 
int getSize () const
 Get size. More...
 
void setSize (const long long int length)
 Set size. More...
 
void set (const JTag &tag, const long long int length)
 Set prefix. More...
 
const JTaggetTag () const
 Get tag. More...
 
JTaggetTag ()
 Get tag. More...
 
void setTag (const JTag &tag)
 Set tag. More...
 
void setTag (const std::string &tag)
 Set tag. More...
 
void setTag (const JTag_t id)
 Set tag. More...
 
JTag_t getID () const
 Get identifier. More...
 
std::string toString () const
 Convert tag to string. More...
 
 operator std::string () const
 Type conversion operators. More...
 
const char * c_str () const
 C-string. More...
 
const char operator[] (int i) const
 Get character. More...
 

Protected Attributes

long long int size
 
JTag_t id
 

Detailed Description

ControlHost prefix.

The ControlHost prefix is a light-weight data structure which consists of a tag and a length. The length is converted to network byte order and vice versa, using methods setSize() and getSize(), respectively.

Definition at line 31 of file JPrefix.hh.

Constructor & Destructor Documentation

JNET::JPrefix::JPrefix ( )
inline

Default constructor.

Definition at line 38 of file JPrefix.hh.

38  :
39  JTag(),
40  size(0)
41  {}
JTag()
Default constructor.
Definition: JTag.hh:43
long long int size
Definition: JPrefix.hh:92
JNET::JPrefix::JPrefix ( const JTag tag,
const long long int  length 
)
inline

Constructor.

Parameters
tagtag
lengthnumber of bytes

Definition at line 50 of file JPrefix.hh.

51  {
52  setTag (tag);
53  setSize(length);
54  }
void setSize(const long long int length)
Set size.
Definition: JPrefix.hh:73
void setTag(const JTag &tag)
Set tag.
Definition: JTag.hh:108

Member Function Documentation

int JNET::JPrefix::getSize ( ) const
inline

Get size.

Returns
number of bytes

Definition at line 62 of file JPrefix.hh.

63  {
64  return ntohl(size);
65  }
long long int size
Definition: JPrefix.hh:92
void JNET::JPrefix::setSize ( const long long int  length)
inline

Set size.

Parameters
lengthnumber of bytes

Definition at line 73 of file JPrefix.hh.

74  {
75  size = htonl(length);
76  }
long long int size
Definition: JPrefix.hh:92
void JNET::JPrefix::set ( const JTag tag,
const long long int  length 
)
inline

Set prefix.

Parameters
tagtag
lengthnumber of bytes

Definition at line 85 of file JPrefix.hh.

86  {
87  setTag (tag);
88  setSize(length);
89  }
void setSize(const long long int length)
Set size.
Definition: JPrefix.hh:73
void setTag(const JTag &tag)
Set tag.
Definition: JTag.hh:108
const JTag& JNET::JTag::getTag ( ) const
inlineinherited

Get tag.

Returns
tag

Definition at line 86 of file JTag.hh.

87  {
88  return static_cast<const JTag&>(*this);
89  }
ControlHost tag.
Definition: JTag.hh:38
JTag& JNET::JTag::getTag ( )
inlineinherited

Get tag.

Returns
tag

Definition at line 97 of file JTag.hh.

98  {
99  return static_cast<JTag&>(*this);
100  }
ControlHost tag.
Definition: JTag.hh:38
void JNET::JTag::setTag ( const JTag tag)
inlineinherited

Set tag.

Parameters
tagtag

Definition at line 108 of file JTag.hh.

109  {
110  id = tag.getID();
111  }
JTag_t getID() const
Get identifier.
Definition: JTag.hh:160
void JNET::JTag::setTag ( const std::string tag)
inlineinherited

Set tag.

This method may throw an exception.

Parameters
tagtag

Definition at line 121 of file JTag.hh.

122  {
123  if (!tag.empty() && tag.size() <= TAGSIZE) {
124 
125  char* __p = (char*) &(this->id);
126 
127  size_t i = 0;
128 
129  for ( ; i != tag.size(); ++i) {
130  __p[i] = tag[i];
131  }
132 
133  for ( ; i != TAGSIZE; ++i) {
134  __p[i] = '\0';
135  }
136 
137  } else {
138 
139  THROW(JControlHostException, "Invalid tag length <" << tag << "> " << tag.size());
140  }
141  }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
static const size_t TAGSIZE
Size of ControlHost tag.
Definition: JTag.hh:32
void JNET::JTag::setTag ( const JTag_t  id)
inlineinherited

Set tag.

Parameters
ididentifier

Definition at line 149 of file JTag.hh.

150  {
151  this->id = id;
152  }
JTag_t id
Definition: JTag.hh:254
JTag_t JNET::JTag::getID ( ) const
inlineinherited

Get identifier.

Returns
identifier

Definition at line 160 of file JTag.hh.

161  {
162  return id;
163  }
JTag_t id
Definition: JTag.hh:254
std::string JNET::JTag::toString ( ) const
inlineinherited

Convert tag to string.

Returns
tag

Definition at line 171 of file JTag.hh.

172  {
173  int pos = TAGSIZE;
174 
175  const char* __p = (const char*) &(this->id);
176 
177  while (pos != 0 && __p[pos-1] == '\0') {
178  --pos;
179  }
180 
181  return std::string(__p, pos);
182  }
static const size_t TAGSIZE
Size of ControlHost tag.
Definition: JTag.hh:32
then awk string
JNET::JTag::operator std::string ( ) const
inlineinherited

Type conversion operators.

Returns
tag

Definition at line 190 of file JTag.hh.

191  {
192  return toString();
193  }
std::string toString() const
Convert tag to string.
Definition: JTag.hh:171
const char* JNET::JTag::c_str ( ) const
inlineinherited

C-string.

Returns
tag

Definition at line 201 of file JTag.hh.

202  {
203  return (const char*) &(this->id);
204  }
JTag_t id
Definition: JTag.hh:254
const char JNET::JTag::operator[] ( int  i) const
inlineinherited

Get character.

Parameters
iindex
Returns
character at index

Definition at line 213 of file JTag.hh.

214  {
215  const char* __p = (const char*) &(this->id);
216 
217  return __p[i];
218  }

Member Data Documentation

long long int JNET::JPrefix::size
protected

Definition at line 92 of file JPrefix.hh.

JTag_t JNET::JTag::id
protectedinherited

Definition at line 254 of file JTag.hh.


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