Collage  1.0.1
Object-Oriented C++ Network Library
objectVersion.h
1 
2 /* Copyright (c) 2009-2013, Stefan Eilemann <eile@equalizergraphics.com>
3  *
4  * This file is part of Collage <https://github.com/Eyescale/Collage>
5  *
6  * This library is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License version 2.1 as published
8  * by the Free Software Foundation.
9  *
10  * This library is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef CO_OBJECTVERSION_H
21 #define CO_OBJECTVERSION_H
22 
23 #include <co/api.h>
24 #include <co/types.h>
25 #include <lunchbox/stdExt.h>
26 #include <iostream>
27 
28 namespace co
29 {
31  static const uint128_t VERSION_NONE( 0, 0 );
32  static const uint128_t VERSION_FIRST( 0, 1 );
33  static const uint128_t VERSION_OLDEST( 0, 0xfffffffffffffffcull );
34  static const uint128_t VERSION_NEXT( 0, 0xfffffffffffffffdull );
35  static const uint128_t VERSION_INVALID( 0, 0xfffffffffffffffeull );
36  static const uint128_t VERSION_HEAD( 0, 0xffffffffffffffffull );
37 
46  {
48  CO_API ObjectVersion();
49 
51  CO_API ObjectVersion( const UUID& identifier, const uint128_t& version);
52 
54  CO_API ObjectVersion( const Object* object );
55 
57  template< class R > ObjectVersion( lunchbox::RefPtr< R > object )
58  { *this = object.get(); }
59 
61  CO_API ObjectVersion& operator = ( const Object* object );
62 
64  bool operator == ( const ObjectVersion& value ) const
65  {
66  return ( identifier == value.identifier &&
67  version == value.version );
68  }
69 
71  bool operator != ( const ObjectVersion& value ) const
72  {
73  return ( identifier != value.identifier ||
74  version != value.version );
75  }
76 
77  bool operator < ( const ObjectVersion& rhs ) const
78  {
79  return identifier < rhs.identifier ||
80  ( identifier == rhs.identifier && version < rhs.version );
81  }
82 
83  bool operator > ( const ObjectVersion& rhs ) const
84  {
85  return identifier > rhs.identifier ||
86  ( identifier == rhs.identifier && version > rhs.version );
87  }
88 
89  uint128_t identifier;
90  uint128_t version;
91  };
92 
93  inline std::ostream& operator << (std::ostream& os, const ObjectVersion& ov)
94  { return os << "id " << ov.identifier << " v" << ov.version; }
95 }
96 
97 namespace lunchbox
98 {
99 template<> inline void byteswap( co::ObjectVersion& value )
100 {
101  lunchbox::byteswap( value.identifier );
102  lunchbox::byteswap( value.version );
103 }
104 }
105 
106 LB_STDEXT_NAMESPACE_OPEN
107 #ifdef LB_STDEXT_MSVC
108 
109  template<>
110  inline size_t hash_compare< co::ObjectVersion >::operator()
111  ( const co::ObjectVersion& key ) const
112  {
113  const size_t hashVersion = hash_value( key.version );
114  const size_t hashID = hash_value( key.identifier );
115 
116  return hash_value( hashVersion ^ hashID );
117  }
118 #else
119 
120  template<> struct hash< co::ObjectVersion >
121  {
122  template< typename P > size_t operator()( const P& key ) const
123  {
124  return hash< uint64_t >()( hash_value( key.version ) ^
125  hash_value( key.identifier ));
126  }
127  };
128 #endif
129 LB_STDEXT_NAMESPACE_CLOSE
130 
131 #endif // CO_OBJECT_H
bool operator>(const ObjectVersion &rhs) const
&lt;
Definition: objectVersion.h:83
CO_API ObjectVersion & operator=(const Object *object)
Assign a new identifier and version.
bool operator<(const ObjectVersion &rhs) const
&lt;
Definition: objectVersion.h:77
uint128_t version
the object version
Definition: objectVersion.h:90
A helper struct bundling an object identifier and version.
Definition: objectVersion.h:45
ObjectVersion(lunchbox::RefPtr< R > object)
Construct a new object version.
Definition: objectVersion.h:57
uint128_t identifier
the object identifier
Definition: objectVersion.h:89
A distributed object.
Definition: object.h:45
bool operator!=(const ObjectVersion &value) const
Definition: objectVersion.h:71
bool operator==(const ObjectVersion &value) const
Definition: objectVersion.h:64
CO_API ObjectVersion()
Construct a new, zero-initialized object version.