OSDN Git Service

CUDA
[eos/hostdependX86LINUX64.git] / util / X86LINUX64 / cuda-6.5 / include / thrust / detail / reference.h
1 /*
2  *  Copyright 2008-2013 NVIDIA Corporation
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  */
16
17 #pragma once
18
19 #include <thrust/detail/config.h>
20 #include <thrust/detail/type_traits.h>
21 #include <thrust/detail/use_default.h>
22 #include <thrust/detail/reference_forward_declaration.h>
23
24
25 namespace thrust
26 {
27 namespace detail
28 {
29
30 template<typename> struct is_wrapped_reference;
31
32 }
33
34 // the base type for all of thrust's system-annotated references.
35 // for reasonable reference-like semantics, derived types must reimplement the following:
36 // 1. constructor from pointer
37 // 2. copy constructor
38 // 3. templated copy constructor from other reference
39 // 4. templated assignment from other reference
40 // 5. assignment from value_type
41 template<typename Element, typename Pointer, typename Derived>
42   class reference
43 {
44   private:
45     typedef typename thrust::detail::eval_if<
46       thrust::detail::is_same<Derived,use_default>::value,
47       thrust::detail::identity_<reference>,
48       thrust::detail::identity_<Derived>
49     >::type derived_type;
50
51     // hint for is_wrapped_reference lets it know that this type (or a derived type)
52     // is a wrapped reference
53     struct wrapped_reference_hint {};
54     template<typename> friend struct thrust::detail::is_wrapped_reference;
55
56   public:
57     typedef Pointer                                              pointer;
58     typedef typename thrust::detail::remove_const<Element>::type value_type;
59
60     __host__ __device__
61     explicit reference(const pointer &ptr);
62
63     template<typename OtherElement, typename OtherPointer, typename OtherDerived>
64     __host__ __device__
65     reference(const reference<OtherElement,OtherPointer,OtherDerived> &other,
66               typename thrust::detail::enable_if_convertible<
67                 typename reference<OtherElement,OtherPointer,OtherDerived>::pointer,
68                 pointer
69               >::type * = 0);
70
71     __host__ __device__
72     derived_type &operator=(const reference &other);
73
74     // XXX this may need an enable_if
75     template<typename OtherElement, typename OtherPointer, typename OtherDerived>
76     __host__ __device__
77     derived_type &operator=(const reference<OtherElement,OtherPointer,OtherDerived> &other);
78
79     __host__ __device__
80     derived_type &operator=(const value_type &x);
81
82     __host__ __device__
83     pointer operator&() const;
84
85     __host__ __device__
86     operator value_type () const;
87
88     __host__ __device__
89     void swap(derived_type &other);
90
91     derived_type &operator++();
92
93     value_type operator++(int);
94
95     // XXX parameterize the type of rhs
96     derived_type &operator+=(const value_type &rhs);
97
98     derived_type &operator--();
99
100     value_type operator--(int);
101
102     // XXX parameterize the type of rhs
103     derived_type &operator-=(const value_type &rhs);
104
105     // XXX parameterize the type of rhs
106     derived_type &operator*=(const value_type &rhs);
107
108     // XXX parameterize the type of rhs
109     derived_type &operator/=(const value_type &rhs);
110
111     // XXX parameterize the type of rhs
112     derived_type &operator%=(const value_type &rhs);
113
114     // XXX parameterize the type of rhs
115     derived_type &operator<<=(const value_type &rhs);
116
117     // XXX parameterize the type of rhs
118     derived_type &operator>>=(const value_type &rhs);
119
120     // XXX parameterize the type of rhs
121     derived_type &operator&=(const value_type &rhs);
122
123     // XXX parameterize the type of rhs
124     derived_type &operator|=(const value_type &rhs);
125
126     // XXX parameterize the type of rhs
127     derived_type &operator^=(const value_type &rhs);
128
129   private:
130     const pointer m_ptr;
131
132     // allow access to m_ptr for other references
133     template <typename OtherElement, typename OtherPointer, typename OtherDerived> friend class reference;
134
135     template<typename System>
136     __host__ __device__
137     inline value_type strip_const_get_value(const System &system) const;
138
139     template<typename OtherPointer>
140     __host__ __device__
141     inline void assign_from(OtherPointer src);
142
143     // XXX this helper exists only to avoid warnings about null references from the other assign_from
144     template<typename System1, typename System2, typename OtherPointer>
145     inline __host__ __device__
146     void assign_from(System1 *system1, System2 *system2, OtherPointer src);
147
148     template<typename System, typename OtherPointer>
149     __host__ __device__
150     inline void strip_const_assign_value(const System &system, OtherPointer src);
151
152     // XXX this helper exists only to avoid warnings about null references from the other swap
153     template<typename System>
154     inline __host__ __device__
155     void swap(System *system, derived_type &other);
156
157     // XXX this helper exists only to avoid warnings about null references from operator value_type ()
158     template<typename System>
159     inline __host__ __device__
160     value_type convert_to_value_type(System *system) const;
161 }; // end reference
162
163   
164 } // end thrust
165
166 #include <thrust/detail/reference.inl>
167