| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#if !defined( INCLUDED_GENERIC_REFERENCE_H ) |
| 23 |
#define INCLUDED_GENERIC_REFERENCE_H |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
template<typename Type> |
| 32 |
class Reference |
| 33 |
{ |
| 34 |
Type* m_contained; |
| 35 |
public: |
| 36 |
explicit Reference( Type& contained ) : m_contained( &contained ){ |
| 37 |
} |
| 38 |
operator Type&() const |
| 39 |
{ |
| 40 |
return *m_contained; |
| 41 |
} |
| 42 |
Type& get() const { |
| 43 |
return *m_contained; |
| 44 |
} |
| 45 |
Type* get_pointer() const { |
| 46 |
return m_contained; |
| 47 |
} |
| 48 |
}; |
| 49 |
|
| 50 |
template<typename Type> |
| 51 |
bool operator<( const Reference<Type>& self, const Reference<Type>& other ){ |
| 52 |
return self.get() < other.get(); |
| 53 |
} |
| 54 |
template<typename Type> |
| 55 |
bool operator==( const Reference<Type>& self, const Reference<Type>& other ){ |
| 56 |
return self.get() == other.get(); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
template<typename Type> |
| 61 |
inline Reference<Type> makeReference( Type& value ){ |
| 62 |
return Reference<Type>( value ); |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
template<typename Type> |
| 69 |
class ConstReference |
| 70 |
{ |
| 71 |
const Type* m_contained; |
| 72 |
public: |
| 73 |
explicit ConstReference( const Type& contained ) : m_contained( &contained ){ |
| 74 |
} |
| 75 |
operator const Type&() const |
| 76 |
{ |
| 77 |
return *m_contained; |
| 78 |
} |
| 79 |
const Type& get() const { |
| 80 |
return *m_contained; |
| 81 |
} |
| 82 |
const Type* get_pointer() const { |
| 83 |
return m_contained; |
| 84 |
} |
| 85 |
}; |
| 86 |
|
| 87 |
template<typename Type> |
| 88 |
bool operator<( const ConstReference<Type>& self, const ConstReference<Type>& other ){ |
| 89 |
return self.get() < other.get(); |
| 90 |
} |
| 91 |
template<typename Type> |
| 92 |
bool operator==( const ConstReference<Type>& self, const ConstReference<Type>& other ){ |
| 93 |
return self.get() == other.get(); |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
template<typename Type> |
| 98 |
inline ConstReference<Type> makeReference( const Type& value ){ |
| 99 |
return ConstReference<Type>( value ); |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
#endif |