zenilib: zenilib/jni/external/zenilib/zeni_net/Zeni/VLUID.h Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
VLUID.h
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2 * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3 *
4 * zenilib is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * zenilib is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16 */
17
33 #ifndef ZENI_VLUID_H
34 #define ZENI_VLUID_H
35
36 #include <Zeni/Error.h>
37 #include <Zeni/Serialization.h>
38
39 namespace Zeni {
40
41 /*** VLUID class ***/
42
43 struct ZENI_NET_DLL VLUID_Too_Large : public Zeni::Error {
44 VLUID_Too_Large() : Error("VLUID too large!") {}
45 };
46
47 class ZENI_NET_DLL VLUID : public Serializable {
48 public:
49 int compare(const VLUID &rhs) const;
50 bool operator==(const VLUID &rhs) const {return !compare(rhs);}
51 bool operator!=(const VLUID &rhs) const {return compare(rhs) != 0;}
52 bool operator<(const VLUID &rhs) const {return compare(rhs) < 0;}
53 bool operator<=(const VLUID &rhs) const {return compare(rhs) < 1;}
54 bool operator>(const VLUID &rhs) const {return compare(rhs) > 0;}
55 bool operator>=(const VLUID &rhs) const {return compare(rhs) > -1;}
56
57 VLUID & operator++(); // prefix
58 VLUID operator++(int); // postfix
59
60 Uint16 size() const {return sizeof(Serializable::m_size) + m_size;}
61
62 const unsigned char & operator[](const size_t &index) const {return reinterpret_cast<const unsigned char &>(m_uid[index]);}
63
64 virtual std::ostream & serialize(std::ostream &os) const;
65 virtual std::istream & unserialize(std::istream &is);
66
67 private:
68 #ifdef _WINDOWS
69 #pragma warning( push )
70 #pragma warning( disable : 4251 )
71 #endif
72 std::basic_string<unsigned char> m_uid;
73 #ifdef _WINDOWS
74 #pragma warning( pop )
75 #endif
76 };
77
78 typedef VLUID Nonce;
79
80 /*** VLUID Based Datatypes ***/
81
82 //template <typename TYPE>
83 //class Net_Datum {
84 //public:
85 // Net_Datum(const TYPE &rhs = TYPE()) : m_datum(rhs) {}
86 // Net_Datum(const VLUID &sauid, const TYPE &rhs = TYPE()) : m_sauid(sauid), m_datum(rhs) {}
87
88 // /** This recv function assumes that
89 // * -the size has already been read in
90 // * -sauid has already been read in
91 // * -sauid has been verified to correspond to this Net_Datum
92 // **/
93 // virtual std::istream & recv(std::istream &is) = 0;
94 //
95 // virtual std::ostream & send(std::ostream &os) const = 0;
96 //
97 // operator const TYPE & () const {return this->m_datum;}
98 // operator TYPE & () {return this->m_datum;}
99 //
100 //protected:
101 // VLUID m_sauid; // server assigned unique identifier
102 //
103 // VLUID m_nonce; // so old packets don't supercede newer ones
104 //
105 // TYPE m_datum;
106 //};
107
108 //template <typename TYPE>
109 //class Local_Datum : public Net_Datum<TYPE> {
110 //public:
111 // Local_Datum(const TYPE &rhs = TYPE()) : Net_Datum<TYPE>(rhs) {}
112 // Local_Datum(const VLUID &sauid, const TYPE &rhs = TYPE()) : Net_Datum<TYPE>(sauid, rhs) {}
113
114 // virtual std::istream & recv(std::istream &is) {return is;}
115 //
116 // virtual std::ostream & send(std::ostream &os) const {
117 // std::ostringstream oss;
118 // oss << this->m_sauid << this->m_nonce << this->m_datum;
119 // const String &str = oss.str();
120 // Uint16 size = str.size();
121 // return serialize(os, size) << str;
122 // }
123 //};
124
125 //template <typename TYPE>
126 //class Remote_Datum : public Net_Datum<TYPE> {
127 //public:
128 // Remote_Datum(const TYPE &rhs = TYPE()) : Net_Datum<TYPE>(rhs) {}
129 // Remote_Datum(const VLUID &sauid, const TYPE &rhs = TYPE()) : Net_Datum<TYPE>(sauid, rhs) {}
130
131 // /** This recv function assumes that
132 // * -the size has already been read in
133 // * -sauid has already been read in
134 // * -sauid has been verified to correspond to this Net_Datum
135 // **/
136 // virtual std::istream & recv(std::istream &is) {
137 // VLUID nonce(is);
138 //
139 // if(this->m_nonce > nonce) {
140 // TYPE datum;
141 // is >> datum;
142 // }
143 // else
144 // is >> this->m_datum;
145 //
146 // return is;
147 // }
148 //
149 // virtual std::ostream & send(std::ostream &os) const {return os;}
150 //};
151
152 }
153
154 #endif
Zeni::VLUID::operator!=
bool operator!=(const VLUID &rhs) const
Definition: VLUID.h:51
Zeni::Serializable::m_size
Uint16 m_size
Definition: Serialization.h:94
Zeni::VLUID_Too_Large
Definition: VLUID.h:43
Zeni::VLUID_Too_Large::VLUID_Too_Large
VLUID_Too_Large()
Definition: VLUID.h:44
Zeni::unserialize
std::istream & unserialize(std::istream &is, Color &value)
Definition: Color.cpp:72
Zeni::serialize
std::ostream & serialize(std::ostream &os, const Color &value)
Definition: Color.cpp:68
Zeni::Nonce
VLUID Nonce
Definition: VLUID.h:78
Zeni::VLUID::operator<=
bool operator<=(const VLUID &rhs) const
Definition: VLUID.h:53
Error.h
Serialization.h
index
GLuint index
Definition: glew.h:1800
Zeni::VLUID::operator>=
bool operator>=(const VLUID &rhs) const
Definition: VLUID.h:55
Zeni::VLUID
Variable Length Unique IDentifier.
Definition: VLUID.h:47
Zeni::Serializable
A base class for objects that can be sent over the network.
Definition: Serialization.h:83
Zeni::VLUID::operator<
bool operator<(const VLUID &rhs) const
Definition: VLUID.h:52
Uint16
uint16_t Uint16
An unsigned 16-bit integer type.
Definition: SDL_stdinc.h:137
Zeni::VLUID::size
Uint16 size() const
Definition: VLUID.h:60
Zeni::Error
The Error Class.
Definition: Error.h:52
Zeni::VLUID::operator[]
const unsigned char & operator[](const size_t &index) const
Definition: VLUID.h:62
Zeni::VLUID::operator>
bool operator>(const VLUID &rhs) const
Definition: VLUID.h:54
Zeni::VLUID::operator==
bool operator==(const VLUID &rhs) const
Definition: VLUID.h:50