| 1 |
/* |
| 2 |
* Advanced Simulation Library <http://asl.org.il> |
| 3 |
* |
| 4 |
* Copyright 2015 Avtech Scientific <http://avtechscientific.com> |
| 5 |
* |
| 6 |
* |
| 7 |
* This file is part of Advanced Simulation Library (ASL). |
| 8 |
* |
| 9 |
* ASL is free software: you can redistribute it and/or modify it |
| 10 |
* under the terms of the GNU Affero General Public License as |
| 11 |
* published by the Free Software Foundation, version 3 of the License. |
| 12 |
* |
| 13 |
* ASL is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU Affero General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Affero General Public License |
| 19 |
* along with ASL. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
|
| 24 |
#ifndef ASLUVALUE_H |
| 25 |
#define ASLUVALUE_H |
| 26 |
|
| 27 |
#include "aslTimeStamp.h" |
| 28 |
#include <memory> |
| 29 |
|
| 30 |
namespace asl |
| 31 |
{ |
| 32 |
|
| 33 |
/// Updatable value. This class stores value and its TimeStamp \ingroup LDI |
| 34 |
template<typename T> class UValue |
| 35 |
{ |
| 36 |
public: |
| 37 |
std::shared_ptr<T> p; |
| 38 |
TimeStamp ts; |
| 39 |
inline explicit UValue():p(new T){} |
| 40 |
inline explicit UValue(const T & a):p(new T(a)){ts.update();} |
| 41 |
/// updates UValue::ts automaticaly |
| 42 |
inline const T & operator=(const T& a){ts.update(); return (*p = a);} |
| 43 |
inline const T & v() const {return *p;}; |
| 44 |
inline T & v() {return *p;}; |
| 45 |
}; |
| 46 |
|
| 47 |
/// \related UValue |
| 48 |
template<typename T> inline bool operator==(const asl::UValue<T> & a,const T & v); |
| 49 |
/// \related UValue |
| 50 |
template<typename T> inline bool operator!=(const asl::UValue<T> & a,const T & v); |
| 51 |
|
| 52 |
//-------------------------- Implementation -------------------------- |
| 53 |
|
| 54 |
|
| 55 |
template<typename T> inline bool operator==(const asl::UValue<T> & a,const T & v) |
| 56 |
{ |
| 57 |
return *(a.p) == v; |
| 58 |
} |
| 59 |
|
| 60 |
template<typename T> inline bool operator!=(const asl::UValue<T> & a,const T & v) |
| 61 |
{ |
| 62 |
return *(a.p) != v; |
| 63 |
} |
| 64 |
|
| 65 |
} //namespace asl |
| 66 |
|
| 67 |
|
| 68 |
#endif // ASLUVALUE_H |