Debian Codegraph @

deps/qt-maybe/Maybe.h

raw symbols SCIP
1 #cxx . . $ `<file>/deps/qt-maybe/Maybe.h`/ifndef QT_MAYBE_H
2 #define QT_MAYBE_Hcxx . . $ `deps/qt-maybe/Maybe.h:2:9`!
3
4 #include "Either.h"cxx . . $ `<file>/deps/qt-maybe/Either.h`/
5
6 /** A simple option type implementation which represents the result
7 * of an operation which returned either a valid result or nothing.
8 *
9 * Maybe<T> is built on top of Either<T1,T2>, using one type to
10 * hold the result (of type T) and the other to represent no result.
11 *
12 * Since Maybe<T> is built on Either<T1,T2>, it uses QVariant for the underlying
13 * value storage and has the same size.
14 *
15 * Maybe<T> instances can be constructed using the just(T) and
16 * nothing() helper functions.
17 */
18 template <class T>
19 class Maybecxx . . $ Maybe#
20 {
21 public:
22 /** Construct a Maybe<T> instance representing no
23 * value.
24 */
25 Maybecxx . . $ Maybe#`Maybe<T>`(49f6e7a06ebc5aa8).()
26 : m_valuecxx . . $ Maybe#m_value.(false)
27 {}
28
29 /** Returns true if this Maybe<T> has a value. */
30 operatorcxx . . $ Maybe#`operator bool`(50ce9a9e25b4a850). bool() const {
31 return m_valuecxx . . $ Maybe#m_value..template iscxx . . $ Either#is(50ce9a9e25b4a850).<T>();
32 }
33
34 /** Returns the value from this Maybe<T>. Asserts
35 * in debug builds if there is no value.
36 */
37 T valuecxx . . $ Maybe#value(8f5363d873dd4781).() const {
38 return m_valuecxx . . $ Maybe#m_value..template ascxx . . $ Either#as(900f63fbdad42e82).<T>();
39 }
40
41 // helper method for the non-member just() function,
42 // which external helpers should use instead
43 template <class U>
44 static Maybecxx . . $ Maybe#<T> justcxx . . $ Maybe#just(273d67e506b63127).(const U& value);
45
46 private:
47 // use the just() function to create a new
48 // Maybe<T> instance with a value
49 Maybecxx . . $ Maybe#`Maybe<T>`(77d9f17553126ecb).(const T& value)
50 : m_valuecxx . . $ Maybe#m_value.(value)
51 {}
52
53 Eithercxx . . $ Either#<bool,T> m_valuecxx . . $ Maybe#m_value.;
54 };
55
56 template <class T>
57 template <class U>
58 Maybecxx . . $ Maybe#<T> Maybecxx . . $ Maybe#<T>::justcxx . . $ Maybe#just(273d67e506b63127).(const U& value)
59 {
60 return Maybecxx . . $ Maybe#<T>(value);
61 }
62
63 // helper type used by nothing()
64 struct NothingTypecxx . . $ NothingType#
65 {
66 template <typename T>
67 operatorcxx . . $ NothingType#`operator Maybe<type-parameter-0-0>`(14051a91f9b6a65b). Maybecxx . . $ Maybe#<T>() const {
68 return Maybecxx . . $ Maybe#<T>();
69 }
70 };
71
72 // helper type used by just()
73 template <typename T>
74 struct JustTypecxx . . $ JustType#
75 {
76 JustTypecxx . . $ JustType#`JustType<T>`(77d9f17553126ecb).(const T& _value)
77 : valuecxx . . $ JustType#value.(_value)
78 {}
79
80 template <typename U>
81 operatorcxx . . $ JustType#`operator Maybe<type-parameter-1-0>`(d7f07c7eccc91850). Maybecxx . . $ Maybe#<U>() const {
82 return Maybecxx . . $ Maybe#<U>::just(valuecxx . . $ JustType#value.);
83 }
84
85 const T& valuecxx . . $ JustType#value.;
86 };
87
88 // helper type specialized for pointer types
89 template <typename T>
90 struct JustTypecxx . . $ JustType#<T*>
91 {
92 JustTypecxx . . $ JustType#`JustType<T *>`(ebd0a1552f8ce24f).(T* _value)
93 : valuecxx . . $ JustType#value.(_value)
94 {}
95
96 operatorcxx . . $ JustType#`operator Maybe<type-parameter-0-0 *>`(eb1c816bde0dfc09). Maybecxx . . $ Maybe#<T*>() const {
97 // just(T*) returns a no-value Maybe if the pointer
98 // is null
99 return valuecxx . . $ JustType#value. ? Maybecxx . . $ Maybe#<T*>::just(valuecxx . . $ JustType#value.) : Maybecxx . . $ Maybe#<T*>();
100 }
101
102 T* valuecxx . . $ JustType#value.;
103 };
104
105 /** Returns a type which can be implicitly cast to any Maybe<T> type,
106 * representing a function which returned no value.
107 */
108 inline NothingTypecxx . . $ NothingType# nothingcxx . . $ nothing(adb11f779fe07013).()
109 {
110 return NothingTypecxx . . $ NothingType#();
111 }
112
113 /** Returns a type which can be implicitly cast to a Maybe<T> type
114 * representing a function which did return a value of @p value.
115 *
116 * just() is specialized for pointer types to return nothing()
117 * if the pointer is null.
118 */
119 template <typename T>
120 inline JustTypecxx . . $ JustType#<T> justcxx . . $ just(62f398f3cea75aa5).(const T& value) {
121 return JustTypecxx . . $ JustType#<T>(value);
122 }
123
124 #endif