TagName.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <string>
8 #include <type_traits>
9 
10 #include "DataStructures/DataBox/TagTraits.hpp"
11 #include "Utilities/PrettyType.hpp"
12 #include "Utilities/Requires.hpp"
13 #include "Utilities/TypeTraits.hpp"
14 #include "Utilities/TypeTraits/CreateHasTypeAlias.hpp"
15 #include "Utilities/TypeTraits/CreateIsCallable.hpp"
16 
17 /// \cond
18 namespace db {
19 struct PrefixTag;
20 } // namespace db
21 /// \endcond
22 
23 namespace db {
24 
25 namespace detail {
27 CREATE_IS_CALLABLE_V(name)
29 CREATE_HAS_TYPE_ALIAS_V(base)
30 } // namespace detail
31 
32 /*!
33  * \ingroup DataBoxGroup
34  * \brief Get the name of a DataBoxTag, including prefixes
35  *
36  * \details
37  * Given a DataBoxTag returns the name of the DataBoxTag as a std::string. If
38  * the DataBoxTag is also a PrefixTag then the prefix is added.
39  *
40  * \tparam Tag the DataBoxTag whose name to get
41  * \return string holding the DataBoxTag's name
42  */
43 template <typename Tag>
44 std::string tag_name() noexcept {
45  if constexpr (detail::is_name_callable_v<Tag>) {
46  return Tag::name();
47  } else if constexpr (db::is_compute_tag_v<Tag>) {
48  static_assert(detail::has_base_v<Tag>,
49  "Compute tags must have a name function or a base alias");
50  return tag_name<typename Tag::base>();
51  } else if constexpr (std::is_base_of_v<db::PrefixTag, Tag>) {
52  return pretty_type::short_name<Tag>() + "(" +
53  tag_name<typename Tag::tag>() + ")";
54  } else {
55  return pretty_type::short_name<Tag>();
56  }
57 }
58 } // namespace db
std::string
PrettyType.hpp
db::tag_name
std::string tag_name() noexcept
Get the name of a DataBoxTag, including prefixes.
Definition: TagName.hpp:44
CREATE_HAS_TYPE_ALIAS
#define CREATE_HAS_TYPE_ALIAS(ALIAS_NAME)
Generate a type trait to check if a class has a type alias with a particular name,...
Definition: CreateHasTypeAlias.hpp:27
cstddef
Requires.hpp
type_traits
db
Namespace for DataBox related things.
Definition: DataBox.hpp:42
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