LeechCraft  0.6.70-11552-gf61ee51c3d
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 <boost/variant.hpp>
39 #include <util/sll/typelist.h>
40 #include <util/sll/typegetter.h>
41 
42 namespace LeechCraft
43 {
44 namespace Util
45 {
46 namespace oral
47 {
48  struct NoAutogen;
49 
50  template<typename T, typename... Tags>
51  struct PKey
52  {
53  using value_type = T;
54 
55  T Val_;
56 
57  PKey () = default;
58 
59  PKey (T val)
60  : Val_ { val }
61  {
62  }
63 
64  PKey& operator= (T val)
65  {
66  Val_ = val;
67  return *this;
68  }
69 
70  operator value_type () const
71  {
72  return Val_;
73  }
74 
75  const value_type& operator* () const
76  {
77  return Val_;
78  }
79  };
80 
81  template<typename T, typename... Args>
82  using PKeyValue_t = typename PKey<T, Args...>::value_type;
83 
84  template<typename T>
85  struct Unique
86  {
87  using value_type = T;
88 
89  T Val_;
90 
91  Unique () = default;
92 
93  Unique (T val)
94  : Val_ { val }
95  {
96  }
97 
99  {
100  Val_ = val;
101  return *this;
102  }
103 
104  operator value_type () const
105  {
106  return Val_;
107  }
108 
109  const value_type& operator* () const
110  {
111  return Val_;
112  }
113  };
114 
115  template<typename T>
117 
118  template<typename T>
119  struct NotNull
120  {
121  using value_type = T;
122 
123  T Val_;
124 
125  NotNull () = default;
126 
127  NotNull (T val)
128  : Val_ { val }
129  {
130  }
131 
133  {
134  Val_ = val;
135  return *this;
136  }
137 
138  operator value_type () const
139  {
140  return Val_;
141  }
142 
143  const value_type& operator* () const
144  {
145  return Val_;
146  }
147  };
148 
149  template<typename T>
151 
152  namespace detail
153  {
154  template<typename T>
155  struct IsReferencesTarget : std::false_type {};
156 
157  template<typename U, typename... Tags>
158  struct IsReferencesTarget<PKey<U, Tags...>> : std::true_type {};
159 
160  template<typename U>
161  struct IsReferencesTarget<Unique<U>> : std::true_type {};
162  }
163 
164  template<auto Ptr>
165  struct References
166  {
168  static_assert (detail::IsReferencesTarget<member_type>::value, "References<> element must refer to a PKey<> element");
169 
170  using value_type = typename member_type::value_type;
172 
173  References () = default;
174 
176  : Val_ { t }
177  {
178  }
179 
180  template<typename T, typename... Tags>
182  : Val_ (static_cast<T> (key))
183  {
184  }
185 
187  {
188  Val_ = val;
189  return *this;
190  }
191 
192  template<typename T, typename... Tags>
194  {
195  Val_ = key;
196  return *this;
197  }
198 
199  operator value_type () const
200  {
201  return Val_;
202  }
203 
204  const value_type& operator* () const
205  {
206  return Val_;
207  }
208  };
209 
210  template<auto Ptr>
212 
213  template<int... Fields>
214  struct PrimaryKey;
215 
216  template<int... Fields>
217  struct UniqueSubset;
218 
219  template<typename... Args>
220  using Constraints = Typelist<Args...>;
221 
222  template<typename T>
223  struct IsIndirect : std::false_type {};
224 
225  template<typename T, typename... Args>
226  struct IsIndirect<PKey<T, Args...>> : std::true_type {};
227 
228  template<typename T>
229  struct IsIndirect<Unique<T>> : std::true_type {};
230 
231  template<typename T>
232  struct IsIndirect<NotNull<T>> : std::true_type {};
233 
234  template<auto Ptr>
235  struct IsIndirect<References<Ptr>> : std::true_type {};
236 
238  {
239  inline static struct DefaultTag {} Default;
240  inline static struct IgnoreTag {} Ignore;
241 
242  struct Replace
243  {
244  QStringList Fields_;
245 
246  template<auto... Ptrs>
247  struct FieldsType
248  {
249  operator InsertAction::Replace () const;
250  };
251 
252  template<auto... Ptrs>
253  inline static FieldsType<Ptrs...> Fields {};
254 
255  template<typename Seq>
256  struct PKeyType
257  {
258  operator InsertAction::Replace () const;
259  };
260 
261  template<typename Seq>
262  inline static PKeyType<Seq> PKey {};
263  };
264 
265  constexpr static auto StaticCount ()
266  {
267  return 2;
268  }
269 
270  using ActionSelector_t = boost::variant<DefaultTag, IgnoreTag, Replace>;
272 
273  template<typename Tag>
274  InsertAction (Tag tag)
275  : Selector_ { tag }
276  {
277  }
278  };
279 }
280 }
281 }
static FieldsType< Ptrs... > Fields
Definition: oraltypes.h:253
Unique & operator=(T val)
Definition: oraltypes.h:98
typename References< Ptr >::value_type ReferencesValue_t
Definition: oraltypes.h:211
const value_type & operator*() const
Definition: oraltypes.h:204
boost::variant< DefaultTag, IgnoreTag, Replace > ActionSelector_t
Definition: oraltypes.h:270
const value_type & operator*() const
Definition: oraltypes.h:75
typename Unique< T >::value_type UniqueValue_t
Definition: oraltypes.h:116
typename detail::DecomposeMemberPtr< decltype(Ptr)>::Value_t MemberPtrType_t
Definition: typegetter.h:93
Open "Replace" dialog.
MemberPtrType_t< Ptr > member_type
Definition: oraltypes.h:167
typename NotNull< T >::value_type NotNullValue_t
Definition: oraltypes.h:150
NotNull & operator=(T val)
Definition: oraltypes.h:132
typename member_type::value_type value_type
Definition: oraltypes.h:170
typename PKey< T, Args... >::value_type PKeyValue_t
Definition: oraltypes.h:82
static struct LeechCraft::Util::oral::InsertAction::DefaultTag Default
static struct LeechCraft::Util::oral::InsertAction::IgnoreTag Ignore
References & operator=(const value_type &val)
Definition: oraltypes.h:186
const value_type & operator*() const
Definition: oraltypes.h:143
const value_type & operator*() const
Definition: oraltypes.h:109
static constexpr auto StaticCount()
Definition: oraltypes.h:265
References(const PKey< T, Tags... > &key)
Definition: oraltypes.h:181