Commit 9744578e authored by Martin Heistermann's avatar Martin Heistermann

experimental: get_property and create_property

parent 0d447e1d
Pipeline #11806 passed with stage
in 3 minutes and 48 seconds
......@@ -41,12 +41,17 @@
#include <vector>
#include <type_traits>
#include "../System/Compiler.hh"
#include "../Config/Export.hh"
#include "OpenVolumeMeshProperty.hh"
#include "PropertyHandles.hh"
#include "TypeName.hh"
#include "ForwardDeclarations.hh"
#if OVM_CXX_17
#include <optional>
#endif
namespace OpenVolumeMesh {
// Forward declarations
......@@ -141,6 +146,18 @@ public:
template<typename T, typename EntityTag>
PropertyTT<T, EntityTag> request_property(const std::string& _name = std::string(), const T _def = T());
#if OVM_CXX_17
/** Create new property: if the property already exists, return no value.
*/
template<typename T, typename EntityTag>
std::optional<PropertyTT<T, EntityTag>> create_property(const std::string& _name = std::string(), const T _def = T());
/** Get existing property: if the property does not exist, return no value.
*/
template<typename T, typename EntityTag>
std::optional<PropertyTT<T, EntityTag>> get_property(const std::string& _name = std::string());
#endif
template<class T> VertexPropertyT<T> request_vertex_property(const std::string& _name = std::string(), const T _def = T());
template<class T> EdgePropertyT<T> request_edge_property(const std::string& _name = std::string(), const T _def = T());
......
......@@ -123,6 +123,28 @@ PropertyTT<T, EntityTag> ResourceManager::request_property(const std::string& _n
return internal_create_property<T, EntityTag>(_name, _def);
}
#if OVM_CXX_17
template<typename T, typename EntityTag>
std::optional<PropertyTT<T, EntityTag>>
ResourceManager::create_property(const std::string& _name, const T _def)
{
auto *prop = internal_find_property<T, EntityTag>(_name);
if (prop)
return {};
return {*internal_create_property<T, EntityTag>(_name, _def)};
}
template<typename T, typename EntityTag>
std::optional<PropertyTT<T, EntityTag>>
ResourceManager::get_property(const std::string& _name)
{
auto *prop = internal_find_property<T, EntityTag>(_name);
if (prop)
return {*prop};
return {};
}
#endif
template<typename T, class EntityTag>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment