LeechCraft  0.6.70-9312-g4cc613a2df
Modular cross-platform feature rich live environment.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
40 namespace LeechCraft
41 {
42 namespace Util
43 {
44 namespace oral
45 {
46  struct NoAutogen;
47 
48  template<typename T, typename... Tags>
49  struct PKey
50  {
51  using value_type = T;
52 
53  T Val_;
54 
55  PKey () = default;
56 
57  PKey (T val)
58  : Val_ { val }
59  {
60  }
61 
62  PKey& operator= (T val)
63  {
64  Val_ = val;
65  return *this;
66  }
67 
68  operator value_type () const
69  {
70  return Val_;
71  }
72 
73  const value_type& operator* () const
74  {
75  return Val_;
76  }
77  };
78 
79  template<typename T>
80  struct Unique
81  {
82  using value_type = T;
83 
84  T Val_;
85 
86  Unique () = default;
87 
88  Unique (T val)
89  : Val_ { val }
90  {
91  }
92 
94  {
95  Val_ = val;
96  return *this;
97  }
98 
99  operator value_type () const
100  {
101  return Val_;
102  }
103 
104  const value_type& operator* () const
105  {
106  return Val_;
107  }
108  };
109 
110  namespace detail
111  {
112  template<typename T>
113  struct IsPKey : std::false_type {};
114 
115  template<typename U, typename... Tags>
116  struct IsPKey<PKey<U, Tags...>> : std::true_type {};
117  }
118 
119  template<typename Seq, int Idx>
120  struct References
121  {
122  using member_type = typename std::decay<typename boost::fusion::result_of::at_c<Seq, Idx>::type>::type;
123  static_assert (detail::IsPKey<member_type>::value, "References<> element must refer to a PKey<> element");
124 
125  using value_type = typename member_type::value_type;
127 
128  References () = default;
129 
131  : Val_ { t }
132  {
133  }
134 
135  template<typename T, typename... Tags>
137  : Val_ (static_cast<T> (key))
138  {
139  }
140 
142  {
143  Val_ = val;
144  return *this;
145  }
146 
147  template<typename T, typename... Tags>
149  {
150  Val_ = key;
151  return *this;
152  }
153 
154  operator value_type () const
155  {
156  return Val_;
157  }
158 
159  const value_type& operator* () const
160  {
161  return Val_;
162  }
163  };
164 
165  template<int... Fields>
166  struct PrimaryKey;
167 
168  template<int... Fields>
169  struct UniqueSubset;
170 
171  template<typename... Args>
172  using Constraints = Typelist<Args...>;
173 }
174 }
175 }
References(const PKey< T, Tags...> &key)
Definition: oraltypes.h:136
Unique & operator=(T val)
Definition: oraltypes.h:93
References & operator=(const value_type &val)
Definition: oraltypes.h:141
const value_type & operator*() const
Definition: oraltypes.h:104
typename member_type::value_type value_type
Definition: oraltypes.h:125
const value_type & operator*() const
Definition: oraltypes.h:73
typename std::decay< typename boost::fusion::result_of::at_c< Seq, Idx >::type >::type member_type
Definition: oraltypes.h:122
const value_type & operator*() const
Definition: oraltypes.h:159