swift
Public Member Functions | List of all members
swift::misc::CCached< T > Class Template Reference

Provides access to one of the values stored in a CValueCache. More...

Public Member Functions

template<typename U >
 CCached (CValueCache *cache, const QString &key, const QString &name, U *owner)
 Constructor. More...
 
template<typename U , typename F >
 CCached (CValueCache *cache, const QString &key, const QString &name, F validator, const T &defaultValue, U *owner)
 Constructor. More...
 
template<typename F >
void setNotifySlot (F slot)
 Set a callback to be called when the value is changed by another source.
 
const T & getThreadLocal () const
 Read the current value.
 
get () const
 Get a copy of the current value. More...
 
CStatusMessage set (const T &value, qint64 timestamp=0)
 Write a new value. Must be called from the thread in which the owner lives.
 
CStatusMessage setAndSave (const T &value, qint64 timestamp=0)
 Write and save in the same step. Must be called from the thread in which the owner lives.
 
CStatusMessage save ()
 Save using the currently set value. Must be called from the thread in which the owner lives.
 
CStatusMessage setProperty (CPropertyIndexRef index, const CVariant &value, qint64 timestamp=0)
 Write a property of the value. Must be called from the thread in which the owner lives.
 
CStatusMessage setAndSaveProperty (CPropertyIndexRef index, const CVariant &value, qint64 timestamp=0)
 Write a property and save in the same step. Must be called from the thread in which the owner lives.
 
bool isOwnerThread () const
 Is current thread the owner thread, so CCached::set is safe.
 
const QString & getKey () const
 Get the key string of this value.
 
QDateTime getTimestamp () const
 Return the time when this value was updated. More...
 
qint64 getTimestampMsSinceEpoch () const
 Return the time when this value was updated. More...
 
qint64 lastUpdatedAge () const
 How old is that cache (ms)?
 
bool isSaved () const
 Return true if this value was already saved.
 
bool isSaving () const
 Return true if this value is currently saving.
 
bool isInitialized () const
 Can be false if key contains OwnerName% and owner's objectName was empty.
 
 CCached (const CCached &)=delete
 Deleted copy constructor.
 
CCachedoperator= (const CCached &)=delete
 Deleted copy assignment operator.
 

Detailed Description

template<typename T>
class swift::misc::CCached< T >

Provides access to one of the values stored in a CValueCache.

Template Parameters
TThe expected value type of the cached value.

Definition at line 352 of file valuecache.h.

Constructor & Destructor Documentation

◆ CCached() [1/2]

template<typename T >
template<typename U >
swift::misc::CCached< T >::CCached ( CValueCache cache,
const QString &  key,
const QString &  name,
U *  owner 
)
inline

Constructor.

Parameters
cacheThe CValueCache object which manages the value.
keyThe key string which identifies the value.
nameHuman readable name corresponding to the key.
ownerWill be the parent of the internal QObject used for signal/slot connections.

Definition at line 361 of file valuecache.h.

◆ CCached() [2/2]

template<typename T >
template<typename U , typename F >
swift::misc::CCached< T >::CCached ( CValueCache cache,
const QString &  key,
const QString &  name,
validator,
const T &  defaultValue,
U *  owner 
)
inline

Constructor.

Parameters
cacheThe CValueCache object which manages the value.
keyThe key string which identifies the value.
nameHuman readable name corresponding to the key.
validatorA functor which tests the validity of a value and returns true if it is valid.
defaultValueA value which will be used as default if the value is invalid.
ownerWill be the parent of the internal QObject used for signal/slot connections.

Definition at line 373 of file valuecache.h.

Member Function Documentation

◆ get()

template<typename T >
T swift::misc::CCached< T >::get ( ) const
inline

Get a copy of the current value.

Remarks
This function is thread safe.

Definition at line 408 of file valuecache.h.

◆ getTimestamp()

template<typename T >
QDateTime swift::misc::CCached< T >::getTimestamp ( ) const
inline

Return the time when this value was updated.

Remarks
This function is thread safe. with tiny risk of mismatch of value and timestamp

Definition at line 449 of file valuecache.h.

◆ getTimestampMsSinceEpoch()

template<typename T >
qint64 swift::misc::CCached< T >::getTimestampMsSinceEpoch ( ) const
inline

Return the time when this value was updated.

Remarks
This function is thread safe. with tiny risk of mismatch of value and timestamp

Definition at line 453 of file valuecache.h.


The documentation for this class was generated from the following file: