TagName.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <string>
7 #include <type_traits>
8 
9 #include "DataStructures/DataBox/TagTraits.hpp"
10 #include "Utilities/PrettyType.hpp"
11 #include "Utilities/TypeTraits/CreateIsCallable.hpp"
12 
13 /// \cond
14 namespace db {
15 struct PrefixTag;
16 } // namespace db
17 /// \endcond
18 
19 namespace db {
20 
21 namespace detail {
23 CREATE_IS_CALLABLE_V(name)
24 } // namespace detail
25 
26 /*!
27  * \ingroup DataBoxGroup
28  * \brief Get the name of a DataBox tag, including prefixes
29  *
30  * \details
31  * Given a DataBox tag returns the name of the DataBox tag as a std::string. If
32  * the DataBox tag is also a PrefixTag then the prefix is added.
33  *
34  * \tparam Tag the DataBox tag whose name to get
35  * \return string holding the DataBox tag's name
36  */
37 template <typename Tag>
38 std::string tag_name() noexcept {
39  if constexpr (detail::is_name_callable_v<Tag>) {
40  return Tag::name();
41  } else if constexpr (db::is_immutable_item_tag_v<Tag>) {
42  return tag_name<typename Tag::base>();
43  } else if constexpr (std::is_base_of_v<db::PrefixTag, Tag>) {
44  return pretty_type::short_name<Tag>() + "(" +
45  tag_name<typename Tag::tag>() + ")";
46  } else {
47  return pretty_type::short_name<Tag>();
48  }
49 }
50 } // namespace db
std::string
PrettyType.hpp
db::tag_name
std::string tag_name() noexcept
Get the name of a DataBox tag, including prefixes.
Definition: TagName.hpp:38
type_traits
db
Namespace for DataBox related things.
Definition: DataBox.hpp:44
CREATE_IS_CALLABLE
#define CREATE_IS_CALLABLE(METHOD_NAME)
Generate a type trait to check if a class has a member function that can be invoked with arguments of...
Definition: CreateIsCallable.hpp:30
string