Inviwo 0.9.12-pre
Inviwo documentation
Loading...
Searching...
No Matches
inviwo::Deserializer Class Reference
+ Inheritance diagram for inviwo::Deserializer:

Public Types

enum class  Result { NoChange , Modified , NotFound }
 
using ExceptionHandler = std::function<void(ExceptionContext)>
 
- Public Types inherited from inviwo::SerializeBase
using allocator_type = std::pmr::polymorphic_allocator<std::byte>
 

Public Member Functions

 Deserializer (const std::filesystem::path &fileName, std::string_view rootElement=SerializeConstants::InviwoWorkspace, allocator_type alloc={})
 Deserialize content from a file.
 
 Deserializer (std::istream &stream, const std::filesystem::path &refPath, std::string_view rootElement=SerializeConstants::InviwoWorkspace, allocator_type alloc={})
 Deserialize content from a stream.
 
 Deserializer (const std::pmr::string &content, const std::filesystem::path &refPath, std::string_view rootElement=SerializeConstants::InviwoWorkspace, allocator_type alloc={})
 Deserialize content from a stream.
 
 Deserializer (const Deserializer &)=delete
 
 Deserializer (Deserializer &&)=default
 
Deserializeroperator= (const Deserializer &that)=delete
 
Deserializeroperator= (Deserializer &&that)=default
 
template<typename T , typename A >
void deserialize (std::string_view key, std::vector< T, A > &sVector, std::string_view itemKey="item")
 Deserialize a vector.
 
template<typename T , typename H , typename P , typename A >
void deserialize (std::string_view key, std::unordered_set< T, H, P, A > &sSet, std::string_view itemKey="item")
 
template<typename T >
void deserialize (std::string_view key, std::list< T > &sContainer, std::string_view itemKey="item")
 
template<typename T , size_t N>
void deserialize (std::string_view key, std::array< T, N > &sContainer, std::string_view itemKey="item")
 
template<std::regular T, typename A >
Result deserializeTrackChanges (std::string_view key, std::vector< T, A > &sVector, std::string_view itemKey="item")
 
template<typename DeserializeFunction >
void deserializeRange (std::string_view key, std::string_view itemKey, DeserializeFunction deserializeFunction)
 
template<typename K , typename V , typename C , typename A >
void deserialize (std::string_view key, std::map< K, V, C, A > &sMap, std::string_view itemKey="item", std::string_view comparisonAttribute=SerializeConstants::KeyAttribute)
 Deserialize a map.
 
template<typename K , typename V , typename H , typename C , typename A >
void deserialize (std::string_view key, std::unordered_map< K, V, H, C, A > &map, std::string_view itemKey="item", std::string_view comparisonAttribute=SerializeConstants::KeyAttribute)
 
template<typename C , typename T = typename C::value_type, typename... Funcs>
requires requires(T& t, size_t i, std::string_view s, deserializer::IndexFunctions<Funcs...> f) { { std::invoke(f.makeNew) } -> std::same_as<T>; { std::invoke(f.onNew, t, i) }; { std::invoke(f.onRemove, t) }; }
void deserialize (std::string_view key, C &container, std::string_view itemKey, deserializer::IndexFunctions< Funcs... > f)
 
template<typename C , typename T = typename C::value_type, typename... Funcs>
requires requires(T& t, size_t i, std::string_view s, deserializer::IdentifierFunctions<Funcs...> f) { { std::invoke(f.getID, t) } -> std::same_as<std::string_view>; { std::invoke(f.makeNew) } -> std::same_as<T>; { std::invoke(f.filter, s, i) } -> std::same_as<bool>; { std::invoke(f.onNew, t, i) }; { std::invoke(f.onRemove, s) }; { std::invoke(f.onMove, t, i) }; }
void deserialize (std::string_view key, C &container, std::string_view itemKey, deserializer::IdentifierFunctions< Funcs... > f)
 
template<typename C , typename K = typename C::key_type, typename T = typename C::mapped_type, typename... Funcs>
requires requires(const K& k, T& t, size_t i, std::string_view s, deserializer::MapFunctions<Funcs...> f) { { std::invoke(f.idTransform, s) } -> std::same_as<K>; { std::invoke(f.makeNew) } -> std::same_as<T>; { std::invoke(f.filter, k) } -> std::same_as<bool>; { std::invoke(f.onNew, k, t) }; { std::invoke(f.onRemove, k) }; }
void deserialize (std::string_view key, C &container, std::string_view itemKey, deserializer::MapFunctions< Funcs... > f)
 
