Inviwo 0.9.12-pre
Inviwo documentation
|
The base class for all data objects. More...
#include <data.h>
Public Types | |
using | self = Self |
using | repr = Repr |
Public Member Functions | |
virtual Data< Self, Repr > * | clone () const =0 |
template<typename T > | |
const T * | getRepresentation () const |
template<typename T > | |
std::shared_ptr< const T > | getRepresentationShared () const |
template<typename T > | |
T * | getEditableRepresentation () |
template<typename T > | |
bool | hasRepresentation () const |
bool | hasRepresentations () const |
void | addRepresentation (std::shared_ptr< Repr > representation) |
void | removeRepresentation (const Repr *representation) |
void | removeOtherRepresentations (const Repr *representation) |
void | clearRepresentations () |
void | invalidateAllOther (const Repr *repr) |
void | updateResource (const ResourceMeta &meta) const |
Protected Member Functions | |
Data (const Data< Self, Repr > &rhs) | |
Data (Data< Self, Repr > &&rhs)=default | |
Data< Self, Repr > & | operator= (const Data< Self, Repr > &that) |
Data< Self, Repr > & | operator= (Data< Self, Repr > &&that)=default |
template<typename F , typename T > | |
decltype(auto) | getLastOr (F &&f, T &&fallback) const |
template<typename F , typename T > | |
void | setLastAndInvalidateOther (F &&f, T &&value) |
The base class for all data objects.
Data is a handle class and, by it self does not have any data, it only stores metadata, and a list of representations. The representations is were the actually data is stored. A Volume can have a set of different representations, for example a VolumeRAM representation and a VolumeGL representation. At any time at least one of the representations should be in a valid state. When ever we want to access the data of a volume we will ask the volume for a representation of some kind, and the handle is then responsible to try and provide that to us. If the requested representation is valid the handle can just return the that representation. If not, it will have to find a valid representation and try to either create the representation we wanted from the valid representation, if there was no representation of the kind we asked for around. Or if there is a invalid representation around, update that representation with the valid representation.
Call getRepresentation to retrieve the data:
Requirements:
1 and 2 are needed to be a vaild member type of std::vector. 3 is needed for the factory pattern, 3 should be implemented using 1.
void inviwo::Data< Self, Repr >::addRepresentation | ( | std::shared_ptr< Repr > | representation | ) |
Add the representation and set it as last valid. The owner of the representation will be set to this object.
representation | The representation to add |
void inviwo::Data< Self, Repr >::clearRepresentations | ( | ) |
Delete all representations.
T * inviwo::Data< Self, Repr >::getEditableRepresentation | ( | ) |
Get an editable representation. This will invalidate all other representations. They will now have to be updated from this one before use.
const T * inviwo::Data< Self, Repr >::getRepresentation | ( | ) | const |
Get a representation of type T. If there already is a valid representation of type T, just return it, if it's invalid use the last valid representation to update it so it will be valid. It there is no representation of type T, create it from the last valid representation. If there are no representations create a default representation and from that create a representation of type T.
bool inviwo::Data< Self, Repr >::hasRepresentation | ( | ) | const |
Check if a specific representation type exists. Example:
bool inviwo::Data< Self, Repr >::hasRepresentations | ( | ) | const |
Check if the Data object has any representation.
void inviwo::Data< Self, Repr >::invalidateAllOther | ( | const Repr * | repr | ) |
This call will make all other representations invalid. You need to call this function if you are modifying a representation directly without calling getEditableRepresentation. getEditableRepresentation will automatically invalidate all other representations.
void inviwo::Data< Self, Repr >::removeOtherRepresentations | ( | const Repr * | representation | ) |
Remove all other representations. This will delete all representations except the one passed in.
representation | The representation to keep |
void inviwo::Data< Self, Repr >::removeRepresentation | ( | const Repr * | representation | ) |
Remove representation from data object. This will delete the representation, thus rendering the representation pointer invalid.
representation | The representation to remove |