LeechCraft  0.6.70-6645-gcd10d7e
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 
39 namespace LeechCraft
40 {
41 namespace Util
42 {
43 namespace oral
44 {
45  struct NoAutogen;
46 
47  template<typename T, typename... Tags>
48  struct PKey
49  {
50  using value_type = T;
51 
52  T Val_;
53 
54  PKey () = default;
55 
56  PKey (T val)
57  : Val_ { val }
58  {
59  }
60 
61  PKey& operator= (T val)
62  {
63  Val_ = val;
64  return *this;
65  }
66 
67  operator value_type () const
68  {
69  return Val_;
70  }
71 
72  const value_type& operator* () const
73  {
74  return Val_;
75  }
76  };
77 
78  template<typename T>
79  struct Unique
80  {
81  using value_type = T;
82 
83  T Val_;
84 
85  Unique () = default;
86 
87  Unique (T val)
88  : Val_ { val }
89  {
90  }
91 
93  {
94  Val_ = val;
95  return *this;
96  }
97 
98  operator value_type () const
99  {
100  return Val_;
101  }
102 
103  const value_type& operator* () const
104  {
105  return Val_;
106  }
107  };
108 
109  namespace detail
110  {
111  template<typename T>
112  struct IsPKey : std::false_type {};
113 
114  template<typename U, typename... Tags>
115  struct IsPKey<PKey<U, Tags...>> : std::true_type {};
116  }
117 
118  template<typename Seq, int Idx>
119  struct References
120  {
121  using member_type = typename std::decay<typename boost::fusion::result_of::at_c<Seq, Idx>::type>::type;
122  static_assert (detail::IsPKey<member_type>::value, "References<> element must refer to a PKey<> element");
123 
124  using value_type = typename member_type::value_type;
126 
127  References () = default;
128 
130  : Val_ { t }
131  {
132  }
133 
134  template<typename T, typename... Tags>
136  : Val_ (static_cast<T> (key))
137  {
138  }
139 
141  {
142  Val_ = val;
143  return *this;
144  }
145 
146  template<typename T, typename... Tags>
148  {
149  Val_ = key;
150  return *this;
151  }
152 
153  operator value_type () const
154  {
155  return Val_;
156  }
157 
158  const value_type& operator* () const
159  {
160  return Val_;
161  }
162  };
163 }
164 }
165 }
typename member_type::value_type value_type
Definition: oraltypes.h:124
const value_type & operator*() const
Definition: oraltypes.h:72
typename std::decay< typename boost::fusion::result_of::at_c< Seq, Idx >::type >::type member_type
Definition: oraltypes.h:121
References(const PKey< T, Tags... > &key)
Definition: oraltypes.h:135