Collage  0.6.1
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, const uint128_t& version);
00049         CO_API ObjectVersion( const Object* object );
00050         template< class R > ObjectVersion( lunchbox::RefPtr< R > object )
00051             { *this = object.get(); }
00052 
00053         CO_API ObjectVersion& operator = ( const Object* object );
00054      
00055         bool operator == ( const ObjectVersion& value ) const
00056             {
00057                 return ( identifier == value.identifier &&
00058                          version == value.version );
00059             }
00060         
00061         bool operator != ( const ObjectVersion& value ) const
00062             {
00063                 return ( identifier != value.identifier ||
00064                          version != value.version );
00065             }
00066         
00067         bool operator < ( const ObjectVersion& rhs ) const
00068             { 
00069                 return identifier < rhs.identifier ||
00070                     ( identifier == rhs.identifier && version < rhs.version );
00071             }
00072 
00073         bool operator > ( const ObjectVersion& rhs ) const
00074             {
00075                 return identifier > rhs.identifier || 
00076                     ( identifier == rhs.identifier && version > rhs.version );
00077             }
00078 
00079         uint128_t identifier;
00080         uint128_t version;
00081 
00083         static CO_API ObjectVersion NONE;
00084     };
00085 
00086     inline std::ostream& operator << (std::ostream& os, const ObjectVersion& ov)
00087         { return os << "id " << ov.identifier << " v" << ov.version; }
00088 
00089 }
00090 
00091 LB_STDEXT_NAMESPACE_OPEN
00092 #ifdef LB_STDEXT_MSVC
00093 
00094     template<>
00095     inline size_t hash_compare< co::ObjectVersion >::operator()
00096         ( const co::ObjectVersion& key ) const
00097     {
00098         const size_t hashVersion = hash_value( key.version );
00099         const size_t hashID = hash_value( key.identifier );
00100 
00101         return hash_value( hashVersion ^ hashID );
00102     }
00103 #else
00104 
00105     template<> struct hash< co::ObjectVersion >
00106     {
00107         template< typename P > size_t operator()( const P& key ) const
00108         {
00109             return hash< uint64_t >()( hash_value( key.version ) ^ 
00110                                        hash_value( key.identifier ));
00111         }
00112     };
00113 #endif
00114 LB_STDEXT_NAMESPACE_CLOSE
00115 
00116 #endif // CO_OBJECT_H
Generated on Mon Nov 26 2012 14:41:44 for Collage 0.6.1 by  doxygen 1.7.6.1