Yate
SharedVars Class Reference

Atomic access and operations to shared variables. More...

#include <yatengine.h>

Inheritance diagram for SharedVars:
Mutex RefObject Lockable GenObject

Public Member Functions

 SharedVars (const char *name=0)
 
void get (const String &name, String &rval)
 
void set (const String &name, const char *val)
 
bool create (const String &name, const char *val=0)
 
void clear (const String &name)
 
void clearAll ()
 
bool exists (const String &name)
 
uint64_t inc (const String &name, uint64_t wrap=0)
 
uint64_t dec (const String &name, uint64_t wrap=0)
 
uint64_t add (const String &name, uint64_t val, uint64_t wrap=0)
 
uint64_t sub (const String &name, uint64_t val, uint64_t wrap=0)
 
void copy (NamedList &dest, const String &prefix=String::empty(), bool skipPrefix=true, bool replace=false)
 
virtual const StringtoString () const
 
- Public Member Functions inherited from Mutex
 Mutex (bool recursive=false, const char *name=0)
 
 Mutex (const Mutex &original)
 
 ~Mutex ()
 
Mutexoperator= (const Mutex &original)
 
virtual bool lock (long maxwait=-1)
 
virtual bool unlock ()
 
virtual bool locked () const
 
const char * owner () const
 
bool recursive () const
 
virtual MutexlockableMutex ()
 
- Public Member Functions inherited from Lockable
virtual ~Lockable ()
 
virtual bool check (long maxwait=-1)
 
virtual bool unlockAll ()
 
virtual SemaphorelockableSemaphore ()
 
virtual RWLocklockableRWLock ()
 
- Public Member Functions inherited from RefObject
 RefObject ()
 
virtual ~RefObject ()
 
virtual void * getObject (const String &name) const
 
virtual bool alive () const
 
bool ref ()
 
bool deref ()
 
int refcount () const
 
virtual void destruct ()
 
- Public Member Functions inherited from GenObject
 GenObject ()
 
virtual ~GenObject ()
 
virtual const StringtraceId () const
 
NamedCountergetObjCounter () const
 
NamedCountersetObjCounter (NamedCounter *counter)
 

Static Public Member Functions

static bool getList (RefPointer< SharedVars > &dest, const String &name)
 
- Static Public Member Functions inherited from Mutex
static int count ()
 
static int locks ()
 
static bool efficientTimedLock ()
 
- Static Public Member Functions inherited from Lockable
static void wait (unsigned long maxwait)
 
static unsigned long wait ()
 
static void startUsingNow ()
 
static void enableSafety (bool safe=true)
 
static bool safety ()
 
- Static Public Member Functions inherited from RefObject
static bool alive (const RefObject *obj)
 
static bool efficientIncDec ()
 
- Static Public Member Functions inherited from GenObject
static void * getObject (const String &name, const GenObject *obj)
 
static bool getObjCounting ()
 
static void setObjCounting (bool enable)
 
static NamedCountergetObjCounter (const String &name, bool create=true)
 
static ObjListgetObjCounters ()
 

Additional Inherited Members

- Protected Member Functions inherited from RefObject
virtual void zeroRefs ()
 
bool resurrect ()
 
virtual void destroyed ()
 

Detailed Description

Atomic access and operations to shared variables.

Class that implements atomic / locked access and operations to its shared variables

Constructor & Destructor Documentation

◆ SharedVars()

SharedVars ( const char * name = 0)
inline

Constructor

Parameters
nameOptional name

Member Function Documentation

◆ add()

uint64_t add ( const String & name,
uint64_t val,
uint64_t wrap = 0 )

Atomically add a value to a variable as unsigned integer

Parameters
nameName of the variable
valValue to add
wrapValue to wrap around at, zero disables
Returns
Value of the variable before addition, zero if it was not defined or not numeric

◆ clear()

void clear ( const String & name)

Clear a variable

Parameters
nameName of the variable to clear

◆ clearAll()

void clearAll ( )

Clear all variables. Does nothing for Engine (global shared list)

◆ copy()

void copy ( NamedList & dest,
const String & prefix = String::empty(),
bool skipPrefix = true,
bool replace = false )
inline

Atomically copy parameters to destination

Parameters
destDestination list
prefixOptional prefix to match in parameter names
skipPrefixSkip over the prefix when building new parameter name
replaceSet to true to replace list parameter instead of adding a new one

References NamedList::copyParams(), and NamedList::copySubParams().

◆ create()

bool create ( const String & name,
const char * val = 0 )

Create and set a variable only if the variable is not already set

Parameters
nameName of the variable to set
valNew value to assign to a variable
Returns
True if a new variable was created

◆ dec()

uint64_t dec ( const String & name,
uint64_t wrap = 0 )

Atomically decrement a variable as unsigned integer

Parameters
nameName of the variable
wrapValue to wrap around at, zero disables (stucks at zero)
Returns
Value of the variable after decrement, zero if it was not defined or not numeric

◆ exists()

bool exists ( const String & name)

Check if a variable exists

Parameters
nameName of the variable
Returns
True if the variable exists

◆ get()

void get ( const String & name,
String & rval )

Get the string value of a variable

Parameters
nameName of the variable
rvalString to return the value into

◆ getList()

static bool getList ( RefPointer< SharedVars > & dest,
const String & name )
static

Retrieve a named list of SharedVars. Create it if not found

Parameters
destDestination to be filled with requested list
nameName of the list
Returns
True id destination is iset. The function will fail if name is empty

◆ inc()

uint64_t inc ( const String & name,
uint64_t wrap = 0 )

Atomically increment a variable as unsigned integer

Parameters
nameName of the variable
wrapValue to wrap around at, zero disables
Returns
Value of the variable before increment, zero if it was not defined or not numeric

◆ set()

void set ( const String & name,
const char * val )

Set the string value of a variable

Parameters
nameName of the variable to set
valNew value to assign to a variable

◆ sub()

uint64_t sub ( const String & name,
uint64_t val,
uint64_t wrap = 0 )

Atomically substract a value from a variable as unsigned integer

Parameters
nameName of the variable
valValue to substract
wrapValue to wrap around at, zero disables
Returns
Value of the variable after substraction, zero if it was not defined or not numeric

◆ toString()

virtual const String & toString ( ) const
inlinevirtual

Retrieve list name

Returns
List name

Reimplemented from GenObject.


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