Blaze 3.9
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>
49
50
51namespace blaze {
52
53//=================================================================================================
54//
55// CLASS DEFINITION
56//
57//=================================================================================================
58
59//*************************************************************************************************
67template< typename Type > // Type of the shared value
69{
70 public:
71 //**Type definitions****************************************************************************
72 using ValueType = Type;
73 using Reference = Type&;
74 using ConstReference = const Type&;
75 using Pointer = Type*;
76 using ConstPointer = const Type*;
77 //**********************************************************************************************
78
79 //**Constructors********************************************************************************
82 inline SharedValue();
83 explicit inline SharedValue( const Type& value );
84
85 SharedValue( const SharedValue& ) = default;
86 SharedValue( SharedValue&& ) = default;
88 //**********************************************************************************************
89
90 //**Destructor**********************************************************************************
93 ~SharedValue() = default;
95 //**********************************************************************************************
96
97 //**Assignment operators************************************************************************
100 SharedValue& operator=( const SharedValue& ) = default;
101 SharedValue& operator=( SharedValue&& ) = default;
103 //**********************************************************************************************
104
105 //**Access operators****************************************************************************
108 inline Reference operator* ();
109 inline ConstReference operator* () const;
111 //**********************************************************************************************
112
113 //**Utility functions***************************************************************************
116 inline Pointer base() const noexcept;
118 //**********************************************************************************************
119
120 private:
121 //**Member variables****************************************************************************
124 mutable std::shared_ptr<Type> value_;
126 //**********************************************************************************************
127
128 //**Forbidden operations************************************************************************
131 void* operator&() const;
133 //**********************************************************************************************
134
135 //**Compile time checks*************************************************************************
142 //**********************************************************************************************
143};
144//*************************************************************************************************
145
146
147
148
149//=================================================================================================
150//
151// CONSTRUCTORS
152//
153//=================================================================================================
154
155//*************************************************************************************************
158template< typename Type > // Type of the shared value
160 : value_() // The shared value
161{}
162//*************************************************************************************************
163
164
165//*************************************************************************************************
172template< typename Type > // Type of the shared value
173inline SharedValue<Type>::SharedValue( const Type& value )
174 : value_( new Type( value ) ) // The shared value
175{}
176//*************************************************************************************************
177
178
179
180
181//=================================================================================================
182//
183// ACCESS OPERATORS
184//
185//=================================================================================================
186
187//*************************************************************************************************
192template< typename Type > // Type of the shared value
194{
195 if( !value_ )
196 value_.reset( new Type() );
197 return *value_;
198}
199//*************************************************************************************************
200
201
202//*************************************************************************************************
207template< typename Type > // Type of the shared value
209{
210 if( !value_ )
211 value_.reset( new Type() );
212 return *value_;
213}
214//*************************************************************************************************
215
216
217
218
219//=================================================================================================
220//
221// UTILITY FUNCTIONS
222//
223//=================================================================================================
224
225//*************************************************************************************************
230template< typename Type > // Type of the shared value
232{
233 return value_.get();
234}
235//*************************************************************************************************
236
237
238
239
240//=================================================================================================
241//
242// GLOBAL OPERATORS
243//
244//=================================================================================================
245
246//*************************************************************************************************
249template< typename T1, typename T2 >
250bool operator==( const SharedValue<T1>& lhs, const SharedValue<T2>& rhs );
251
252template< typename T1, typename T2 >
253bool operator!=( const SharedValue<T1>& lhs, const SharedValue<T2>& rhs );
255//*************************************************************************************************
256
257
258//*************************************************************************************************
266template< typename T1, typename T2 >
267inline bool operator==( const SharedValue<T1>& lhs, const SharedValue<T2>& rhs )
268{
269 return ( lhs.base() == rhs.base() );
270}
271//*************************************************************************************************
272
273
274//*************************************************************************************************
282template< typename T1, typename T2 >
283inline bool operator!=( const SharedValue<T1>& lhs, const SharedValue<T2>& rhs )
284{
285 return ( lhs.base() != rhs.base() );
286}
287//*************************************************************************************************
288
289
290
291
292//=================================================================================================
293//
294// GLOBAL FUNCTIONS
295//
296//=================================================================================================
297
298//*************************************************************************************************
301template< RelaxationFlag RF, typename Type >
302bool isDefault( const SharedValue<Type>& value );
303
304template< RelaxationFlag RF, typename T1, typename T2 >
305bool equal( const SharedValue<T1>& lhs, const SharedValue<T2>& rhs );
307//*************************************************************************************************
308
309
310//*************************************************************************************************
320template< RelaxationFlag RF, typename Type >
321inline bool isDefault( const SharedValue<Type>& value )
322{
323 using blaze::isDefault;
324
325 return isDefault<RF>( *value );
326}
327//*************************************************************************************************
328
329
330//*************************************************************************************************
342template< RelaxationFlag RF, typename T1, typename T2 >
343inline bool equal( const SharedValue<T1>& a, const SharedValue<T2>& b )
344{
345 return equal<RF>( *a, *b );
346}
347//*************************************************************************************************
348
349} // namespace blaze
350
351#endif
Constraint on the data type.
Constraint on the data type.
Constraint on the data type.
Header file for the relaxation flag enumeration.
Constraint on the data type.
Value shared among several positions within a symmetric matrix.
Definition: SharedValue.h:69
Pointer base() const noexcept
Low-level access to the underlying, shared value.
Definition: SharedValue.h:231
Type * Pointer
Pointer to the shared value.
Definition: SharedValue.h:75
Type & Reference
Reference to the shared value.
Definition: SharedValue.h:73
const Type & ConstReference
Reference-to-const to the shared value.
Definition: SharedValue.h:74
Type ValueType
Type of the shared value.
Definition: SharedValue.h:72
Reference operator*()
Direct access to the shared value.
Definition: SharedValue.h:193
const Type * ConstPointer
Pointer-to-const to the shared value.
Definition: SharedValue.h:76
std::shared_ptr< Type > value_
The shared value.
Definition: SharedValue.h:124
SharedValue()
Default constructor for a SharedValue.
Definition: SharedValue.h:159
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.
Definition: Volatile.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_POINTER_TYPE(T)
Constraint on the data type.
Definition: Pointer.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.
Definition: Const.h:79
#define BLAZE_CONSTRAINT_MUST_NOT_BE_REFERENCE_TYPE(T)
Constraint on the data type.
Definition: Reference.h:79
bool equal(const SharedValue< T1 > &lhs, const SharedValue< T2 > &rhs)
Equality check for a two shared values.
Definition: SharedValue.h:343
bool operator!=(const SharedValue< T1 > &lhs, const SharedValue< T2 > &rhs)
Inequality comparison between two SharedValue objects.
Definition: SharedValue.h:283
bool operator==(const SharedValue< T1 > &lhs, const SharedValue< T2 > &rhs)
Equality comparison between two SharedValue objects.
Definition: SharedValue.h:267
bool isDefault(const SharedValue< Type > &value)
Returns whether the shared value is in default state.
Definition: SharedValue.h:321