reference.h

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2001-2006, William Joseph.
00003 All Rights Reserved.
00004 
00005 This file is part of GtkRadiant.
00006 
00007 GtkRadiant is free software; you can redistribute it and/or modify
00008 it under the terms of the GNU General Public License as published by
00009 the Free Software Foundation; either version 2 of the License, or
00010 (at your option) any later version.
00011 
00012 GtkRadiant is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with GtkRadiant; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 */
00021 
00022 #if !defined(INCLUDED_GENERIC_REFERENCE_H)
00023 #define INCLUDED_GENERIC_REFERENCE_H
00024 
00027 
00031 template<typename Type>
00032 class Reference {
00033     Type* m_contained;
00034 public:
00035     explicit Reference(Type& contained) : m_contained(&contained) {
00036     }
00037     operator Type&() const {
00038         return *m_contained;
00039     }
00040     Type& get() const {
00041         return *m_contained;
00042     }
00043     Type* get_pointer() const {
00044         return m_contained;
00045     }
00046 };
00047 
00048 template<typename Type>
00049 bool operator<(const Reference<Type>& self, const Reference<Type>& other) {
00050     return self.get() < other.get();
00051 }
00052 template<typename Type>
00053 bool operator==(const Reference<Type>& self, const Reference<Type>& other) {
00054     return self.get() == other.get();
00055 }
00056 
00058 template<typename Type>
00059 inline Reference<Type> makeReference(Type& value) {
00060     return Reference<Type>(value);
00061 }
00062 
00066 template<typename Type>
00067 class ConstReference {
00068     const Type* m_contained;
00069 public:
00070     explicit ConstReference(const Type& contained) : m_contained(&contained) {
00071     }
00072     operator const Type&() const {
00073         return *m_contained;
00074     }
00075     const Type& get() const {
00076         return *m_contained;
00077     }
00078     const Type* get_pointer() const {
00079         return m_contained;
00080     }
00081 };
00082 
00083 template<typename Type>
00084 bool operator<(const ConstReference<Type>& self, const ConstReference<Type>& other) {
00085     return self.get() < other.get();
00086 }
00087 template<typename Type>
00088 bool operator==(const ConstReference<Type>& self, const ConstReference<Type>& other) {
00089     return self.get() == other.get();
00090 }
00091 
00093 template<typename Type>
00094 inline ConstReference<Type> makeReference(const Type& value) {
00095     return ConstReference<Type>(value);
00096 }
00097 
00098 
00099 #endif

Generated by  doxygen 1.6.2