reference.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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