zenilib: zenilib/jni/external/zenilib/zeni_net/VLUID.cpp 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.cpp
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
18 #include <zeni_net.h>
19
20 #include <iostream>
21
22 namespace Zeni {
23 /*** VLUID Class ***/
24
25 int VLUID::compare(const VLUID &rhs) const {
26 if(m_size > rhs.m_size)
27 return 1;
28 else if(rhs.m_size > m_size)
29 return -1;
30
31 Sint32 index = m_size - 1;
32 for(; index > -1; --index) {
33 const unsigned char &c = m_uid[size_t(index)];
34 const unsigned char &rhs_c = rhs.m_uid[size_t(index)];
35
36 if(c > rhs_c)
37 return 1;
38 else if(rhs_c > c)
39 return -1;
40 }
41
42 return 0;
43 }
44
45 VLUID & VLUID::operator++() { //prefix
46 Uint16 index = 0;
47 for(; index < m_size; ++index)
48 if(++m_uid[index])
49 break;
50
51 if(index == m_size) {
52 if(++m_size)
53 m_uid += static_cast<unsigned char>(0);
54 else
55 m_uid.clear();
56 }
57
58 return *this;
59 }
60
61 VLUID VLUID::operator++(int) { //postfix
62 VLUID prev = *this;
63 ++*this;
64 return prev;
65 }
66
67 std::ostream & VLUID::serialize(std::ostream &os) const {
68 Serializable::serialize(os);
69
70 return os.write(reinterpret_cast<const char *>(m_uid.c_str()), m_size);
71 }
72
73 std::istream & VLUID::unserialize(std::istream &is) {
74 Serializable::unserialize(is);
75
76 if(is) {
77 m_uid.resize(m_size);
78
79 if(!is.read(const_cast<char *>(reinterpret_cast<const char *>(m_uid.c_str())), m_size))
80 m_uid.clear();
81 }
82 else
83 m_uid.clear();
84
85 return is;
86 }
87
88 }
89
90 #include <Zeni/Undefine.h>
zeni_net.h
Zeni::VLUID::operator++
VLUID & operator++()
Definition: VLUID.cpp:45
Zeni::Serializable::m_size
Uint16 m_size
Definition: Serialization.h:94
Sint32
int32_t Sint32
A signed 32-bit integer type.
Definition: SDL_stdinc.h:141
Zeni::VLUID::unserialize
virtual std::istream & unserialize(std::istream &is)
Definition: VLUID.cpp:73
Undefine.h
Zeni::Serializable::unserialize
virtual std::istream & unserialize(std::istream &is)=0
Definition: Serialization.cpp:234
Zeni::VLUID::compare
int compare(const VLUID &rhs) const
Definition: VLUID.cpp:25
c
const GLfloat * c
Definition: glew.h:14913
index
GLuint index
Definition: glew.h:1800
Zeni::VLUID
Variable Length Unique IDentifier.
Definition: VLUID.h:47
Zeni::VLUID::serialize
virtual std::ostream & serialize(std::ostream &os) const
Definition: VLUID.cpp:67
Zeni::Serializable::serialize
virtual std::ostream & serialize(std::ostream &os) const =0
Definition: Serialization.cpp:230
Uint16
uint16_t Uint16
An unsigned 16-bit integer type.
Definition: SDL_stdinc.h:137
size_t
unsigned int size_t
Definition: SDL_config_windows.h:67