Equalizer  1.2.1
objectVersion.h
00001 
00002 /* Copyright (c) 2009-2011, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #ifndef CO_OBJECTVERSION_H
00019 #define CO_OBJECTVERSION_H
00020 
00021 #include <co/api.h>
00022 #include <co/types.h>
00023 #include <co/base/stdExt.h>
00024 
00025 #include <iostream>
00026 
00027 namespace co
00028 {
00029     class Object;
00030 
00032     extern CO_API const uint128_t VERSION_NONE;
00033     extern CO_API const uint128_t VERSION_FIRST;
00034     extern CO_API const uint128_t VERSION_NEXT;
00035     extern CO_API const uint128_t VERSION_INVALID;
00036     extern CO_API const uint128_t VERSION_OLDEST;
00037     extern CO_API const uint128_t VERSION_HEAD;
00038 
00046     struct ObjectVersion
00047     {
00048         CO_API ObjectVersion();
00049         CO_API ObjectVersion( const base::UUID& identifier,
00050                                  const uint128_t& version );
00051         CO_API ObjectVersion( const Object* object );
00052         CO_API ObjectVersion& operator = ( const Object* object );
00053      
00054         bool operator == ( const ObjectVersion& value ) const
00055             {
00056                 return ( identifier == value.identifier &&
00057                          version == value.version );
00058             }
00059         
00060         bool operator != ( const ObjectVersion& value ) const
00061             {
00062                 return ( identifier != value.identifier ||
00063                          version != value.version );
00064             }
00065         
00066         bool operator < ( const ObjectVersion& rhs ) const
00067             { 
00068                 return identifier < rhs.identifier ||
00069                     ( identifier == rhs.identifier && version < rhs.version );
00070             }
00071 
00072         bool operator > ( const ObjectVersion& rhs ) const
00073             {
00074                 return identifier > rhs.identifier || 
00075                     ( identifier == rhs.identifier && version > rhs.version );
00076             }
00077 
00078         uint128_t identifier;
00079         uint128_t version;
00080 
00082         static CO_API ObjectVersion NONE;
00083     };
00084 
00085     inline std::ostream& operator << (std::ostream& os, const ObjectVersion& ov)
00086     {
00087         os << "id " << ov.identifier << " v" << ov.version;
00088         return os;
00089     }
00090 
00091 }
00092 
00093 CO_STDEXT_NAMESPACE_OPEN
00094 #ifdef CO_STDEXT_MSVC
00095 
00096     template<>
00097     inline size_t hash_compare< co::ObjectVersion >::operator()
00098         ( const co::ObjectVersion& key ) const
00099     {
00100         const size_t hashVersion = hash_value( key.version );
00101         const size_t hashID = hash_value( key.identifier );
00102 
00103         return hash_value( hashVersion ^ hashID );
00104     }
00105 #else
00106 
00107     template<> struct hash< co::ObjectVersion >
00108     {
00109         template< typename P > size_t operator()( const P& key ) const
00110         {
00111             return hash< uint64_t >()( hash_value( key.version ) ^ 
00112                                        hash_value( key.identifier ));
00113         }
00114     };
00115 #endif
00116 CO_STDEXT_NAMESPACE_CLOSE
00117 
00118 #endif // CO_OBJECT_H
Generated on Fri Jun 8 2012 15:44:32 for Equalizer 1.2.1 by  doxygen 1.8.0