HoverRace  2.0
ClassicObjStream.h
Go to the documentation of this file.
1 
2 // ClassicObjStream.h
3 // Standard HoverRace 1.x parcel data stream.
4 //
5 // Copyright (c) 2010, 2012 Michael Imamura.
6 //
7 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
8 // you may not use this file except in compliance with the License.
9 //
10 // A copy of the license should have been attached to the package from which
11 // you have taken this file. If you can not find the license you can not use
12 // this file.
13 //
14 //
15 // The author makes no representations about the suitability of
16 // this software for any purpose. It is provided "as is" "AS IS",
17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
18 // implied.
19 //
20 // See the License for the specific language governing permissions
21 // and limitations under the License.
22 
23 #pragma once
24 
25 #include "ObjStream.h"
26 
27 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
28 # ifdef MR_ENGINE
29 # define MR_DllDeclare __declspec( dllexport )
30 # else
31 # define MR_DllDeclare __declspec( dllimport )
32 # endif
33 #else
34 # define MR_DllDeclare
35 #endif
36 
37 namespace HoverRace {
38 namespace Parcel {
39 
46 {
47  typedef ObjStream SUPER;
48  public:
49  public:
50  ClassicObjStream(FILE *stream, const Util::OS::path_t &name, bool writing);
51  virtual ~ClassicObjStream() { }
52 
53  private:
54  void WriteBuf(const void *buf, size_t ct)
55  {
56  size_t ret = fwrite(buf, ct, 1, stream);
57  if (ret == 0) throw ObjStreamExn(GetName(), _("Write failed"));
58  }
59 
60  public:
61  virtual void Write(const void *buf, size_t ct) { WriteBuf(buf, ct); }
62 
63  virtual void WriteUInt8(MR_UInt8 i);
64  virtual void WriteInt16(MR_Int16 i);
65  virtual void WriteUInt16(MR_UInt16 i);
66  virtual void WriteInt32(MR_Int32 i);
67  virtual void WriteUInt32(MR_UInt32 i);
68  virtual void WriteString(const std::string &s);
69 # if defined(_WIN32) && !defined(WITH_OBJSTREAM)
70  virtual void WriteCString(const CString &s) { WriteString((const char *)s); }
71 # endif
72 
73  private:
74  void WriteStringLength(MR_UInt32 len);
75 
76  void ReadBuf(void *buf, size_t ct)
77  {
78  size_t ret = fread(buf, ct, 1, stream);
79  if (ret == 0) throw ObjStreamExn(GetName(), _("Read failed"));
80  }
81 
82  public:
83  virtual void Read(void *buf, size_t ct) { ReadBuf(buf, ct); }
84 
85  virtual void ReadUInt8(MR_UInt8 &i);
86  virtual void ReadInt16(MR_Int16 &i);
87  virtual void ReadUInt16(MR_UInt16 &i);
88  virtual void ReadInt32(MR_Int32 &i);
89  virtual void ReadUInt32(MR_UInt32 &i);
90  virtual void ReadString(std::string &s);
91 # if defined(_WIN32) && !defined(WITH_OBJSTREAM)
92  virtual void ReadCString(CString &s) { std::string ss; ReadString(ss); s = ss.c_str(); }
93 # endif
94 
95  private:
96  MR_UInt32 ReadStringLength();
97 
98  private:
100 };
101 
102 } // namespace Parcel
103 } // namespace HoverRace
104 
105 #undef MR_DllDeclare
virtual void Write(const void *buf, size_t ct)
Definition: ClassicObjStream.h:61
boost::filesystem::path path_t
Definition: OS.h:57
uint16_t MR_UInt16
Definition: MR_Types.h:42
virtual void Read(void *buf, size_t ct)
Definition: ClassicObjStream.h:83
virtual ~ClassicObjStream()
Definition: ClassicObjStream.h:51
Standard HoverRace 1.x parcel data stream.
Definition: ClassicObjStream.h:45
#define MR_DllDeclare
Definition: ClassicObjStream.h:34
void WriteBuf(const void *buf, size_t ct)
Definition: ClassicObjStream.h:54
ObjStream SUPER
Definition: ClassicObjStream.h:47
FILE * stream
Definition: ClassicObjStream.h:99
void ReadBuf(void *buf, size_t ct)
Definition: ClassicObjStream.h:76
Definition: ObjStream.h:43
Base class for parcel serializers.
Definition: ObjStream.h:58
int16_t MR_Int16
Definition: MR_Types.h:41
int32_t MR_Int32
Definition: MR_Types.h:43
Definition: Announcement.h:24
uint32_t MR_UInt32
Definition: MR_Types.h:44
uint8_t MR_UInt8
Definition: MR_Types.h:40
Definition: Symbol.h:253