Jpp
 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,
51  const int length)
52  {
53  setTag (tag);
54  setSize(length);
55  }
56 
57 
58  /**
59  * Get size.
60  *
61  * \return number of bytes
62  */
63  int getSize() const
64  {
65  return ntohl(size);
66  }
67 
68 
69  /**
70  * Set size.
71  *
72  * \param length number of bytes
73  */
74  void setSize(const int length)
75  {
76  size = htonl(length);
77  }
78 
79 
80  /**
81  * Set prefix.
82  *
83  * \param tag tag
84  * \param length number of bytes
85  * \return true if OK; else false
86  */
87  void set(const JTag& tag,
88  const int length)
89  {
90  setTag (tag);
91  setSize(length);
92  }
93 
94  protected:
95  int size;
96  };
97 }
98 
99 #endif
ControlHost prefix.
Definition: JPrefix.hh:31
Exceptions.
void setSize(const int length)
Set size.
Definition: JPrefix.hh:74
char tag[TAGSIZE]
Definition: JTag.hh:247
int getSize() const
Get size.
Definition: JPrefix.hh:63
JPrefix()
Default constructor.
Definition: JPrefix.hh:38
void setTag(const JTag &tag)
Set tag.
Definition: JTag.hh:105
void set(const JTag &tag, const int length)
Set prefix.
Definition: JPrefix.hh:87
JPrefix(const JTag &tag, const int length)
Constructor.
Definition: JPrefix.hh:50
ControlHost tag.
Definition: JTag.hh:35