void deserialize (std::string_view key, signed char &data, const SerializationTarget &target=SerializationTarget::Node)
 
void deserialize (std::string_view key, char &data, const SerializationTarget &target=SerializationTarget::Node)
 
void deserialize (std::string_view key, unsigned char &data, const SerializationTarget &target=SerializationTarget::Node)
 
template<typename T , typename std::enable_if< std::is_integral< T >::value||util::is_floating_point< T >::value||util::is_string< T >::value, int >::type = 0>
void deserialize (std::string_view key, T &data, const SerializationTarget &target=SerializationTarget::Node)
 
template<typename T , typename std::enable_if< std::is_enum< T >::value, int >::type = 0>
void deserialize (std::string_view key, T &data, const SerializationTarget &target=SerializationTarget::Node)
 
template<typename T >
void deserialize (std::string_view key, flags::flags< T > &data, const SerializationTarget &target=SerializationTarget::Node)
 
template<typename Vec , typename std::enable_if< util::rank< Vec >::value==1, int >::type = 0>
void deserialize (std::string_view key, Vec &data)
 
template<typename Mat , typename std::enable_if< util::rank< Mat >::value==2, int >::type = 0>
void deserialize (std::string_view key, Mat &data)
 
template<size_t N>
void deserialize (std::string_view key, std::bitset< N > &bits)
 
void deserialize (std::string_view key, std::filesystem::path &path, const SerializationTarget &target=SerializationTarget::Node)
 
void deserialize (std::string_view key, Serializable &sObj)
 Deserialize any Serializable object.
 
template<class Base , class T >
void deserializeAs (std::string_view key, T *&data)
 
template<class T >
void deserialize (std::string_view key, std::unique_ptr< T > &data)
 
template<class T >
void deserialize (std::string_view key, std::shared_ptr< T > &data)
 
template<class Base , class T >
void deserializeAs (std::string_view key, std::unique_ptr< T > &data)
 
template<class T >
requires requires(T& t, Deserializer& d) { { t.deserialize(d) }; }
void deserialize (std::string_view key, T &sObj)
 
std::optional< std::string_view > attribute (std::string_view key) const
 
std::optional< std::string_view > attribute (std::string_view child, std::string_view key) const
 
bool hasElement (std::string_view key) const
 
void setExceptionHandler (ExceptionHandler handler)
 
void handleError (const ExceptionContext &context)
 
void convertVersion (VersionConverter *converter)
 
void registerFactory (FactoryBase *factory)
 
int getVersion () const
 
- Public Member Functions inherited from inviwo::SerializeBase
 SerializeBase (const std::filesystem::path &fileName, allocator_type alloc={})
 Base class for Serializer and Deserializer.
 
 SerializeBase (const SerializeBase &rhs)=delete
 
 SerializeBase (SerializeBase &&rhs) noexcept
 
SerializeBaseoperator= (const SerializeBase &)=delete
 
SerializeBaseoperator= (SerializeBase &&) noexcept
 
const std::filesystem::path & getFileName () const
 Gets the workspace file name.
 
const std::filesystem::path & getFileDir () const
 Gets the workspace file directory.
 
allocator_type getAllocator () const
 
- Public Member Functions inherited from inviwo::LogFilter
 LogFilter (Logger *logger=LogCentral::getPtr())
 
 LogFilter (Logger *logger, LogVerbosity verbosity)
 
 LogFilter (const LogFilter &)=default
 
 LogFilter (LogFilter &&) noexcept=default
 
LogFilteroperator= (const LogFilter &)=default
 
LogFilteroperator= (LogFilter &&) noexcept=default
 
void setVerbosity (LogVerbosity verbosity)
 
LogVerbosity getVerbosity ()
 
void setLogger (Logger *logger)
 
LoggergetLogger () const
 
virtual void log (std::string_view logSource, LogLevel level, LogAudience audience, std::string_view file, std::string_view function, int line, std::string_view msg) override
 
virtual void logProcessor (Processor *processor, LogLevel level, LogAudience audience, std::string_view msg, std::string_view file, std::string_view function, int line) override
 
virtual void logNetwork (LogLevel level, LogAudience audience, std::string_view msg, std::string_view file, std::string_view function, int line) override
 
- Public Member Functions inherited from inviwo::Logger
virtual void logAssertion (std::string_view file, std::string_view function, int line, std::string_view msg)
 

Friends

class NodeSwitch
 

Additional Inherited Members

