zenilib  0.5.3.0
 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 {
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) {
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>
VLUID & operator++()
Definition: VLUID.cpp:45
int32_t Sint32
A signed 32-bit integer type.
Definition: SDL_stdinc.h:141
virtual std::istream & unserialize(std::istream &is)
Definition: VLUID.cpp:73
virtual std::istream & unserialize(std::istream &is)=0
int compare(const VLUID &rhs) const
Definition: VLUID.cpp:25
const GLfloat * c
Definition: glew.h:14913
GLuint index
Definition: glew.h:1800
Variable Length Unique IDentifier.
Definition: VLUID.h:47
virtual std::ostream & serialize(std::ostream &os) const
Definition: VLUID.cpp:67
virtual std::ostream & serialize(std::ostream &os) const =0
uint16_t Uint16
An unsigned 16-bit integer type.
Definition: SDL_stdinc.h:137
unsigned int size_t