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/CreateHasTypeAlias.hpp"
12 #include "Utilities/TypeTraits/CreateIsCallable.hpp"
13 
14 /// \cond
15 namespace db {
16 struct PrefixTag;
17 } // namespace db
18 /// \endcond
19 
20 namespace db {
21 
22 namespace detail {
27 } // namespace detail
28 
29 /*!
30  * \ingroup DataBoxGroup
31  * \brief Get the name of a DataBox tag, including prefixes
32  *
33  * \details
34  * Given a DataBox tag returns the name of the DataBox tag as a std::string. If
35  * the DataBox tag is also a PrefixTag then the prefix is added.
36  *
37  * \tparam Tag the DataBox tag whose name to get
38  * \return string holding the DataBox tag's name
39  */
40 template <typename Tag>
41 std::string tag_name() noexcept {
42  if constexpr (detail::is_name_callable_v<Tag>) {
43  return Tag::name();
44  } else if constexpr (detail::has_base_v<Tag>) {
45  return tag_name<typename Tag::base>();
46  } else if constexpr (std::is_base_of_v<db::PrefixTag, Tag>) {
47  return pretty_type::short_name<Tag>() + "(" +
48  tag_name<typename Tag::tag>() + ")";
49  } else {
50  return pretty_type::short_name<Tag>();
51  }
52 }
53 } // 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:41
CREATE_IS_CALLABLE_V
#define CREATE_IS_CALLABLE_V(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:68
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
CREATE_HAS_TYPE_ALIAS_V
#define CREATE_HAS_TYPE_ALIAS_V(ALIAS_NAME)
Generate a type trait to check if a class has a type alias with a particular name,...
Definition: CreateHasTypeAlias.hpp:39
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:31
string