SeqAn3
The Modern C++ library for sequence analysis.
reflection.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2019, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2019, Knut Reinert & MPI für molekulare Genetik
4 // This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5 // shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6 // -----------------------------------------------------------------------------------------------------
7 
13 #pragma once
14 
15 #include <utility>
16 
18 
19 namespace seqan3::detail
20 {
21 
32 template <typename type>
33 struct get_display_name_size
34 {
35 private:
37  static constexpr auto get_size()
38  {
39  // __PRETTY_FUNCTION__ exposes the signature of the class including the name of the template instance as
40  // a static const char[]. The following code, extracts the part that displays the template name.
41  auto name_ptr = __PRETTY_FUNCTION__;
42 
43  // Move pointer to first letter of actual type name.
44  while (*name_ptr++ != '=')
45  {}
46 
47  for (; *name_ptr == ' '; ++name_ptr)
48  {}
49 
50  // Find the end of the actual type name.
51  char const * end_name_ptr = name_ptr;
52  int count = 1;
53 
54  for (; ; ++end_name_ptr)
55  {
56  switch (*end_name_ptr)
57  {
58  case '[':
59  ++count;
60  break;
61  case ']':
62  --count;
63  if (!count)
64  return size_t(end_name_ptr - name_ptr);
65  break;
66  }
67  }
68  return size_t(0);
69  };
70 
71 public:
73  static constexpr size_t value = get_size();
74 };
75 
79 template <typename type>
80 constexpr size_t get_display_name_size_v = get_display_name_size<type>::value;
81 
95 template <typename type>
96 struct get_display_name
97 {
98 private:
100  static constexpr auto get_display_name_fn()
101  {
102  // Use a helper function to extract the size of the requested type.
103  constexpr auto name_length = get_display_name_size_v<type>;
104 
105  // Extract the type again.
106  auto name_ptr = __PRETTY_FUNCTION__;
107 
108  // Move pointer to first letter of actual type name.
109  while (*name_ptr++ != '=')
110  {}
111 
112  for (; *name_ptr == ' '; ++name_ptr)
113  {}
114 
115  return small_string<name_length>{name_ptr, name_ptr + name_length};
116  };
117 public:
119  static constexpr small_string value = get_display_name_fn();
120 };
121 
125 template <typename type>
126 constexpr small_string get_display_name_v = get_display_name<type>::value;
127 } // namespace seqan3::detail
T count(T... args)
Definition: aligned_sequence_concept.hpp:35
A constexpr string implementation to manipulate string literals at compile time.