Image Component Library (ICL)
Classes | Public Member Functions | Static Public Member Functions | Static Private Member Functions | List of all members
icl::qt::DataStore Class Reference

Extension of the associative container MultiTypeMap. More...

#include <DataStore.h>

Inheritance diagram for icl::qt::DataStore:
icl::utils::MultiTypeMap

Classes

struct  Assign
 internally used assignment structure More...
 
class  Data
 Arbitrary Data encapsulation type. More...
 
struct  KeyNotFoundException
 Internal Exception type thrown if operator[] is given an unknown index string. More...
 
struct  UnassignableTypesException
 Internal Exception type thrown if Data::operator= is called for incompatible values. More...
 

Public Member Functions

Data operator[] (const std::string &key)
 Allows to assign new values to a entry with given key (NEW) More...
 
template<class T >
std::vector< T > collect (const std::vector< std::string > &keys)
 convenience function that allows collecting data from different source entries More...
 
- Public Member Functions inherited from icl::utils::MultiTypeMap
 MultiTypeMap ()
 Default constructor (create a new MultiTypeMap object) More...
 
 ~MultiTypeMap ()
 Destructor (deletes all remaining data) More...
 
template<class T >
T * allocArray (const std::string &id, unsigned int n)
 Allocates a new memory block (new T[n]) for the given id string. More...
 
template<class T >
T & allocValue (const std::string &id, const T &val=T())
 Allocates a new memory elements (new T(val)) for the given id string. More...
 
template<class T >
void release (const std::string &id)
 release the data element that is associated with the given id More...
 
template<class T >
T * getArray (const std::string &id, int *lenDst=0)
 get a T* that is associated with the given id More...
 
template<class T >
T & getValue (const std::string &id, bool checkType=true)
 get a T reference that is associated with the given id More...
 
template<class T >
const T & getValue (const std::string &id, bool checkType=true) const
 
const std::string & getType (const std::string &id) const
 returns the RTTI string type identifier, for the entry associated with id More...
 
template<class T >
bool checkType (const std::string &id) const
 checks if the type-id associated with the template parameter T is compatible to the entry for id More...
 
bool isArray (const std::string &id) const
 returns whether an entry is an array or a value More...
 
bool contains (const std::string &id) const
 returns whether a given value is already set More...
 
void lock () const
 
void unlock () const
 internally unlocks the data store More...
 
void listContents () const
 shows a list of currently contained data More...
 
void clear ()
 
std::vector< EntrygetEntryList () const
 returns a list of all entries More...
 

Static Public Member Functions

static void list_possible_assignments (const std::string &srcType, const std::string &dstType)
 gives a list of possible assignemts for optinally given src and dst Type More...
 
template<class SRC , class DST >
static void register_assignment_rule (const std::string &srcTypeName, const std::string &dstTypeName, utils::Function< void, const SRC &, DST & > assign)
 registers a new assignment rule to the DataStore class More...
 
template<class SRC , class DST >
static void register_trivial_assignment_rule (const std::string &srcTypeName, const std::string &dstTypeName)
 registers trivial assignment rule to the DataStore class More...
 
- Static Public Member Functions inherited from icl::utils::MultiTypeMap
template<class T >
static const std::string & get_type_name ()
 internally used wrapper function for RTTI More...
 

Static Private Member Functions

static void register_assignment_rule (Assign *assign)
 internal assign method More...
 

Additional Inherited Members

- Protected Types inherited from icl::utils::MultiTypeMap
typedef std::map< std::string, DataArrayDataMap
 internal definition More...
 
typedef SmartPtr< DataMapSmartDataMapPtr
 internal definition More...
 
typedef SmartPtr< MutexSmartMutexPtr
 internal definition More...
 
- Protected Member Functions inherited from icl::utils::MultiTypeMap
bool check_type_internal (const std::string &id, const std::string &typestr) const
 
- Protected Attributes inherited from icl::utils::MultiTypeMap
SmartDataMapPtr m_oDataMapPtr
 Smart-Pointer to the underlying data (allows shallow copies) More...
 
SmartMutexPtr m_oMutexPtr
 mutex to handle syncronous calls More...
 

Detailed Description

Extension of the associative container MultiTypeMap.

Adds an index operator[string] for direct access to contained values

Member Function Documentation

◆ collect()

template<class T >
std::vector<T> icl::qt::DataStore::collect ( const std::vector< std::string > &  keys)
inline

convenience function that allows collecting data from different source entries

This function can e.g. be used to obtain data from an array of 'float' GUI components

◆ list_possible_assignments()

static void icl::qt::DataStore::list_possible_assignments ( const std::string &  srcType,
const std::string &  dstType 
)
static

gives a list of possible assignemts for optinally given src and dst Type

◆ operator[]()

Data icl::qt::DataStore::operator[] ( const std::string &  key)

Allows to assign new values to a entry with given key (NEW)

The returned Data-Element is a shallow Reference of a DataStore entry of internal type DataArray. Each entry is typed by C++'s RTTI, so, the function can determine if the assigned value is compatible to actual type of the data element. Internally a magic assignment system is used to determine whether two types can be assigned, and what to do if. Basically one can say, type assignments line T = T are of course allowed as well as type assignments A = B, if A and B are C++ built-in numerical type (int, float, etc.) Additionally a lot of GUIHandle types (contained by a GUI's DataStore) can be assigned (and updated, see void DataStore::Data::update()) with this mechanism

A detailed description of all allowed assigmnet must ba added here: TODO...

Here are some examples ...

DataStore x;
x.allocValue("hello",int(5));
x.allocValue("world",float(5));
x.allocValue("!",std::string("yes yes!"));
x["hello"] = "44"; // string to int
x["world"] = 4; // int to float
x["!"] = 44; // int to string
x["hello"] = 44; // int to int
x.allocValue("image",ImgHandle(...));
x["image"] = icl::create("parrot"); // ImgQ to ImageHandle
x.allocValue("sl",SliderHandle(...));
x["sl"] = 7; // sets slider value to 7
std::cout << "slider val is:" << x["sl"].as<int>() << std::endl;
x["sl"] = Range32s(3,9); // sets slider's Range ...

◆ register_assignment_rule() [1/2]

static void icl::qt::DataStore::register_assignment_rule ( Assign assign)
staticprivate

internal assign method

◆ register_assignment_rule() [2/2]

template<class SRC , class DST >
static void icl::qt::DataStore::register_assignment_rule ( const std::string &  srcTypeName,
const std::string &  dstTypeName,
utils::Function< void, const SRC &, DST & >  assign 
)
inlinestatic

registers a new assignment rule to the DataStore class

After the call, the two types can be assigned (for reading and writing DataStore entries)

◆ register_trivial_assignment_rule()

template<class SRC , class DST >
static void icl::qt::DataStore::register_trivial_assignment_rule ( const std::string &  srcTypeName,
const std::string &  dstTypeName 
)
inlinestatic

registers trivial assignment rule to the DataStore class

Trivial assignments are performed using dst = src


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