Blaze  3.6
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 <memory>
48 
49 
50 namespace blaze {
51 
52 //=================================================================================================
53 //
54 // CLASS DEFINITION
55 //
56 //=================================================================================================
57 
58 //*************************************************************************************************
66 template< typename Type > // Type of the shared value
68 {
69  public:
70  //**Type definitions****************************************************************************
71  using ValueType = Type;
72  using Reference = Type&;
73  using ConstReference = const Type&;
74  using Pointer = Type*;
75  using ConstPointer = const Type*;
76  //**********************************************************************************************
77 
78  //**Constructors********************************************************************************
81  explicit inline SharedValue();
82  explicit inline SharedValue( const Type& value );
83 
84  SharedValue( const SharedValue& ) = default;
85  SharedValue( SharedValue&& ) = default;
87  //**********************************************************************************************
88 
89  //**Destructor**********************************************************************************
92  ~SharedValue() = default;
94  //**********************************************************************************************
95 
96  //**Assignment operators************************************************************************
99  SharedValue& operator=( const SharedValue& ) = default;
100  SharedValue& operator=( SharedValue&& ) = default;
102  //**********************************************************************************************
103 
104  //**Access operators****************************************************************************
107  inline Reference operator* ();
108  inline ConstReference operator* () const;
110  //**********************************************************************************************
111 
112  //**Utility functions***************************************************************************
115  inline Pointer base() const noexcept;
117  //**********************************************************************************************
118 
119  private:
120  //**Member variables****************************************************************************
123  mutable std::shared_ptr<Type> value_;
124 
125  //**********************************************************************************************
126 
127  //**Forbidden operations************************************************************************
130  void* operator&() const;
131 
132  //**********************************************************************************************
133 
134  //**Compile time checks*************************************************************************
141  //**********************************************************************************************
142 };
143 //*************************************************************************************************
144 
145 
146 
147 
148 //=================================================================================================
149 //
150 // CONSTRUCTORS
151 //
152 //=================================================================================================
153 
154 //*************************************************************************************************
157 template< typename Type > // Type of the shared value
158 inline SharedValue<Type>::SharedValue()
159  : value_() // The shared value
160 {}
161 //*************************************************************************************************
162 
163 
164 //*************************************************************************************************
171 template< typename Type > // Type of the shared value
172 inline SharedValue<Type>::SharedValue( const Type& value )
173  : value_( new Type( value ) ) // The shared value
174 {}
175 //*************************************************************************************************
176 
177 
178 
179 
180 //=================================================================================================
181 //
182 // ACCESS OPERATORS
183 //
184 //=================================================================================================
185 
186 //*************************************************************************************************
191 template< typename Type > // Type of the shared value
193 {
194  if( !value_ )
195  value_.reset( new Type() );
196  return *value_;
197 }
198 //*************************************************************************************************
199 
200 
201 //*************************************************************************************************
206 template< typename Type > // Type of the shared value
208 {
209  if( !value_ )
210  value_.reset( new Type() );
211  return *value_;
212 }
213 //*************************************************************************************************
214 
215 
216 
217 
218 //=================================================================================================
219 //
220 // UTILITY FUNCTIONS
221 //
222 //=================================================================================================
223 
224 //*************************************************************************************************
229 template< typename Type > // Type of the shared value
230 inline typename SharedValue<Type>::Pointer SharedValue<Type>::base() const noexcept
231 {
232  return value_.get();
233 }
234 //*************************************************************************************************
235 
236 
237 
238 
239 //=================================================================================================
240 //
241 // GLOBAL OPERATORS
242 //
243 //=================================================================================================
244 
245 //*************************************************************************************************
248 template< typename T1, typename T2 >
249 bool operator==( const SharedValue<T1>& lhs, const SharedValue<T2>& rhs );
250 
251 template< typename T1, typename T2 >
252 bool operator!=( const SharedValue<T1>& lhs, const SharedValue<T2>& rhs );
254 //*************************************************************************************************
255 
256 
257 //*************************************************************************************************
265 template< typename T1, typename T2 >
266 inline bool operator==( const SharedValue<T1>& lhs, const SharedValue<T2>& rhs )
267 {
268  return ( lhs.base() == rhs.base() );
269 }
270 //*************************************************************************************************
271 
272 
273 //*************************************************************************************************
281 template< typename T1, typename T2 >
282 inline bool operator!=( const SharedValue<T1>& lhs, const SharedValue<T2>& rhs )
283 {
284  return ( lhs.base() != rhs.base() );
285 }
286 //*************************************************************************************************
287 
288 
289 
290 
291 //=================================================================================================
292 //
293 // GLOBAL FUNCTIONS
294 //
295 //=================================================================================================
296 
297 //*************************************************************************************************
300 template< bool RF, typename Type >
301 bool isDefault( const SharedValue<Type>& value );
302 
303 template< bool RF, typename T1, typename T2 >
304 bool equal( const SharedValue<T1>& lhs, const SharedValue<T2>& rhs );
306 //*************************************************************************************************
307 
308 
309 //*************************************************************************************************
319 template< bool RF, typename Type >
320 inline bool isDefault( const SharedValue<Type>& value )
321 {
322  using blaze::isDefault;
323 
324  return isDefault<RF>( *value );
325 }
326 //*************************************************************************************************
327 
328 
329 //*************************************************************************************************
341 template< bool RF, typename T1, typename T2 >
342 inline bool equal( const SharedValue<T1>& a, const SharedValue<T2>& b )
343 {
344  return equal<RF>( *a, *b );
345 }
346 //*************************************************************************************************
347 
348 } // namespace blaze
349 
350 #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,...
Definition: Const.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.In case the given data type is a volatile-qualified type,...
Definition: Volatile.h:79
const Type & ConstReference
Reference-to-const to the shared value.
Definition: SharedValue.h:73
Constraint on the data type.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
#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:79
Reference operator *()
Direct access to the shared value.
Definition: SharedValue.h:192
constexpr bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:253
Constraint on the data type.
SharedValue()
Default constructor for a SharedValue.
Definition: SharedValue.h:158
Type & Reference
Reference to the shared value.
Definition: SharedValue.h:72
const Type * ConstPointer
Pointer-to-const to the shared value.
Definition: SharedValue.h:75
Type * Pointer
Pointer to the shared value.
Definition: SharedValue.h:74
constexpr bool operator!=(const NegativeAccuracy< A > &lhs, const T &rhs)
Inequality comparison between a NegativeAccuracy object and a floating point value.
Definition: Accuracy.h:293
Type ValueType
Type of the shared value.
Definition: SharedValue.h:71
Constraint on the data type.
Pointer base() const noexcept
Low-level access to the underlying, shared value.
Definition: SharedValue.h:230
#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,...
Definition: Reference.h:79
Constraint on the data type.
std::shared_ptr< Type > value_
The shared value.
Definition: SharedValue.h:123
Value shared among several positions within a symmetric matrix.The SharedValue class template represe...
Definition: SharedValue.h:67
bool isDefault(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is in default state.
Definition: DiagonalProxy.h:635
bool equal(const SharedValue< T1 > &lhs, const SharedValue< T2 > &rhs)
Equality check for a two shared values.
Definition: SharedValue.h:342