osgEarth 2.1.1
|
00001 /* -*-c++-*- */ 00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph 00003 * Copyright 2008-2010 Pelican Mapping 00004 * http://osgearth.org 00005 * 00006 * osgEarth is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/> 00018 */ 00019 00020 #ifndef OSGEARTH_REVISIONING_H 00021 #define OSGEARTH_REVISIONING_H 1 00022 00023 #include <osgEarth/Common> 00024 00025 namespace osgEarth 00026 { 00030 struct Revision // header-only; no export 00031 { 00032 Revision() : _value(-1) { } 00033 Revision(int init) : _value(init) { } 00034 void reset() { _value = -1; } 00035 operator int() const { return _value; } 00036 int operator ++() { return ++_value; } 00037 int operator --() { return --_value; } 00038 private: 00039 int _value; 00040 }; 00041 00048 template<typename T> class Revisioned : public T // header-only; no export 00049 { 00050 public: 00052 void dirty() { 00053 ++_revision; 00054 } 00055 00058 virtual void sync( Revision& externalRevision ) const { 00059 externalRevision = _revision; 00060 } 00061 00063 bool outOfSyncWith( const Revision& externalRevision) const { 00064 return !inSyncWith( externalRevision ); 00065 } 00066 00068 virtual bool inSyncWith( const Revision& externalRevision ) const { 00069 return _alwaysDirty ? false : _revision == externalRevision; 00070 } 00071 00072 protected: 00073 Revisioned() : _revision(0), _alwaysDirty(false) { } 00074 00076 void setAlwaysDirty( bool value ) { 00077 _alwaysDirty = value; 00078 } 00079 00080 private: 00081 Revision _revision; 00082 bool _alwaysDirty; 00083 }; 00084 } 00085 00086 #endif // OSGEARTH_REVISIONING_H