LeechCraft  0.6.70-10870-g558588d6ec
Modular cross-platform feature rich live environment.
oraltypes.h
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Boost Software License - Version 1.0 - August 17th, 2003
6  *
7  * Permission is hereby granted, free of charge, to any person or organization
8  * obtaining a copy of the software and accompanying documentation covered by
9  * this license (the "Software") to use, reproduce, display, distribute,
10  * execute, and transmit the Software, and to prepare derivative works of the
11  * Software, and to permit third-parties to whom the Software is furnished to
12  * do so, all subject to the following:
13  *
14  * The copyright notices in the Software and this entire statement, including
15  * the above license grant, this restriction and the following disclaimer,
16  * must be included in all copies of the Software, in whole or in part, and
17  * all derivative works of the Software, unless such copies or derivative
18  * works are solely in the form of machine-executable object code generated by
19  * a source language processor.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
24  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
25  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  **********************************************************************/
29 
30 #pragma once
31 
32 #define BOOST_RESULT_OF_USE_DECLTYPE
33 
34 #include <type_traits>
35 #include <boost/fusion/include/at_c.hpp>
36 #include <boost/fusion/adapted/struct/adapt_struct.hpp>
37 #include <boost/fusion/include/adapt_struct.hpp>
38 #include <util/sll/typelist.h>
39 #include <util/sll/typegetter.h>
40 
41 namespace LeechCraft
42 {
43 namespace Util
44 {
45 namespace oral
46 {
47  struct NoAutogen;
48 
49  template<typename T, typename... Tags>
50  struct PKey
51  {
52  using value_type = T;
53 
54  T Val_;
55 
56  PKey () = default;
57 
58  PKey (T val)
59  : Val_ { val }
60  {
61  }
62 
63  PKey& operator= (T val)
64  {
65  Val_ = val;
66  return *this;
67  }
68 
69  operator value_type () const
70  {
71  return Val_;
72  }
73 
74  const value_type& operator* () const
75  {
76  return Val_;
77  }
78  };
79 
80  template<typename T, typename... Args>
81  using PKeyValue_t = typename PKey<T, Args...>::value_type;
82 
83  template<typename T>
84  struct Unique
85  {
86  using value_type = T;
87 
88  T Val_;
89 
90  Unique () = default;
91 
92  Unique (T val)
93  : Val_ { val }
94  {
95  }
96 
98  {
99  Val_ = val;
100  return *this;
101  }
102 
103  operator value_type () const
104  {
105  return Val_;
106  }
107 
108  const value_type& operator* () const
109  {
110  return Val_;
111  }
112  };
113 
114  template<typename T>
116 
117  template<typename T>
118  struct NotNull
119  {
120  using value_type = T;
121 
122  T Val_;
123 
124  NotNull () = default;
125 
126  NotNull (T val)
127  : Val_ { val }
128  {
129  }
130 
132  {
133  Val_ = val;
134  return *this;
135  }
136 
137  operator value_type () const
138  {
139  return Val_;
140  }
141 
142  const value_type& operator* () const
143  {
144  return Val_;
145  }
146  };
147 
148  template<typename T>
150 
151  namespace detail
152  {
153  template<typename T>
154  struct IsPKey : std::false_type {};
155 
156  template<typename U, typename... Tags>
157  struct IsPKey<PKey<U, Tags...>> : std::true_type {};
158  }
159 
160  template<auto Ptr>
161  struct References
162  {
164  static_assert (detail::IsPKey<member_type>::value, "References<> element must refer to a PKey<> element");
165 
166  using value_type = typename member_type::value_type;
168 
169  References () = default;
170 
172  : Val_ { t }
173  {
174  }
175 
176  template<typename T, typename... Tags>
178  : Val_ (static_cast<T> (key))
179  {
180  }
181 
183  {
184  Val_ = val;
185  return *this;
186  }
187 
188  template<typename T, typename... Tags>
190  {
191  Val_ = key;
192  return *this;
193  }
194 
195  operator value_type () const
196  {
197  return Val_;
198  }
199 
200  const value_type& operator* () const
201  {
202  return Val_;
203  }
204  };
205 
206  template<auto Ptr>
208 
209  template<int... Fields>
210  struct PrimaryKey;
211 
212  template<int... Fields>
213  struct UniqueSubset;
214 
215  template<typename... Args>
216  using Constraints = Typelist<Args...>;
217 
218  template<typename T>
219  struct IsIndirect : std::false_type {};
220 
221  template<typename T, typename... Args>
222  struct IsIndirect<PKey<T, Args...>> : std::true_type {};
223 
224  template<typename T>
225  struct IsIndirect<Unique<T>> : std::true_type {};
226 
227  template<typename T>
228  struct IsIndirect<NotNull<T>> : std::true_type {};
229 
230  template<auto Ptr>
231  struct IsIndirect<References<Ptr>> : std::true_type {};
232 }
233 }
234 }
Unique & operator=(T val)
Definition: oraltypes.h:97
typename References< Ptr >::value_type ReferencesValue_t
Definition: oraltypes.h:207
const value_type & operator*() const
Definition: oraltypes.h:200
const value_type & operator*() const
Definition: oraltypes.h:74
typename Unique< T >::value_type UniqueValue_t
Definition: oraltypes.h:115
typename detail::DecomposeMemberPtr< decltype(Ptr)>::Value_t MemberPtrType_t
Definition: typegetter.h:93
MemberPtrType_t< Ptr > member_type
Definition: oraltypes.h:163
typename NotNull< T >::value_type NotNullValue_t
Definition: oraltypes.h:149
NotNull & operator=(T val)
Definition: oraltypes.h:131
typename member_type::value_type value_type
Definition: oraltypes.h:166
typename PKey< T, Args... >::value_type PKeyValue_t
Definition: oraltypes.h:81
References & operator=(const value_type &val)
Definition: oraltypes.h:182
const value_type & operator*() const
Definition: oraltypes.h:142
const value_type & operator*() const
Definition: oraltypes.h:108
References(const PKey< T, Tags... > &key)
Definition: oraltypes.h:177