]> git.mxchange.org Git - flightgear.git/blob - src/Server/messagebuf.hxx
Tune up the starter torque to match the recent changes to engine
[flightgear.git] / src / Server / messagebuf.hxx
1 // messagebuf.hxx -- Multiplayer Client/Server message buffer class\r
2 //\r
3 // Written by John Barrett, started November 2003.\r
4 //\r
5 // Copyright (C) 2003  John R. Barrett - jbarrett@accesshosting.com\r
6 //\r
7 // This program is free software; you can redistribute it and/or\r
8 // modify it under the terms of the GNU General Public License as\r
9 // published by the Free Software Foundation; either version 2 of the\r
10 // License, or (at your option) any later version.\r
11 //\r
12 // This program is distributed in the hope that it will be useful, but\r
13 // WITHOUT ANY WARRANTY; without even the implied warranty of\r
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
15 // General Public License for more details.\r
16 //\r
17 // You should have received a copy of the GNU General Public License\r
18 // along with this program; if not, write to the Free Software\r
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
20 //\r
21 \r
22 \r
23 #ifndef _FG_MPS_MESSAGEBUF_HXX\r
24 #define _FG_MPS_MESSAGEBUF_HXX\r
25 \r
26 #include <simgear/compiler.h>\r
27 \r
28 #include STL_STRING\r
29 #include <stdexcept>\r
30 \r
31 SG_USING_STD(string);\r
32 SG_USING_STD(invalid_argument);\r
33 \r
34 class FGMPSDataException : public invalid_argument\r
35 {\r
36 public:\r
37     FGMPSDataException( const string& what_string )\r
38         : invalid_argument(what_string) {}\r
39 };\r
40 \r
41 class FGMPSMessageBuf \r
42 {\r
43 \r
44 private:\r
45         string          buf;\r
46         size_t          pos;\r
47         unsigned char   tmp[16];\r
48 \r
49 public:\r
50 \r
51         FGMPSMessageBuf()               { init(""); }\r
52         FGMPSMessageBuf(string data)    { init(data); }\r
53 \r
54         ~FGMPSMessageBuf() {}\r
55 \r
56         void init(string data)\r
57         {\r
58                 buf = data;\r
59                 pos = 0;\r
60         }\r
61 \r
62         void    clr()                   { buf = ""; }\r
63         void    add(string data)        { buf += data; }\r
64         void    set(string data)        { buf = data; }\r
65         string& str()                   { return buf; }\r
66         size_t  ofs()                   { return pos; }\r
67         void    ofs(size_t val)         { pos = val; }\r
68 \r
69         unsigned char   get(bool raw = false);\r
70         unsigned char   peek(size_t ofs = 0) { return buf[pos+ofs]; }\r
71         void            put(unsigned char byte, bool raw = false);\r
72 \r
73         void write1(void* data);\r
74         void write2(void* data);\r
75         void write4(void* data);\r
76         void write8(void* data);\r
77         void writef(float data);\r
78         void writed(double data);\r
79         void writes(string data);\r
80 \r
81         void*   read1();\r
82         void*   read2();\r
83         void*   read4();\r
84         void*   read8();\r
85         float   readf();\r
86         double  readd();\r
87         string  reads(size_t length);\r
88 \r
89         string& buffer() { return buf; }\r
90 };\r
91 \r
92 #endif\r