Equalizer  1.3.1-git
objectVersion.h
00001 
00002 /* Copyright (c) 2009-2012, 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 <lunchbox/stdExt.h>
00024 #include <iostream>
00025 
00026 namespace co
00027 {
00028     class Object;
00029 
00031     extern CO_API const uint128_t VERSION_NONE;
00032     extern CO_API const uint128_t VERSION_FIRST;
00033     extern CO_API const uint128_t VERSION_NEXT;
00034     extern CO_API const uint128_t VERSION_INVALID;
00035     extern CO_API const uint128_t VERSION_OLDEST;
00036     extern CO_API const uint128_t VERSION_HEAD;
00037 
00045     struct ObjectVersion
00046     {
00047         CO_API ObjectVersion();
00048         CO_API ObjectVersion( const UUID& identifier,
00049                                  const uint128_t& version );
00050         CO_API ObjectVersion( const Object* object );
00051         CO_API ObjectVersion& operator = ( const Object* object );
00052      
00053         bool operator == ( const ObjectVersion& value ) const
00054             {
00055                 return ( identifier == value.identifier &&
00056                          version == value.version );
00057             }
00058         
00059         bool operator != ( const ObjectVersion& value ) const
00060             {
00061                 return ( identifier != value.identifier ||
00062                          version != value.version );
00063             }
00064         
00065         bool operator < ( const ObjectVersion& rhs ) const
00066             { 
00067                 return identifier < rhs.identifier ||
00068                     ( identifier == rhs.identifier && version < rhs.version );
00069             }
00070 
00071         bool operator > ( const ObjectVersion& rhs ) const
00072             {
00073                 return identifier > rhs.identifier || 
00074                     ( identifier == rhs.identifier && version > rhs.version );
00075             }
00076 
00077         uint128_t identifier;
00078         uint128_t version;
00079 
00081         static CO_API ObjectVersion NONE;
00082     };
00083 
00084     inline std::ostream& operator << (std::ostream& os, const ObjectVersion& ov)
00085     {
00086         os << "id " << ov.identifier << " v" << ov.version;
00087         return os;
00088     }
00089 
00090 }
00091 
00092 LB_STDEXT_NAMESPACE_OPEN
00093 #ifdef LB_STDEXT_MSVC
00094 
00095     template<>
00096     inline size_t hash_compare< co::ObjectVersion >::operator()
00097         ( const co::ObjectVersion& key ) const
00098     {
00099         const size_t hashVersion = hash_value( key.version );
00100         const size_t hashID = hash_value( key.identifier );
00101 
00102         return hash_value( hashVersion ^ hashID );
00103     }
00104 #else
00105 
00106     template<> struct hash< co::ObjectVersion >
00107     {
00108         template< typename P > size_t operator()( const P& key ) const
00109         {
00110             return hash< uint64_t >()( hash_value( key.version ) ^ 
00111                                        hash_value( key.identifier ));
00112         }
00113     };
00114 #endif
00115 LB_STDEXT_NAMESPACE_CLOSE
00116 
00117 #endif // CO_OBJECT_H
Generated on Tue May 1 2012 15:14:27 for Equalizer 1.3.1-git by  doxygen 1.8.0