Loading...
Searching...
No Matches
stringconvert.h
Go to the documentation of this file.
1#ifndef _BBM_STRINGCONVERT_H_
2#define _BBM_STRINGCONVERT_H_
3
4#include <string>
5
6/************************************************************************/
7/*! \file stringconvert.h
8
9 \brief concept to check if a type has a valid string_converter.
10
11*************************************************************************/
12
13namespace bbm {
14
15 //! \brief forward decalaration
16 template<typename T> struct string_converter;
17
18 namespace concepts {
19
20 /********************************************************************/
21 /*! \brief concept to check if a type has a valid string_converter with:
22
23 + std::string toString(const T& )
24
25 *********************************************************************/
26 template<typename T>
27 concept to_string_converter = requires(const T& t)
28 {
29 { string_converter<T>::toString(t) } -> std::convertible_to<std::string>;
30 };
31
32 /********************************************************************/
33 /*! \brief concept to check if a type has a valid string_converter with:
34
35 + T fromString(const std::string& )
36
37 *********************************************************************/
38 template<typename T>
39 concept from_string_converter = requires(const T& t)
40 {
41 { string_converter<T>::fromString(std::declval<std::string>()) } -> std::same_as<T>;
42 };
43
44 /********************************************************************/
45 /*! \brief Concept to check if type has a toString member
46 ********************************************************************/
47 template<typename T>
48 concept has_toString = requires(T t)
49 {
50 { t.toString() } -> std::same_as<std::string>;
51 };
52
53 /********************************************************************/
54 /*! \brief Concept to check if type has a fromString member
55 ********************************************************************/
56 template<typename T>
57 concept has_fromString = requires
58 {
59 { std::decay_t<T>::fromString( std::declval<std::string>() ) } -> std::same_as<std::decay_t<T>>;
60 };
61
62
63 /********************************************************************/
64 /*! @{ \name check if string conversion is fully defined
65 *******************************************************************/
66 template<typename T> concept to_stringconvert = (has_toString<T> || to_string_converter<T>);
68 template<typename T> concept stringconvert = to_stringconvert<T> && from_stringconvert<T>;
69 //! @}
70
71 } // end concepts namespace
72
73
74 /**********************************************************************/
75 /*! @{ \name forward declarations of toString and fromString
76 **********************************************************************/
77 template<typename T> requires concepts::from_stringconvert<T>
78 inline T fromString(const std::string&);
79
80 template<typename T> requires concepts::to_stringconvert<T>
81 inline std::string toString(const T&);
82
83} // end bbm namespace
84
85#endif /* _BBM_STRINGCONVERT_H_ */
concept to check if a type has a valid string_converter with:
Definition: stringconvert.h:39
Definition: stringconvert.h:67
Concept to check if type has a fromString member.
Definition: stringconvert.h:57
Concept to check if type has a toString member.
Definition: stringconvert.h:48
Definition: stringconvert.h:68
concept to check if a type has a valid string_converter with:
Definition: stringconvert.h:27
Definition: stringconvert.h:66
Definition: aggregatebsdf.h:29
T fromString(const std::string &)
fromString alias
Definition: stringconvert.h:584
std::string toString(const T &)
toString alias
Definition: stringconvert.h:594
static T fromString(const std::string &str)
convert a string to a type T
Definition: stringconvert.h:61
static std::string toString(const T &obj)
convert an object to a type T
Definition: stringconvert.h:112