Equalizer 1.0

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 
00038     struct ObjectVersion
00039     {
00040         CO_API ObjectVersion();
00041         CO_API ObjectVersion( const base::UUID& identifier,
00042                                  const uint128_t& version );
00043         CO_API ObjectVersion( const Object* object );
00044         CO_API ObjectVersion& operator = ( const Object* object );
00045      
00046         bool operator == ( const ObjectVersion& value ) const
00047             {
00048                 return ( identifier == value.identifier &&
00049                          version == value.version );
00050             }
00051         
00052         bool operator != ( const ObjectVersion& value ) const
00053             {
00054                 return ( identifier != value.identifier ||
00055                          version != value.version );
00056             }
00057         
00058         bool operator < ( const ObjectVersion& rhs ) const
00059             { 
00060                 return identifier < rhs.identifier ||
00061                     ( identifier == rhs.identifier && version < rhs.version );
00062             }
00063 
00064         bool operator > ( const ObjectVersion& rhs ) const
00065             {
00066                 return identifier > rhs.identifier || 
00067                     ( identifier == rhs.identifier && version > rhs.version );
00068             }
00069 
00070         uint128_t identifier;
00071         uint128_t version;
00072 
00074         static ObjectVersion NONE;
00075     };
00076 
00077     inline std::ostream& operator << (std::ostream& os, const ObjectVersion& ov)
00078     {
00079         os << "id " << ov.identifier << " v" << ov.version;
00080         return os;
00081     }
00082 
00083 }
00084 
00085 CO_STDEXT_NAMESPACE_OPEN
00086 #ifdef CO_STDEXT_MSVC
00087 
00088     template<>
00089     inline size_t hash_compare< co::ObjectVersion >::operator()
00090         ( const co::ObjectVersion& key ) const
00091     {
00092         const size_t hashVersion = hash_value( key.version );
00093         const size_t hashID = hash_value( key.identifier );
00094 
00095         return hash_value( hashVersion ^ hashID );
00096     }
00097 #else
00098 
00099     template<> struct hash< co::ObjectVersion >
00100     {
00101         template< typename P > size_t operator()( const P& key ) const
00102         {
00103             return hash< uint64_t >()( hash_value( key.version ) ^ 
00104                                        hash_value( key.identifier ));
00105         }
00106     };
00107 #endif
00108 CO_STDEXT_NAMESPACE_CLOSE
00109 
00110 #endif // CO_OBJECT_H
Generated on Sun May 8 2011 19:11:07 for Equalizer 1.0 by  doxygen 1.7.3