- Static Public Member Functions inherited from inviwo::SerializeBase
template<typename U >
static constexpr bool isPrimitiveType ()
 Checks whether the given type is a primitive type.
 
- Protected Attributes inherited from inviwo::SerializeBase
std::filesystem::path fileName_
 
std::filesystem::path fileDir_
 
std::unique_ptr< TiXmlDocument > doc_
 
TiXmlElement * rootElement_
 
bool retrieveChild_
 

Constructor & Destructor Documentation

◆ Deserializer() [1/3]

inviwo::Deserializer::Deserializer ( const std::filesystem::path & fileName,
std::string_view rootElement = SerializeConstants::InviwoWorkspace,
allocator_type alloc = {} )
explicit

Deserialize content from a file.

Parameters
fileNamepath to file that is to be deserialized.

◆ Deserializer() [2/3]

inviwo::Deserializer::Deserializer ( std::istream & stream,
const std::filesystem::path & refPath,
std::string_view rootElement = SerializeConstants::InviwoWorkspace,
allocator_type alloc = {} )

Deserialize content from a stream.

Parameters
streamStream with content that is to be deserialized.
refPathUsed to calculate paths relative to the stream source if any.

◆ Deserializer() [3/3]

inviwo::Deserializer::Deserializer ( const std::pmr::string & content,
const std::filesystem::path & refPath,
std::string_view rootElement = SerializeConstants::InviwoWorkspace,
allocator_type alloc = {} )

Deserialize content from a stream.

Parameters
contentString with content that is to be deserialized.
refPathUsed to calculate paths relative to the stream source if any.

Member Function Documentation

◆ deserialize() [1/3]

template<typename C , typename T , typename... Funcs>
requires requires(T& t, size_t i, std::string_view s, deserializer::IndexFunctions<Funcs...> f) { { std::invoke(f.makeNew) } -> std::same_as<T>; { std::invoke(f.onNew, t, i) }; { std::invoke(f.onRemove, t) }; }
void inviwo::Deserializer::deserialize ( std::string_view key,
C & container,
std::string_view itemKey,
deserializer::IndexFunctions< Funcs... > f )

For more advanced deserialization. Useful when one has to call observer notifications. Example usage, serialize as usual

s.serialize("TFPrimitives", values_, "point");

Then deserialize with notifications:

d.deserialize(("TFPrimitives", values_ "point", deserializer::IndexFunctions{
.makeNew = []() { return std::unique_ptr<TFPrimitive>{}; },
.onNew = [&](std::unique_ptr<TFPrimitiveSet>& primitive) {
notifyControlPointAdded(primitive.get());
},
.onRemove = [&](std::unique_ptr<TFPrimitiveSet>& primitive) {
notifyControlPointRemoved(primitive.get());
}});
Definition deserializer.h:97

◆ deserialize() [2/3]

template<typename K , typename V , typename C , typename A >
void inviwo::Deserializer::deserialize ( std::string_view key,
std::map< K, V, C, A > & sMap,
std::string_view itemKey = "item",
std::string_view comparisonAttribute = SerializeConstants::KeyAttribute )

Deserialize a map.

Deserialize a map, which can have keys of type K, values of type V* (pointers) and compare function C ( optional if K primitive type, i.e., std::string, int, etc.,) eg., std::map<std::string, Property*>

eg. xml tree

<Properties>
<Property identifier="enableMIP" displayName="MIP">
<value content="0" />
</Property>
<Property identifier="enableShading" displayName="Shading">
<value content="0" />
</Property>
<Properties>

In the above xml tree,

key = "Properties" itemKey = "Property" param comparisonAttribute = "identifier"

Parameters
keyMap key or parent node of itemKey.
sMapmap to be deserialized - source / input map.
itemKeymap item key of children nodes.
comparisonAttributeforced comparison attribute.

◆ deserialize() [3/3]

template<typename T , typename A >
void inviwo::Deserializer::deserialize ( std::string_view key,
std::vector< T, A > & sVector,
std::string_view itemKey = "item" )

Deserialize a vector.

Deserialize the vector that has pre-allocated objects of type T or allocated by deserializer. A vector is identified by key and vector items are identified by itemKey

eg. xml tree with key=Properties and itemKey=Property

<Properties>
     <Property identifier="enableMIP" displayName="MIP">
         <value content="0" />
     </Property>
     <Property identifier="enableShading" displayName="Shading">
         <value content="0" />
     </Property>
<Properties>
Parameters
keyvector key.
sVectorvector to be deserialized.
itemKeyvector item key

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