diff --git a/MeshLib/Properties-impl.h b/MeshLib/Properties-impl.h index c7ec37d1dc4dfa9a2f21c441af878cbd3277a19e..c83073c67c9827a2035d4ba3469ac8f37294d35b 100644 --- a/MeshLib/Properties-impl.h +++ b/MeshLib/Properties-impl.h @@ -10,10 +10,9 @@ * */ - template <typename T> -boost::optional<PropertyVector<T> &> -Properties::createNewPropertyVector(std::string const& name, +PropertyVector<T>* Properties::createNewPropertyVector( + std::string const& name, MeshItemType mesh_item_type, std::size_t n_components) { @@ -23,7 +22,7 @@ Properties::createNewPropertyVector(std::string const& name, if (it != _properties.end()) { ERR("A property of the name \"%s\" is already assigned to the mesh.", name.c_str()); - return boost::optional<PropertyVector<T> &>(); + return nullptr; } auto entry_info( _properties.insert( @@ -32,15 +31,12 @@ Properties::createNewPropertyVector(std::string const& name, ) ) ); - return boost::optional<PropertyVector<T> &>(*( - static_cast<PropertyVector<T>*>((entry_info.first)->second) - ) - ); + return static_cast<PropertyVector<T>*>((entry_info.first)->second); } template <typename T> -boost::optional<PropertyVector<T> &> -Properties::createNewPropertyVector(std::string const& name, +PropertyVector<T>* Properties::createNewPropertyVector( + std::string const& name, std::size_t n_prop_groups, std::vector<std::size_t> const& item2group_mapping, MeshItemType mesh_item_type, @@ -54,7 +50,7 @@ Properties::createNewPropertyVector(std::string const& name, if (it != _properties.end()) { ERR("A property of the name \"%s\" already assigned to the mesh.", name.c_str()); - return boost::optional<PropertyVector<T> &>(); + return nullptr; } // check entries of item2group_mapping for consistence @@ -62,7 +58,7 @@ Properties::createNewPropertyVector(std::string const& name, std::size_t const group_id (item2group_mapping[k]); if (group_id >= n_prop_groups) { ERR("The mapping to property %d for item %d is not in the correct range [0,%d).", group_id, k, n_prop_groups); - return boost::optional<PropertyVector<T> &>(); + return nullptr; } } @@ -75,47 +71,37 @@ Properties::createNewPropertyVector(std::string const& name, ) ) ); - return boost::optional<PropertyVector<T> &> - (*(static_cast<PropertyVector<T>*>((entry_info.first)->second))); + return static_cast<PropertyVector<T>*>((entry_info.first)->second); } template <typename T> -boost::optional<PropertyVector<T> const&> -Properties::getPropertyVector(std::string const& name) const +PropertyVector<T> const* Properties::getPropertyVector( + std::string const& name) const { std::map<std::string, PropertyVectorBase*>::const_iterator it( - _properties.find(name) - ); - if (it == _properties.end()) { + _properties.find(name)); + if (it == _properties.end()) + { ERR("A property with the specified name \"%s\" is not available.", name.c_str()); - return boost::optional<PropertyVector<T> const&>(); + return nullptr; } - PropertyVector<T> const* t=dynamic_cast<PropertyVector<T>const*>(it->second); - if (!t) { - return boost::optional<PropertyVector<T> const&>(); - } - return *t; + return dynamic_cast<PropertyVector<T> const*>(it->second); } template <typename T> -boost::optional<PropertyVector<T>&> -Properties::getPropertyVector(std::string const& name) +PropertyVector<T>* Properties::getPropertyVector(std::string const& name) { std::map<std::string, PropertyVectorBase*>::iterator it( - _properties.find(name) - ); - if (it == _properties.end()) { + _properties.find(name)); + if (it == _properties.end()) + { ERR("A property with the specified name \"%s\" is not available.", name.c_str()); - return boost::optional<PropertyVector<T>&>(); + return nullptr; } - PropertyVector<T> *t=dynamic_cast<PropertyVector<T>*>(it->second); - if (!t) { - return boost::optional<PropertyVector<T> &>(); - } - return *t; + return dynamic_cast<PropertyVector<T>*>(it->second); } diff --git a/MeshLib/Properties.h b/MeshLib/Properties.h index 8c9f370a3d26fe49011d0cf5fbda2e92ea2a3ada..1dacf08e7d5799e2e89e0873f31c305cff348740 100644 --- a/MeshLib/Properties.h +++ b/MeshLib/Properties.h @@ -18,8 +18,6 @@ #include <string> #include <map> -#include <boost/optional.hpp> - #include <logog/include/logog.hpp> #include "Location.h" @@ -42,28 +40,25 @@ class Properties public: /// Method creates a PropertyVector if a PropertyVector with the same name /// and the same type T was not already created before. In case there exists - /// already such a PropertyVector the returned boost::optional holds an - /// invalid/unusable PropertyVector. - /// There are two versions of this method. This method is used - /// when every mesh item at hand has its own property value, i.e. \f$n\f$ - /// mesh item and \f$n\f$ different property values. + /// already such a PropertyVector a nullptr is returned. + /// There are two versions of this method. This method is used when every + /// mesh item at hand has its own property value, i.e. \f$n\f$ mesh item and + /// \f$n\f$ different property values. /// The user has to ensure the correct usage of the vector later on. /// @tparam T type of the property value /// @param name the name of the property /// @param mesh_item_type for instance node or element assigned properties /// @param n_components number of components for each tuple - /// @return On success a reference to a PropertyVector packed into a - /// boost::optional else an empty boost::optional. + /// @return A pointer to a PropertyVector on success and a nullptr + /// otherwise. template <typename T> - boost::optional<PropertyVector<T> &> - createNewPropertyVector(std::string const& name, - MeshItemType mesh_item_type, - std::size_t n_components = 1); + PropertyVector<T>* createNewPropertyVector(std::string const& name, + MeshItemType mesh_item_type, + std::size_t n_components = 1); /// Method creates a PropertyVector if a PropertyVector with the same name /// and the same type T was not already created before. In case there exists - /// already such a PropertyVector the returned boost::optional holds an - /// invalid/unusable PropertyVector. + /// already such a PropertyVector a nullptr is returned. /// This method is used if only a small number of distinct property values /// in a property exist (e.g. mapping property groups to elements). /// In this case a mapping between mesh items and properties (stored @@ -75,25 +70,25 @@ public: /// group /// @param mesh_item_type for instance node or element assigned properties /// @param n_components number of components for each tuple - /// @return On success a reference to a PropertyVector packed into a - /// boost::optional else an empty boost::optional. + /// @return A pointer to a PropertyVector on success and a nullptr + /// otherwise. template <typename T> - boost::optional<PropertyVector<T> &> - createNewPropertyVector(std::string const& name, + PropertyVector<T>* createNewPropertyVector( + std::string const& name, std::size_t n_prop_groups, std::vector<std::size_t> const& item2group_mapping, MeshItemType mesh_item_type, std::size_t n_components = 1); - /// Method to get a vector of property values. + /// Returns a property vector with given \c name or nullptr if no such + /// property vector exists. template <typename T> - boost::optional<PropertyVector<T> const&> - getPropertyVector(std::string const& name) const; + PropertyVector<T> const* getPropertyVector(std::string const& name) const; - /// Method to get a vector of property values. + /// Returns a property vector with given \c name or nullptr if no such + /// property vector exists. template <typename T> - boost::optional<PropertyVector<T>&> - getPropertyVector(std::string const& name); + PropertyVector<T>* getPropertyVector(std::string const& name); void removePropertyVector(std::string const& name);