Collage  1.1.2
High-performance C++ library for developing object-oriented distributed applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
objectVersion.h
1 
2 /* Copyright (c) 2009-2014, 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/bitOperation.h>
26 #include <lunchbox/stdExt.h>
27 #include <iostream>
28 
29 namespace co
30 {
32 static const uint128_t VERSION_NONE( 0, 0 );
33 static const uint128_t VERSION_FIRST( 0, 1 );
34 static const uint128_t VERSION_NEWEST( 0, 0xfffffffffffffffbull );
35 static const uint128_t VERSION_OLDEST( 0, 0xfffffffffffffffcull );
36 static const uint128_t VERSION_NEXT( 0, 0xfffffffffffffffdull );
37 static const uint128_t VERSION_INVALID( 0, 0xfffffffffffffffeull );
38 static const uint128_t VERSION_HEAD( 0, 0xffffffffffffffffull );
39 
48 {
50  CO_API ObjectVersion();
51 
53  CO_API ObjectVersion( const uint128_t& identifier, const uint128_t& version );
54 
56  CO_API ObjectVersion( const Object* object );
57 
59  template< class R > ObjectVersion( lunchbox::RefPtr< R > object )
60  { *this = object.get(); }
61 
63  CO_API ObjectVersion& operator = ( const Object* object );
64 
66  bool operator == ( const ObjectVersion& value ) const
67  {
68  return ( identifier == value.identifier &&
69  version == value.version );
70  }
71 
73  bool operator != ( const ObjectVersion& value ) const
74  {
75  return ( identifier != value.identifier ||
76  version != value.version );
77  }
78 
79  bool operator < ( const ObjectVersion& rhs ) const
80  {
81  return identifier < rhs.identifier ||
82  ( identifier == rhs.identifier && version < rhs.version );
83  }
84 
85  bool operator > ( const ObjectVersion& rhs ) const
86  {
87  return identifier > rhs.identifier ||
88  ( identifier == rhs.identifier && version > rhs.version );
89  }
90 
91  uint128_t identifier;
92  uint128_t version;
93 };
94 
95 inline std::ostream& operator << (std::ostream& os, const ObjectVersion& ov)
96 { return os << "id " << ov.identifier << " v" << ov.version; }
97 }
98 
99 namespace lunchbox
100 {
101 template<> inline void byteswap( co::ObjectVersion& value )
102 {
103  lunchbox::byteswap( value.identifier );
104  lunchbox::byteswap( value.version );
105 }
106 }
107 
108 LB_STDEXT_NAMESPACE_OPEN
109 #ifdef LB_STDEXT_MSVC
110 
111 template<>
112 inline size_t hash_compare< co::ObjectVersion >::operator()
113  ( const co::ObjectVersion& key ) const
114 {
115  const size_t hashVersion = hash_value( key.version );
116  const size_t hashID = hash_value( key.identifier );
117 
118  return hash_value( hashVersion ^ hashID );
119 }
120 #else
121 
122 template<> struct hash< co::ObjectVersion >
123 {
124  template< typename P > size_t operator()( const P& key ) const
125  {
126  return hash< uint64_t >()( hash_value( key.version ) ^
127  hash_value( key.identifier ));
128  }
129 };
130 #endif
131 LB_STDEXT_NAMESPACE_CLOSE
132 
133 #endif // CO_OBJECT_H
Defines export visibility macros for Collage.
A distributed object.
Definition: object.h:45
bool operator!=(const ObjectVersion &value) const
Definition: objectVersion.h:73
CO_API ObjectVersion()
Construct a new, zero-initialized object version.
A helper struct bundling an object identifier and version.
Definition: objectVersion.h:47
CO_API ObjectVersion & operator=(const Object *object)
Assign a new identifier and version.
uint128_t identifier
the object identifier
Definition: objectVersion.h:91
bool operator==(const ObjectVersion &value) const
Definition: objectVersion.h:66
ObjectVersion(lunchbox::RefPtr< R > object)
Construct a new object version.
Definition: objectVersion.h:59
uint128_t version
the object version
Definition: objectVersion.h:92
bool operator<(const ObjectVersion &rhs) const
<
Definition: objectVersion.h:79
bool operator>(const ObjectVersion &rhs) const
<
Definition: objectVersion.h:85