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_COMMON_H 00021 #define OSGEARTH_COMMON_H 1 00022 00023 #include <osgEarth/Export> 00024 #include <osgEarth/Notify> 00025 #include <osg/Referenced> 00026 #include <osg/ref_ptr> 00027 #include <osg/Version> 00028 #include <string> 00029 00030 // define the OSG Version checks for older OSG versions 00031 00032 #ifndef OSG_MIN_VERSION_REQUIRED 00033 # define OSG_MIN_VERSION_REQUIRED(MAJOR, MINOR, PATCH) ((OPENSCENEGRAPH_MAJOR_VERSION>MAJOR) || (OPENSCENEGRAPH_MAJOR_VERSION==MAJOR && (OPENSCENEGRAPH_MINOR_VERSION>MINOR || (OPENSCENEGRAPH_MINOR_VERSION==MINOR && OPENSCENEGRAPH_PATCH_VERSION>=PATCH)))) 00034 # define OSG_VERSION_LESS_THAN(MAJOR, MINOR, PATCH) ((OPENSCENEGRAPH_MAJOR_VERSION<MAJOR) || (OPENSCENEGRAPH_MAJOR_VERSION==MAJOR && (OPENSCENEGRAPH_MINOR_VERSION<MINOR || (OPENSCENEGRAPH_MINOR_VERSION==MINOR && OPENSCENEGRAPH_PATCH_VERSION<PATCH)))) 00035 # define OSG_VERSION_LESS_OR_EQUAL(MAJOR, MINOR, PATCH) ((OPENSCENEGRAPH_MAJOR_VERSION<MAJOR) || (OPENSCENEGRAPH_MAJOR_VERSION==MAJOR && (OPENSCENEGRAPH_MINOR_VERSION<MINOR || (OPENSCENEGRAPH_MINOR_VERSION==MINOR && OPENSCENEGRAPH_PATCH_VERSION<=PATCH)))) 00036 # define OSG_VERSION_GREATER_THAN(MAJOR, MINOR, PATCH) ((OPENSCENEGRAPH_MAJOR_VERSION>MAJOR) || (OPENSCENEGRAPH_MAJOR_VERSION==MAJOR && (OPENSCENEGRAPH_MINOR_VERSION>MINOR || (OPENSCENEGRAPH_MINOR_VERSION==MINOR && OPENSCENEGRAPH_PATCH_VERSION>PATCH)))) 00037 # define OSG_VERSION_GREATER_OR_EQUAL(MAJOR, MINOR, PATCH) ((OPENSCENEGRAPH_MAJOR_VERSION>MAJOR) || (OPENSCENEGRAPH_MAJOR_VERSION==MAJOR && (OPENSCENEGRAPH_MINOR_VERSION>MINOR || (OPENSCENEGRAPH_MINOR_VERSION==MINOR && OPENSCENEGRAPH_PATCH_VERSION>=PATCH)))) 00038 #endif 00039 00041 namespace osgEarth 00042 { 00043 // application-wide unique ID. 00044 typedef int UID; 00045 00051 template<typename T> struct optional { 00052 optional() : _set(false), _value(T()), _defaultValue(T()) { } 00053 optional(T defaultValue) : _set(false), _value(defaultValue), _defaultValue(defaultValue) { } 00054 optional(T defaultValue, T value) : _set(true), _value(value), _defaultValue(defaultValue) { } 00055 optional(const optional<T>& rhs) { (*this)=rhs; } 00056 virtual ~optional() { } 00057 optional<T>& operator =(const optional<T>& rhs) { _set=rhs._set; _value=rhs._value; _defaultValue=rhs._defaultValue; return *this; } 00058 const T& operator =(const T& value) { _set=true; _value=value; return _value; } 00059 bool operator ==(const optional<T>& rhs) const { return _set && rhs._set && _value==rhs._value; } 00060 bool operator !=(const optional<T>& rhs) const { return !( (*this)==rhs); } 00061 bool operator ==(const T& value) const { return _value==value; } 00062 bool operator !=(const T& value) const { return _value!=value; } 00063 bool isSetTo(const T& value) const { return _set && _value==value; } // differs from == in that the value must be explicity set 00064 bool isSet() const { return _set; } 00065 void unset() { _set = false; _value=_defaultValue; } 00066 00067 //T& get() { return _value; } 00068 const T& get() const { return _value; } 00069 const T& value() const { return _value; } 00070 const T& defaultValue() const { return _defaultValue; } 00071 00072 // gets a mutable reference, automatically setting 00073 T& mutable_value() { _set = true; return _value; } 00074 00075 void init(T defValue) { _value=defValue; _defaultValue=defValue; unset(); } 00076 00077 operator const T*() const { return &_value; } 00078 00079 T* operator ->() { _set=true; return &_value; } 00080 const T* operator ->() const { return &_value; } 00081 00082 private: 00083 bool _set; 00084 T _value; 00085 T _defaultValue; 00086 typedef T* optional::*unspecified_bool_type; 00087 00088 public: 00089 operator unspecified_bool_type() const { return 0; } 00090 }; 00091 } 00092 00093 // backwards-compat stuff: 00094 00095 #if OSG_VERSION_LESS_THAN( 2, 9, 5 ) 00096 00097 #include <osgDB/ReaderWriter> 00098 namespace osgDB 00099 { 00100 typedef osgDB::ReaderWriter::Options Options; 00101 } 00102 00103 #endif // OSG_VERSION_LESS_THAN( 2, 9, 5 ) 00104 00105 #if OSG_MIN_VERSION_REQUIRED(2,9,8) 00106 # include <osgGA/CameraManipulator> 00107 namespace osgGA { 00108 typedef CameraManipulator MatrixManipulator; 00109 }; 00110 # include <osg/ObserverNodePath> 00111 # define USE_OBSERVER_NODE_PATH 1 00112 #else 00113 # include <osgGA/MatrixManipulator> 00114 #endif 00115 00116 00117 #endif // OSGEARTH_COMMON_H