Jpp  15.0.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPrefix.hh
Go to the documentation of this file.
1 #ifndef __JNET__JCONTROLHOSTPREFIX__
2 #define __JNET__JCONTROLHOSTPREFIX__
3 
4 #include <istream>
5 #include <ostream>
6 #include <string>
7 #include <arpa/inet.h>
8 
9 #include "JLang/JException.hh"
10 #include "JNet/JTag.hh"
11 
12 
13 /**
14  * \author mdejong
15  */
16 
17 namespace JNET {}
18 namespace JPP { using namespace JNET; }
19 
20 namespace JNET {
21 
22 
23  /**
24  * ControlHost prefix.
25  *
26  * The ControlHost prefix is a light-weight data structure which
27  * consists of a tag and a length.
28  * The length is converted to network byte order and vice versa,
29  * using methods setSize() and getSize(), respectively.
30  */
31  class JPrefix :
32  public JTag
33  {
34  public:
35  /**
36  * Default constructor.
37  */
38  JPrefix() :
39  JTag(),
40  size(0)
41  {}
42 
43 
44  /**
45  * Constructor.
46  *
47  * \param tag tag
48  * \param length number of bytes
49  */
50  JPrefix(const JTag& tag, const long long int length)
51  {
52  setTag (tag);
53  setSize(length);
54  }
55 
56 
57  /**
58  * Get size.
59  *
60  * \return number of bytes
61  */
62  int getSize() const
63  {
64  return ntohl(size);
65  }
66 
67 
68  /**
69  * Set size.
70  *
71  * \param length number of bytes
72  */
73  void setSize(const long long int length)
74  {
75  size = htonl(length);
76  }
77 
78 
79  /**
80  * Set prefix.
81  *
82  * \param tag tag
83  * \param length number of bytes
84  * \return true if OK; else false
85  */
86  void set(const JTag& tag, const long long int length)
87  {
88  setTag (tag);
89  setSize(length);
90  }
91 
92  protected:
93  long long int size;
94  };
95 }
96 
97 #endif
ControlHost prefix.
Definition: JPrefix.hh:31
Exceptions.
void setSize(const long long int length)
Set size.
Definition: JPrefix.hh:73
int getSize() const
Get size.
Definition: JPrefix.hh:62
JPrefix()
Default constructor.
Definition: JPrefix.hh:38
void setTag(const JTag &tag)
Set tag.
Definition: JTag.hh:108
long long int size
Definition: JPrefix.hh:93
JPrefix(const JTag &tag, const long long int length)
Constructor.
Definition: JPrefix.hh:50
void set(const JTag &tag, const long long int length)
Set prefix.
Definition: JPrefix.hh:86
ControlHost tag.
Definition: JTag.hh:38
ControlHost tag.