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  // No explicitly declared copy constructor.
85  //**********************************************************************************************
86 
87  //**Destructor**********************************************************************************
88  // No explicitly declared destructor.
89  //**********************************************************************************************
90 
91  //**Access operators****************************************************************************
94  inline Reference operator* ();
95  inline ConstReference operator* () const;
97  //**********************************************************************************************
98 
99  //**Utility functions***************************************************************************
102  inline Pointer base() const noexcept;
104  //**********************************************************************************************
105 
106  private:
107  //**Member variables****************************************************************************
110  mutable std::shared_ptr<Type> value_;
111 
112  //**********************************************************************************************
113 
114  //**Forbidden operations************************************************************************
117  void* operator&() const;
118 
119  //**********************************************************************************************
120 
121  //**Compile time checks*************************************************************************
128  //**********************************************************************************************
129 };
130 //*************************************************************************************************
131 
132 
133 
134 
135 //=================================================================================================
136 //
137 // CONSTRUCTORS
138 //
139 //=================================================================================================
140 
141 //*************************************************************************************************
144 template< typename Type > // Type of the shared value
145 inline SharedValue<Type>::SharedValue()
146  : value_() // The shared value
147 {}
148 //*************************************************************************************************
149 
150 
151 //*************************************************************************************************
158 template< typename Type > // Type of the shared value
159 inline SharedValue<Type>::SharedValue( const Type& value )
160  : value_( new Type( value ) ) // The shared value
161 {}
162 //*************************************************************************************************
163 
164 
165 
166 
167 //=================================================================================================
168 //
169 // ACCESS OPERATORS
170 //
171 //=================================================================================================
172 
173 //*************************************************************************************************
178 template< typename Type > // Type of the shared value
180 {
181  if( !value_ )
182  value_.reset( new Type() );
183  return *value_;
184 }
185 //*************************************************************************************************
186 
187 
188 //*************************************************************************************************
193 template< typename Type > // Type of the shared value
195 {
196  if( !value_ )
197  value_.reset( new Type() );
198  return *value_;
199 }
200 //*************************************************************************************************
201 
202 
203 
204 
205 //=================================================================================================
206 //
207 // UTILITY FUNCTIONS
208 //
209 //=================================================================================================
210 
211 //*************************************************************************************************
216 template< typename Type > // Type of the shared value
217 inline typename SharedValue<Type>::Pointer SharedValue<Type>::base() const noexcept
218 {
219  return value_.get();
220 }
221 //*************************************************************************************************
222 
223 
224 
225 
226 //=================================================================================================
227 //
228 // GLOBAL OPERATORS
229 //
230 //=================================================================================================
231 
232 //*************************************************************************************************
235 template< typename T1, typename T2 >
236 inline bool operator==( const SharedValue<T1>& lhs, const SharedValue<T2>& rhs );
237 
238 template< typename T1, typename T2 >
239 inline bool operator!=( const SharedValue<T1>& lhs, const SharedValue<T2>& rhs );
241 //*************************************************************************************************
242 
243 
244 //*************************************************************************************************
252 template< typename T1, typename T2 >
253 inline bool operator==( const SharedValue<T1>& lhs, const SharedValue<T2>& rhs )
254 {
255  return ( lhs.base() == rhs.base() );
256 }
257 //*************************************************************************************************
258 
259 
260 //*************************************************************************************************
268 template< typename T1, typename T2 >
269 inline bool operator!=( const SharedValue<T1>& lhs, const SharedValue<T2>& rhs )
270 {
271  return ( lhs.base() != rhs.base() );
272 }
273 //*************************************************************************************************
274 
275 
276 
277 
278 //=================================================================================================
279 //
280 // GLOBAL FUNCTIONS
281 //
282 //=================================================================================================
283 
284 //*************************************************************************************************
287 template< bool RF, typename Type >
288 inline bool isDefault( const SharedValue<Type>& value );
290 //*************************************************************************************************
291 
292 
293 //*************************************************************************************************
303 template< bool RF, typename Type >
304 inline bool isDefault( const SharedValue<Type>& value )
305 {
306  using blaze::isDefault;
307 
308  return isDefault<RF>( *value );
309 }
310 //*************************************************************************************************
311 
312 } // namespace blaze
313 
314 #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: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, a compilation error is created.
Definition: Volatile.h:79
STL namespace.
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
constexpr bool operator==(const NegativeAccuracy< A > &lhs, const T &rhs)
Equality comparison between a NegativeAccuracy object and a floating point value. ...
Definition: Accuracy.h:250
Constraint on the data type.
SharedValue()
Default constructor for a SharedValue.
Definition: SharedValue.h:145
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:290
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:217
#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:79
Constraint on the data type.
std::shared_ptr< Type > value_
The shared value.
Definition: SharedValue.h:110
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:628
Reference operator*()
Direct access to the shared value.
Definition: SharedValue.h:179