LeechCraft  0.6.70-13729-g7046a9d2a7
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 #include <variant>
33 #include <type_traits>
34 #include <boost/fusion/include/at_c.hpp>
35 #include <boost/fusion/adapted/struct/adapt_struct.hpp>
36 #include <boost/fusion/include/adapt_struct.hpp>
37 #include <util/sll/typelist.h>
38 #include <util/sll/typegetter.h>
39 
40 namespace LC
41 {
42 namespace Util
43 {
44 namespace oral
45 {
46  struct NoAutogen;
47 
48  template<typename T, typename Concrete>
50  {
51  using value_type = T;
52 
53  T Val_;
54 
55  IndirectHolderBase () = default;
56 
58  : Val_ { val }
59  {
60  }
61 
62  template<typename U = T, typename Sub = typename U::value_type>
64  : Val_ { val }
65  {
66  }
67 
68  Concrete& operator= (T val)
69  {
70  Val_ = val;
71  return static_cast<Concrete&> (*this);
72  }
73 
74  operator value_type () const
75  {
76  return Val_;
77  }
78 
79  const value_type& operator* () const
80  {
81  return Val_;
82  }
83 
84  const value_type* operator-> () const
85  {
86  return &Val_;
87  }
88  };
89 
90  template<typename T, typename... Tags>
91  struct PKey : IndirectHolderBase<T, PKey<T, Tags...>>
92  {
93  using PKey::IndirectHolderBase::IndirectHolderBase;
94  };
95 
96  template<typename T, typename... Args>
97  using PKeyValue_t = typename PKey<T, Args...>::value_type;
98 
99  template<typename T>
100  struct Unique : IndirectHolderBase<T, Unique<T>>
101  {
102  using Unique::IndirectHolderBase::IndirectHolderBase;
103  };
104 
105  template<typename T>
107 
108  template<typename T>
109  struct NotNull : IndirectHolderBase<T, NotNull<T>>
110  {
111  using NotNull::IndirectHolderBase::IndirectHolderBase;
112  };
113 
114  template<typename T>
116 
117  template<typename T>
119 
120  namespace detail
121  {
122  template<typename T>
123  struct IsReferencesTarget : std::false_type {};
124 
125  template<typename U, typename... Tags>
126  struct IsReferencesTarget<PKey<U, Tags...>> : std::true_type {};
127 
128  template<typename U>
129  struct IsReferencesTarget<Unique<U>> : std::true_type {};
130  }
131 
132  template<auto Ptr>
133  struct References : IndirectHolderBase<typename MemberPtrType_t<Ptr>::value_type, References<Ptr>>
134  {
136  static_assert (detail::IsReferencesTarget<member_type>::value, "References<> element must refer to a PKey<> element");
137 
138  using References::IndirectHolderBase::IndirectHolderBase;
139 
140  template<typename T, typename... Tags>
143  {
144  }
145 
146  template<typename T, typename... Tags>
148  {
149  this->Val_ = key;
150  return *this;
151  }
152  };
153 
154  template<auto Ptr>
156 
157  template<int... Fields>
158  struct PrimaryKey;
159 
160  template<int... Fields>
161  struct UniqueSubset;
162 
163  template<typename... Args>
164  using Constraints = Typelist<Args...>;
165 
166  template<auto... Fields>
167  struct Index;
168 
169  template<typename... Args>
170  using Indices = Typelist<Args...>;
171 
172  template<typename T>
173  struct IsIndirect : std::false_type {};
174 
175  template<typename T, typename... Args>
176  struct IsIndirect<PKey<T, Args...>> : std::true_type {};
177 
178  template<typename T>
179  struct IsIndirect<Unique<T>> : std::true_type {};
180 
181  template<typename T>
182  struct IsIndirect<NotNull<T>> : std::true_type {};
183 
184  template<auto Ptr>
185  struct IsIndirect<References<Ptr>> : std::true_type {};
186 
188  {
189  inline static struct DefaultTag {} Default;
190  inline static struct IgnoreTag {} Ignore;
191 
192  struct Replace
193  {
194  QStringList Fields_;
195 
196  template<auto... Ptrs>
197  struct FieldsType
198  {
199  operator InsertAction::Replace () const;
200  };
201 
202  template<auto... Ptrs>
203  inline static FieldsType<Ptrs...> Fields {};
204 
205  template<typename Seq>
206  struct PKeyType
207  {
208  operator InsertAction::Replace () const;
209  };
210 
211  template<typename Seq>
212  inline static PKeyType<Seq> PKey {};
213  };
214 
215  constexpr static auto StaticCount ()
216  {
217  return 2;
218  }
219 
220  using ActionSelector_t = std::variant<DefaultTag, IgnoreTag, Replace>;
222 
223  template<typename Tag>
224  InsertAction (Tag tag)
225  : Selector_ { tag }
226  {
227  }
228  };
229 }
230 }
231 }
static struct LC::Util::oral::InsertAction::IgnoreTag Ignore
const value_type * operator->() const
Definition: oraltypes.h:84
static constexpr auto StaticCount()
Definition: oraltypes.h:215
Open "Replace" dialog.
MemberPtrType_t< Ptr > member_type
Definition: oraltypes.h:135
typename PKey< T, Args... >::value_type PKeyValue_t
Definition: oraltypes.h:97
typename References< Ptr >::value_type ReferencesValue_t
Definition: oraltypes.h:155
MemberTypeType_t< decltype(Ptr)> MemberPtrType_t
Definition: typegetter.h:101
References & operator=(const PKey< T, Tags... > &key)
Definition: oraltypes.h:147
typename NotNull< T >::value_type NotNullValue_t
Definition: oraltypes.h:115
ActionSelector_t Selector_
Definition: oraltypes.h:221
static struct LC::Util::oral::InsertAction::DefaultTag Default
typename Unique< T >::value_type UniqueValue_t
Definition: oraltypes.h:106
static FieldsType< Ptrs... > Fields
Definition: oraltypes.h:203
std::variant< DefaultTag, IgnoreTag, Replace > ActionSelector_t
Definition: oraltypes.h:220
const value_type & operator*() const
Definition: oraltypes.h:79
Definition: constants.h:35
References(const PKey< T, Tags... > &key)
Definition: oraltypes.h:141