HoverRace  2.0
ObjStream.h
Go to the documentation of this file.
1 
2 // ObjStream.h
3 //
4 // Copyright (c) 2010, 2015 Michael Imamura.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 
22 #pragma once
23 
24 #include <string>
25 
26 #include "../Exception.h"
27 #include "../Util/MR_Types.h"
28 #include "../Util/OS.h"
29 
30 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
31 # ifdef MR_ENGINE
32 # define MR_DllDeclare __declspec( dllexport )
33 # else
34 # define MR_DllDeclare __declspec( dllimport )
35 # endif
36 #else
37 # define MR_DllDeclare
38 #endif
39 
40 namespace HoverRace {
41 namespace Parcel {
42 
44 {
45  using SUPER = Exception;
46 
47 public:
48  ObjStreamExn() : SUPER() { }
49  ObjStreamExn(const std::string &msg) : SUPER(msg) { }
50  ObjStreamExn(const Util::OS::path_t &path, const std::string &details);
51  virtual ~ObjStreamExn() noexcept { }
52 };
53 
59 {
60 private:
61  ObjStream() { }
62 public:
63  ObjStream(const Util::OS::path_t &name, int version, bool writing) :
64  name(name), version(version), writing(writing)
65  { }
66  virtual ~ObjStream() { }
67 
68 public:
69  const Util::OS::path_t &GetName() const { return name; }
70  int GetVersion() const { return version; }
71  bool IsWriting() const { return writing; }
72 
73 public:
74  virtual void Write(const void *buf, size_t ct) = 0;
75 
76  virtual void WriteUInt8(MR_UInt8 i) = 0;
77  friend ObjStream &operator<<(ObjStream &os, MR_UInt8 i) { os.WriteUInt8(i); return os; }
78 
79  virtual void WriteInt16(MR_Int16 i) = 0;
80  friend ObjStream &operator<<(ObjStream &os, MR_Int16 i) { os.WriteInt16(i); return os; }
81 
82  virtual void WriteUInt16(MR_UInt16 i) = 0;
83  friend ObjStream &operator<<(ObjStream &os, MR_UInt16 i) { os.WriteUInt16(i); return os; }
84 
85  virtual void WriteInt32(MR_Int32 i) = 0;
86  friend ObjStream &operator<<(ObjStream &os, MR_Int32 i) { os.WriteInt32(i); return os; }
87 
88  virtual void WriteUInt32(MR_UInt32 i) = 0;
89  friend ObjStream &operator<<(ObjStream &os, MR_UInt32 i) { os.WriteUInt32(i); return os; }
90 
91  virtual void WriteString(const std::string &s) = 0;
92  friend ObjStream &operator<<(ObjStream &os, const std::string &s) { os.WriteString(s); return os; }
93 
94 # if defined(_WIN32) && !defined(WITH_OBJSTREAM)
95  virtual void WriteCString(const CString &s) = 0;
96  friend ObjStream &operator<<(ObjStream &os, const CString &s) { os.WriteCString(s); return os; }
97 # endif
98 
99  virtual void Read(void *buf, size_t ct) = 0;
100 
101  virtual void ReadUInt8(MR_UInt8 &i) = 0;
102  friend ObjStream &operator>>(ObjStream &os, MR_UInt8 &i) { os.ReadUInt8(i); return os; }
103 
104  virtual void ReadInt16(MR_Int16 &i) = 0;
105  friend ObjStream &operator>>(ObjStream &os, MR_Int16 &i) { os.ReadInt16(i); return os; }
106 
107  virtual void ReadUInt16(MR_UInt16 &i) = 0;
108  friend ObjStream &operator>>(ObjStream &os, MR_UInt16 &i) { os.ReadUInt16(i); return os; }
109 
110  virtual void ReadInt32(MR_Int32 &i) = 0;
111  friend ObjStream &operator>>(ObjStream &os, MR_Int32 &i) { os.ReadInt32(i); return os; }
112 
113  virtual void ReadUInt32(MR_UInt32 &i) = 0;
114  friend ObjStream &operator>>(ObjStream &os, MR_UInt32 &i) { os.ReadUInt32(i); return os; }
115 
116  virtual void ReadString(std::string &s) = 0;
117  friend ObjStream &operator>>(ObjStream &os, std::string &s) { os.ReadString(s); return os; }
118 
119 # if defined(_WIN32) && !defined(WITH_OBJSTREAM)
120  virtual void ReadCString(CString &s) = 0;
121  friend ObjStream &operator>>(ObjStream &os, CString &s) { os.ReadCString(s); return os; }
122 # endif
123 
124 private:
126  int version;
127  bool writing;
128 };
129 typedef std::shared_ptr<ObjStream> ObjStreamPtr;
130 
131 } // namespace Parcel
132 } // namespace HoverRace
133 
134 #undef MR_DllDeclare
friend ObjStream & operator<<(ObjStream &os, MR_UInt32 i)
Definition: ObjStream.h:89
boost::filesystem::path path_t
Definition: OS.h:57
int version
Definition: ObjStream.h:126
uint16_t MR_UInt16
Definition: MR_Types.h:42
Util::OS::path_t name
Definition: ObjStream.h:125
friend ObjStream & operator>>(ObjStream &os, MR_UInt16 &i)
Definition: ObjStream.h:108
#define MR_DllDeclare
Definition: ObjStream.h:37
virtual void WriteUInt32(MR_UInt32 i)=0
friend ObjStream & operator>>(ObjStream &os, std::string &s)
Definition: ObjStream.h:117
friend ObjStream & operator<<(ObjStream &os, const std::string &s)
Definition: ObjStream.h:92
ObjStreamExn()
Definition: ObjStream.h:48
ObjStream()
Definition: ObjStream.h:61
virtual void ReadString(std::string &s)=0
virtual ~ObjStreamExn() noexcept
Definition: ObjStream.h:51
bool IsWriting() const
Definition: ObjStream.h:71
std::exception SUPER
Definition: Exception.h:44
ObjStreamExn(const std::string &msg)
Definition: ObjStream.h:49
friend ObjStream & operator<<(ObjStream &os, MR_Int16 i)
Definition: ObjStream.h:80
std::shared_ptr< ObjStream > ObjStreamPtr
Definition: ObjStream.h:129
virtual void ReadUInt16(MR_UInt16 &i)=0
friend ObjStream & operator<<(ObjStream &os, MR_UInt16 i)
Definition: ObjStream.h:83
virtual void WriteInt16(MR_Int16 i)=0
friend ObjStream & operator>>(ObjStream &os, MR_Int32 &i)
Definition: ObjStream.h:111
ObjStream(const Util::OS::path_t &name, int version, bool writing)
Definition: ObjStream.h:63
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
friend ObjStream & operator>>(ObjStream &os, MR_Int16 &i)
Definition: ObjStream.h:105
bool writing
Definition: ObjStream.h:127
int GetVersion() const
Definition: ObjStream.h:70
virtual void ReadUInt8(MR_UInt8 &i)=0
virtual void ReadInt16(MR_Int16 &i)=0
virtual ~ObjStream()
Definition: ObjStream.h:66
virtual void WriteInt32(MR_Int32 i)=0
virtual void WriteUInt16(MR_UInt16 i)=0
std::ostream & operator<<(std::ostream &os, const Vec2 &v)
Definition: Vec.h:48
virtual void ReadUInt32(MR_UInt32 &i)=0
Definition: Announcement.h:24
virtual void ReadInt32(MR_Int32 &i)=0
friend ObjStream & operator<<(ObjStream &os, MR_Int32 i)
Definition: ObjStream.h:86
uint32_t MR_UInt32
Definition: MR_Types.h:44
friend ObjStream & operator>>(ObjStream &os, MR_UInt8 &i)
Definition: ObjStream.h:102
virtual void WriteString(const std::string &s)=0
Base exception, providing constructors for setting the message.
Definition: Exception.h:42
friend ObjStream & operator>>(ObjStream &os, MR_UInt32 &i)
Definition: ObjStream.h:114
const Util::OS::path_t & GetName() const
Definition: ObjStream.h:69
virtual void WriteUInt8(MR_UInt8 i)=0
uint8_t MR_UInt8
Definition: MR_Types.h:40
friend ObjStream & operator<<(ObjStream &os, MR_UInt8 i)
Definition: ObjStream.h:77
std::istream & operator>>(std::istream &in, RoomList::IpAddr &ip)
Definition: RoomList.cpp:176