Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
name.hh
Go to the documentation of this file.
1 #ifndef VCSN_MISC_NAME_HH
2 # define VCSN_MISC_NAME_HH
3 
4 # include <initializer_list>
5 # include <iostream>
6 # include <memory>
7 # include <string>
8 # include <vector>
9 
11 # include <vcsn/misc/direction.hh>
12 # include <vcsn/misc/signature.hh>
13 
14 namespace vcsn
15 {
16 
17  /*---------------.
18  | Static names. |
19  `---------------*/
20 
21  template <typename T>
22  struct snamer
23  {
24  std::string operator()()
25  {
26  return T::sname();
27  }
28  };
29 
30  template <typename T>
31  std::string sname()
32  {
33  return snamer<T>()();
34  }
35 
36  template <typename T>
37  std::string sname(T&)
38  {
39  return sname<T>();
40  }
41 
43  template <typename... Args>
44  inline
45  signature
47  {
48  return {sname<Args>()...};
49  }
50 
51  /*----------------.
52  | Dynamic names. |
53  `----------------*/
54 
55  template <typename T>
56  struct vnamer
57  {
58  std::string operator()(T& t)
59  {
60  return t->vname(false);
61  }
62  };
63 
64  template <typename T>
65  std::string vname(T& t)
66  {
67  return vnamer<T>()(t);
68  }
69 
70  /*------------------.
71  | Specializations. |
72  `------------------*/
73 
74 
75  template <typename T>
76  struct snamer<std::shared_ptr<T>>: snamer<T>
77  {};
78 
79 #define DEFINE(Type) \
80  template <> \
81  struct snamer<Type> \
82  { \
83  std::string operator()() \
84  { \
85  return #Type; \
86  } \
87  }; \
88  \
89  template <> \
90  struct vnamer<Type> \
91  { \
92  std::string operator()(Type&) \
93  { \
94  return #Type; \
95  } \
96  };
97 
98 
99  DEFINE(bool);
100  DEFINE(float);
101  DEFINE(int);
102  DEFINE(unsigned);
103 
104  DEFINE(std::istream);
105  DEFINE(const std::string);
106  DEFINE(const std::vector<unsigned>);
107  DEFINE(std::ostream);
108 
111 #undef DEFINE
112 
113 
114  /*--------------------.
115  | integral_constant. |
116  `--------------------*/
117 
118 
119  template <typename T, T Value>
120  struct snamer<std::integral_constant<T, Value>>
121  {
122  std::string operator()()
123  {
124  return "std::integral_constant<unsigned, " + std::to_string(Value) + ">";
125  }
126  };
127 
128  template <typename T, T Value>
129  struct vnamer<std::integral_constant<T, Value>>
130  {
131  using type = std::integral_constant<T, Value>;
132  std::string operator()(type)
133  {
134  return sname<type>();
135  }
136  };
137 
156  {
157  std::string name;
158  };
159 
160  template <>
162  {
164  {
165  return t.name;
166  }
167  };
168 
169 
170  /*-------------.
171  | vsignature. |
172  `-------------*/
173 
175  template <typename... Args>
176  inline
177  signature
178  vsignature(Args&&... args)
179  {
180  return {vname(std::forward<Args>(args))...};
181  }
182 
183 } // namespace vcsn
184 
185 #endif // !VCSN_MISC_NAME_HH
std::integral_constant< T, Value > type
Definition: name.hh:131
std::string to_string(identities i)
Definition: identities.cc:13
std::string name
Definition: name.hh:157
std::string sname()
Definition: name.hh:31
signature vsignature(Args &&...args)
The signature of (Args...).
Definition: name.hh:178
std::string sname(T &)
Definition: name.hh:37
signature ssignature()
Static signature.
Definition: name.hh:46
std::string operator()(T &t)
Definition: name.hh:58
std::string operator()()
Definition: name.hh:24
A simple placeholder for integral constants.
Definition: name.hh:155
std::string vname(T &t)
Definition: name.hh:65
direction
Orientation.
Definition: direction.hh:10
std::string operator()(integral_constant t)
Definition: name.hh:163
identities
A ratexpset can implement several different sets of identities on expressions.
Definition: identities.hh:17
#define DEFINE(Type)
Definition: name.hh:79