File: message.h

package info (click to toggle)
sinfo 0.0.48-2.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 3,332 kB
  • sloc: sh: 11,213; cpp: 6,722; makefile: 271; xml: 151; perl: 149
file content (53 lines) | stat: -rw-r--r-- 1,208 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef _message_h
#define _message_h

#include <stdexcept>
#include <boost/shared_array.hpp>


#define STANDARDBUFFERSIZE 4096
#define STANDARDBUFFERINCREMENT 1024


class MessageException : public std::runtime_error
{
public:
  explicit MessageException(const std::string& what):std::runtime_error(what)
  {}

  virtual ~MessageException() throw() {}
};


class Message
{
private:
  boost::shared_array<char> memory;
  unsigned long memorySize;  // size of allocated memory
  unsigned long startIndex;  // memory[startIndex] is the first valid byte
  unsigned long endIndex;    // memory[endIndex]   is the byte AFTER the last valid byte


public:
  Message(unsigned long length=STANDARDBUFFERSIZE, const char * data=0);
  Message(const Message& message);
  ~Message();

  bool dontSendFlag;

  void setMessage(unsigned long length, const char * data);

  Message & operator= (const Message & message);
  const char & operator [] (unsigned long idx);

  const char * getDataPtr() const;
  unsigned long size() const;
  void clear();

  void pushFrontMemory(const void *src, size_t n);
  void pushBackMemory(const void *src, size_t n);
  void popFrontMemory(void *dest, size_t n);
};


#endif // _message_h