Loading...
Searching...
No Matches
config.h
Go to the documentation of this file.
1#ifndef _BBM_CONFIG_CONCEPT_H_
2#define _BBM_CONFIG_CONCEPT_H_
3
4#include <concepts>
5#include <type_traits>
6
7#include "concepts/named.h"
8
9/************************************************************************/
10/*! \file config.h
11
12 \brief config contract
13
14*************************************************************************/
15
16namespace bbm {
17 namespace concepts {
18
19 /**********************************************************************/
20 /*! \brief config concept
21
22 Each config struct contains:
23 + concepts::named
24 + a Config typedef that points to itself
25 + a Value typedef
26 + a Spectrum typedef
27 + static Spectrum wavelength() that returns a Spectrum-type with the
28 wavelength in each channel in nm.
29 **********************************************************************/
30 template<typename T>
31 concept config = requires
32 {
33 requires concepts::named<T>;
34
35 typename std::decay_t<T>::Config;
36 typename std::decay_t<T>::Value;
37 typename std::decay_t<T>::Spectrum;
38
39 { std::decay_t<T>::wavelength() } -> std::same_as<typename std::decay_t<T>::Spectrum>;
40
41 // Config must point to itself.
42 requires std::same_as<typename std::decay_t<T>::Config, std::decay_t<T>>;
43 };
44
45
46
47 /*********************************************************************/
48 /*! \brief has_config
49
50 Check if the object has a Config typedef.
51 **********************************************************************/
52 template<typename T>
53 concept has_config = requires {typename std::decay_t<T>::Config;};
54
55
56 /*********************************************************************/
57 /*! \brief matching_config concept
58
59 Checks if all types have the same config; will fail if any type is not
60 a config.
61 **********************************************************************/
62 template<typename... U>
63 concept matching_config = (std::same_as<typename std::decay_t<std::tuple_element_t<0, std::tuple<U...>>>::Config, typename std::decay_t<U>::Config> && ...);
64
65
66 /*********************************************************************/
67 /*! \brief config archtype for concept cheking.
68 *********************************************************************/
69 namespace archetype {
70 struct config {
71 static constexpr string_literal name = "archetype";
72 using Config = config;
73 using Value = float;
74 using Spectrum = bbm::color<float>;
75 static constexpr Spectrum wavelength(void);
76 };
77 } // end arcetype namespace
78
79 } // end concepts namespace
80} // end bbm namespace
81
82#endif /* _BBM_CONFIG_CONCEPT_H_ */
config concept
Definition: config.h:31
has_config
Definition: config.h:53
matching_config concept
Definition: config.h:63
A named class is a class that contains a static constexpr string_literal name.
Definition: named.h:19
named (class) concept.
Definition: aggregatebsdf.h:29
Definition: config.h:70
bbm::color< float > Spectrum
Definition: config.h:74
static constexpr Spectrum wavelength(void)
static constexpr string_literal name
Definition: config.h:71
float Value
Definition: config.h:73
Definition: string_literal.h:16