Equalizer  1.2.1
serializable.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_SERIALIZABLE_H
00019 #define CO_SERIALIZABLE_H
00020 
00021 #include <co/object.h>        // base class
00022 #include <co/dataOStream.h>   // used inline
00023 #include <co/dataIStream.h>   // used inline
00024 
00025 namespace co
00026 {
00035     class Serializable : public Object
00036     {
00037     public:
00039         uint64_t getDirty() const { return _dirty; }
00040 
00042         virtual bool isDirty() const { return ( _dirty != DIRTY_NONE ); }
00043 
00045         virtual bool isDirty( const uint64_t dirtyBits ) const
00046             { return (_dirty & dirtyBits) == dirtyBits; }
00047 
00048         virtual uint128_t commit( const uint32_t incarnation = CO_COMMIT_NEXT )
00049             {
00050                 const uint128_t& version = co::Object::commit( incarnation );
00051                 _dirty = DIRTY_NONE;
00052                 return version;
00053             }
00054 
00055     protected:
00057         Serializable() : _dirty( DIRTY_NONE ) {}
00058         
00063         Serializable( const Serializable& )
00064                 : co::Object(), _dirty ( DIRTY_NONE ) {}
00065         
00067         virtual ~Serializable() {}
00068 
00081         virtual void serialize( co::DataOStream&, const uint64_t ){};
00082 
00093         virtual void deserialize( co::DataIStream&, const uint64_t ){};
00094 
00095         virtual ChangeType getChangeType() const { return DELTA; }
00096 
00103         enum DirtyBits
00104         {
00105             DIRTY_NONE       = 0,
00106             DIRTY_CUSTOM     = 1,
00107             DIRTY_ALL        = 0xFFFFFFFFFFFFFFFFull
00108         };
00109 
00111         virtual void setDirty( const uint64_t bits ) { _dirty |= bits; }
00112 
00114         virtual void unsetDirty( const uint64_t bits ) { _dirty &= ~bits; }
00115 
00116         virtual void notifyAttached()
00117             {
00118                 if( isMaster( ))
00119                     _dirty = DIRTY_NONE;
00120             }
00121 
00122     private:
00123         virtual void getInstanceData( co::DataOStream& os )
00124             {
00125                 serialize( os, DIRTY_ALL );
00126             }
00127 
00128         virtual void applyInstanceData( co::DataIStream& is )
00129             {
00130                 if( !is.hasData( ))
00131                     return;
00132                 deserialize( is, DIRTY_ALL );
00133             }
00134 
00135         virtual void pack( co::DataOStream& os )
00136             {
00137                 if( _dirty == DIRTY_NONE )
00138                     return;
00139 
00140                 os << _dirty;
00141                 serialize( os, _dirty );
00142             }
00143 
00144         virtual void unpack( co::DataIStream& is )
00145             {
00146                 EQASSERT( is.hasData( ));
00147                 if( !is.hasData( ))
00148                     return;
00149 
00150                 uint64_t dirty;
00151                 is >> dirty;
00152                 deserialize( is, dirty );
00153             }
00154 
00156         uint64_t _dirty;
00157 
00158         struct Private;
00159         Private* _private; // placeholder for binary-compatible changes
00160     };
00161 }
00162 #endif // CO_SERIALIZABLE_H
Generated on Fri Jun 8 2012 15:44:32 for Equalizer 1.2.1 by  doxygen 1.8.0