///|/ Copyright (c) Prusa Research 2023 Tomáš Mészáros @tamasmeszaros ///|/ ///|/ PrusaSlicer is released under the terms of the AGPLv3 or higher ///|/ #ifndef DATASTORETRAITS_HPP #define DATASTORETRAITS_HPP #include #include "libslic3r/libslic3r.h" namespace Slic3r { namespace arr2 { // Some items can be containers of arbitrary data stored under string keys. template struct DataStoreTraits_ { static constexpr bool Implemented = false; template static const T *get(const ArrItem &, const std::string &key) { return nullptr; } // Same as above just not const. template static T *get(ArrItem &, const std::string &key) { return nullptr; } static bool has_key(const ArrItem &itm, const std::string &key) { return false; } }; template struct WritableDataStoreTraits_ { static constexpr bool Implemented = false; template static void set(ArrItem &, const std::string &key, T &&data) { } }; template using DataStoreTraits = DataStoreTraits_>; template constexpr bool IsDataStore = DataStoreTraits>::Implemented; template using DataStoreOnly = std::enable_if_t, TT>; template const T *get_data(const ArrItem &itm, const std::string &key) { return DataStoreTraits::template get(itm, key); } template bool has_key(const ArrItem &itm, const std::string &key) { return DataStoreTraits::has_key(itm, key); } template T *get_data(ArrItem &itm, const std::string &key) { return DataStoreTraits::template get(itm, key); } template using WritableDataStoreTraits = WritableDataStoreTraits_>; template constexpr bool IsWritableDataStore = WritableDataStoreTraits>::Implemented; template using WritableDataStoreOnly = std::enable_if_t, TT>; template void set_data(ArrItem &itm, const std::string &key, T &&data) { WritableDataStoreTraits::template set(itm, key, std::forward(data)); } template constexpr bool IsReadWritableDataStore = IsDataStore && IsWritableDataStore; template using ReadWritableDataStoreOnly = std::enable_if_t, TT>; }} // namespace Slic3r::arr2 #endif // DATASTORETRAITS_HPP