![]() |
ImFusion SDK 4.3
|
#include <AnatomyPlugin/include/ImFusion/AnatomyPlugin/KeyValueStore.h>
Template class for storing key/value pairs. More...
Inheritance diagram for KeyValueStore< StoredT >:Template class for storing key/value pairs.
For each value, additional attributes for visualisation are also stored. The template argument is the underlying "storage type" of this class, and is either a "raw" type T or a unique_ptr/shared_ptr/raw pointer for some type T. For pointer-like storage type, this class dereferences the argument in its interfaces, which means that nullptr values may not be stored! For vec3 stores, entries are also checked for NaN values.
keyValueStore["key"] = std::make_unique<T>(...) For technical reasons, for missing keys operator[] first creates an (emtpy, invalid) Entry, and then assigns to it. Until the assignment has taken place, this means that a nullptr/NaN has been stored at the entry, and the entry should not be used.This object emits signals when objects are created/removed/changed.
This class can be used to automatically keep world/image representations of objects synchronized. Here hat is meant is that the "world" representation of an object is the "image" representation transformed by some (rigid) matrix mat, i.e. conceptually world = mat*image. All objects are accessible in world coordinates, but for each object the relevant parts of the original image representation are also stored. The world representation can be kept synchronized when changes to mat are made, and likewise changes in the world representation must result in image being kept synchronized. For this, see the synchronizeWorld and synchronizeLocal functions. The latter is register on Data::signalMatrixChanged for the case that T derives from Data. For more details,
The copy constructor of this object has been deleted to avoid creation of accidental copies. To explicitly copy a KeyValueStore, first create a new KeyValueStore object, and then assign the result of clone to it.
Classes | |
| class | Entry |
Public Types | |
| using | T = typename like_pointer<StoredT>::type |
| This is T for std::unique_ptr<T>, std::shared_ptr<T> and T* and otherwise equal to StoredT. | |
| using | refT = std::conditional_t<std::is_base_of_v<Data, T>, T, const T> |
| Only allow const reference access for non-Data types. | |
Public Member Functions | |
| KeyValueStore (const mat4 &matrixToSynchronizeWith) | |
Constructor which keeps poses synchronized using matrixToSynchronizeWith. | |
| void | synchronizeWorld () |
| void | synchronizeLocal () |
| KeyValueStore (std::map< std::string, StoredT >) | |
| KeyValueStore< StoredT > & | operator= (KeyValueStore< StoredT > &&other) |
| void | clear () |
| Remove all entries in this key/value store. | |
| KeyValueStore< StoredT > | clone (const std::function< StoredT(const T &)> &cloneIndividual={}) const |
Use this function for creating copies of this object, the result can be (move) assigned to the target If an argument is given, this is applied to each stored object during cloning to "clone" T. | |
| Entry & | operator[] (const std::string &key) |
| Access an element by a key. The resulting object is an Entry object that can be assigned to, see the class documentation. | |
| const Entry & | operator[] (const std::string &key) const |
| Const access an element by a key. This assumes that the element exists. | |
| MapT::iterator | find (const std::string &key) |
| MapT::const_iterator | find (const std::string &key) const |
| StoredT | take (const std::string &key) |
| bool | has (const std::string &key) const |
| Check whether an element with the given key exists. | |
| bool | hasAll (const std::vector< std::string > &keys) const |
| Check whether all elements with the given keys exist. | |
| template<typename... Ts> | |
| bool | hasAll (Ts... args) const |
| Check whether all elements with the given keys exist. | |
| bool | hasAny (const std::vector< std::string > &keys) const |
| Check whether any elements with the given keys exist. | |
| template<typename... Ts> | |
| bool | hasAny (Ts... args) const |
| Check whether any elements with the given keys exist. | |
| const refT & | get (const std::string &key) const |
| Get a const reference value to item key. Assumes the item exists. | |
| refT & | get (const std::string &key) |
| Get a reference to item key. Assumes the item exists. | |
| template<typename U = StoredT, bool like_pointer = is_like_pointer> | |
| Entry * | set (const std::string &key, const U &other, std::enable_if_t<!like_pointer, void * >=nullptr) |
| Assign a value to the item key. | |
| template<bool like_pointer = is_like_pointer> | |
| Entry * | set (const std::string &key, StoredT value, std::enable_if_t< like_pointer, void * >=nullptr) |
| Assign a value to the item key. | |
| template<typename U> | |
| void | setAttribute (const std::string &key, const std::string attributeName, const U &value) |
| Set additional attributes (currently only used for visualisation) for a key/value pair. | |
| MapT::iterator | begin () |
| Iterator functions. | |
| MapT::const_iterator | begin () const |
| MapT::iterator | end () |
| MapT::const_iterator | end () const |
| MapT::const_iterator | cbegin () const |
| MapT::const_iterator | cend () const |
| size_t | size () const |
| Convenience functions. | |
| bool | empty () const |
| std::set< std::string > | keys () const |
Public Member Functions inherited from SignalReceiver | |
| SignalReceiver ()=default | |
| Default constructor. | |
| SignalReceiver (const SignalReceiver &other) | |
| Copy constructor, does not copy any existing signal connections from other. | |
| SignalReceiver & | operator= (SignalReceiver rhs) |
| Assignment operator, disconnects all existing connections, does not copy any existing signal connections from rhs. | |
| virtual | ~SignalReceiver () |
| Virtual destructor disconnects from all connected signals. | |
Static Public Member Functions | |
| static const T & | dereference (const StoredT &other) |
| Helper function that dereferences pointer-like types but not non-pointer-like types. | |
Static Public Attributes | |
| static constexpr bool | is_like_pointer = like_pointer<StoredT>::value |
Protected Types | |
| using | MapT = std::map<std::string, Entry> |
| Helper typedefs. | |
| Signal< const std::string &, Entry & > | signalKeyValueAdded |
| Signals. | |
| Signal< const std::string &, refT & > | signalKeyValueRemoved |
| This signal is emitted after a key/value pair has been removed. | |
| Signal< const std::string &, refT &, Entry & > | signalKeyValueChanged |
| This signal is emitted after a key/value pair has been changed. | |
Additional Inherited Members | |
Protected Member Functions inherited from NotCopyable | |
| NotCopyable (NotCopyable &&) noexcept=default | |
| NotCopyable & | operator= (NotCopyable &&) noexcept=default |
| NotCopyable (const NotCopyable &)=delete | |
| NotCopyable & | operator= (const NotCopyable &)=delete |
Protected Member Functions inherited from SignalReceiver | |
| void | disconnectAll () |
| Disconnects all existing connections. | |
| using refT = std::conditional_t<std::is_base_of_v<Data, T>, T, const T> |
Only allow const reference access for non-Data types.
We allow non-const access for Data types because here we can find out about changes that affect image coordinates using signalMatrixChanged.
|
explicit |
Constructor which keeps poses synchronized using matrixToSynchronizeWith.
This reference must remain valid during the lifetime of this object
| KeyValueStore< StoredT > clone | ( | const std::function< StoredT(const T &)> & | cloneIndividual = {} | ) | const |
Use this function for creating copies of this object, the result can be (move) assigned to the target If an argument is given, this is applied to each stored object during cloning to "clone" T.
If no argument is supplied, the copy constructor of T is used if this exists and is accessible Example: keyValueStore.clone([](const SharedImageSet &sis){return sis->clone();})
| KeyValueStore< StoredT >::Entry * set | ( | const std::string & | key, |
| const U & | other, | ||
| std::enable_if_t<!like_pointer, void * > | = nullptr ) |
Assign a value to the item key.
If the item doesn't exist, it will be created If the value is not valid (e.g. contains NaN values for vectors), the item will not be created, and any previous value for that key will be deleted.
| KeyValueStore< StoredT >::Entry * set | ( | const std::string & | key, |
| StoredT | value, | ||
| std::enable_if_t< like_pointer, void * > | = nullptr ) |
Assign a value to the item key.
If the item doesn't exist, it will be created If the value is not valid (e.g. is nullptr for pointers), the item will not be created, and any previous value for that key will be deleted.
| void setAttribute | ( | const std::string & | key, |
| const std::string | attributeName, | ||
| const U & | value ) |
Set additional attributes (currently only used for visualisation) for a key/value pair.
Currently supported is e.g. the "color" attribute. Internally, this uses ImFusion::Properties for serialization. Attributes can also read/written using the attributes() member of Iterator/ConstIterator.
| Signal<const std::string&, Entry&> signalKeyValueAdded |
Signals.
This signal is emitted after an element has been added
| Signal<const std::string&, refT&> signalKeyValueRemoved |
This signal is emitted after a key/value pair has been removed.
The parameter is the value of the object that has been removed. The object at this stage is no longer part of the key/value store, but may be considered in a valid state.
| Signal<const std::string&, refT&, Entry&> signalKeyValueChanged |
This signal is emitted after a key/value pair has been changed.
The first parameter is the old value, the second is the new value. Both objects are in a valid state when this signal is emitted.