SharedValue.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_ADAPTORS_SYMMETRICMATRIX_SHAREDVALUE_H_
36 #define _BLAZE_MATH_ADAPTORS_SYMMETRICMATRIX_SHAREDVALUE_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <boost/shared_ptr.hpp>
44 #include <blaze/math/shims/Move.h>
49 
50 
51 namespace blaze {
52 
53 //=================================================================================================
54 //
55 // CLASS DEFINITION
56 //
57 //=================================================================================================
58 
59 //*************************************************************************************************
67 template< typename Type > // Type of the shared value
69 {
70  public:
71  //**Type definitions****************************************************************************
72  typedef Type ValueType;
73  typedef Type& Reference;
74  typedef const Type& ConstReference;
75  typedef Type* Pointer;
76  typedef const Type* ConstPointer;
77  //**********************************************************************************************
78 
79  //**Constructors********************************************************************************
82  explicit inline SharedValue();
83  explicit inline SharedValue( const Type& value );
84  // No explicitly declared copy constructor.
86  //**********************************************************************************************
87 
88  //**Destructor**********************************************************************************
89  // No explicitly declared destructor.
90  //**********************************************************************************************
91 
92  //**Access operators****************************************************************************
95  inline Reference operator* ();
96  inline ConstReference operator* () const;
98  //**********************************************************************************************
99 
100  //**Utility functions***************************************************************************
103  inline Pointer base() const;
105  //**********************************************************************************************
106 
107  private:
108  //**Member variables****************************************************************************
111  mutable boost::shared_ptr<Type> value_;
112 
113  //**********************************************************************************************
114 
115  //**Forbidden operations************************************************************************
118  void* operator&() const;
119 
120  //**********************************************************************************************
121 
122  //**Compile time checks*************************************************************************
129  //**********************************************************************************************
130 };
131 //*************************************************************************************************
132 
133 
134 
135 
136 //=================================================================================================
137 //
138 // CONSTRUCTORS
139 //
140 //=================================================================================================
141 
142 //*************************************************************************************************
145 template< typename Type > // Type of the shared value
147  : value_() // The shared value
148 {}
149 //*************************************************************************************************
150 
151 
152 //*************************************************************************************************
159 template< typename Type > // Type of the shared value
160 inline SharedValue<Type>::SharedValue( const Type& value )
161  : value_( new Type( value ) ) // The shared value
162 {}
163 //*************************************************************************************************
164 
165 
166 
167 
168 //=================================================================================================
169 //
170 // ACCESS OPERATORS
171 //
172 //=================================================================================================
173 
174 //*************************************************************************************************
179 template< typename Type > // Type of the shared value
181 {
182  if( !value_ )
183  value_.reset( new Type() );
184  return *value_;
185 }
186 //*************************************************************************************************
187 
188 
189 //*************************************************************************************************
194 template< typename Type > // Type of the shared value
196 {
197  if( !value_ )
198  value_.reset( new Type() );
199  return *value_;
200 }
201 //*************************************************************************************************
202 
203 
204 
205 
206 //=================================================================================================
207 //
208 // UTILITY FUNCTIONS
209 //
210 //=================================================================================================
211 
212 //*************************************************************************************************
217 template< typename Type > // Type of the shared value
219 {
220  return value_.get();
221 }
222 //*************************************************************************************************
223 
224 
225 
226 
227 //=================================================================================================
228 //
229 // GLOBAL OPERATORS
230 //
231 //=================================================================================================
232 
233 //*************************************************************************************************
236 template< typename T1, typename T2 >
237 inline bool operator==( const SharedValue<T1>& lhs, const SharedValue<T2>& rhs );
238 
239 template< typename T1, typename T2 >
240 inline bool operator!=( const SharedValue<T1>& lhs, const SharedValue<T2>& rhs );
242 //*************************************************************************************************
243 
244 
245 //*************************************************************************************************
253 template< typename T1, typename T2 >
254 inline bool operator==( const SharedValue<T1>& lhs, const SharedValue<T2>& rhs )
255 {
256  return ( lhs.base() == rhs.base() );
257 }
258 //*************************************************************************************************
259 
260 
261 //*************************************************************************************************
269 template< typename T1, typename T2 >
270 inline bool operator!=( const SharedValue<T1>& lhs, const SharedValue<T2>& rhs )
271 {
272  return ( lhs.base() != rhs.base() );
273 }
274 //*************************************************************************************************
275 
276 
277 
278 
279 //=================================================================================================
280 //
281 // GLOBAL FUNCTIONS
282 //
283 //=================================================================================================
284 
285 //*************************************************************************************************
288 template< typename Type >
289 inline bool isDefault( const SharedValue<Type>& value );
291 //*************************************************************************************************
292 
293 
294 //*************************************************************************************************
304 template< typename Type >
305 inline bool isDefault( const SharedValue<Type>& value )
306 {
307  using blaze::isDefault;
308 
309  return isDefault( *value );
310 }
311 //*************************************************************************************************
312 
313 } // namespace blaze
314 
315 #endif
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.In case the given data type is a const-qualified type, a compilation error is created.
Definition: Const.h:116
Type & Reference
Reference to the shared value.
Definition: SharedValue.h:73
const Type * ConstPointer
Pointer-to-const to the shared value.
Definition: SharedValue.h:76
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.In case the given data type is a volatile-qualified type, a compilation error is created.
Definition: Volatile.h:116
Type * Pointer
Pointer to the shared value.
Definition: SharedValue.h:75
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:861
Constraint on the data type.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.In case the given data type T is not a pointer type, a compilation error ...
Definition: Pointer.h:116
Constraint on the data type.
SharedValue()
Default constructor for a SharedValue.
Definition: SharedValue.h:146
Pointer base() const
Low-level access to the underlying, shared value.
Definition: SharedValue.h:218
void * operator&() const
Address operator (private & undefined)
Constraint on the data type.
boost::shared_ptr< Type > value_
The shared value.
Definition: SharedValue.h:111
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.In case the given data type T is not a reference type, a compilation error is created.
Definition: Reference.h:116
Constraint on the data type.
Header file for the move shim.
Type ValueType
Type of the shared value.
Definition: SharedValue.h:72
Value shared among several positions within a symmetric matrix.The SharedValue class template represe...
Definition: SharedValue.h:68
bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:249
bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:289
const Type & ConstReference
Reference-to-const to the shared value.
Definition: SharedValue.h:74
Reference operator*()
Direct access to the shared value.
Definition: SharedValue.h:180