/* * Copyright 2008-2012 NVIDIA Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include #include #include namespace thrust { namespace detail { template struct is_wrapped_reference; } // the base type for all of thrust's system-annotated references. // for reasonable reference-like semantics, derived types must reimplement the following: // 1. constructor from pointer // 2. copy constructor // 3. templated copy constructor from other reference // 4. templated assignment from other reference // 5. assignment from value_type template class reference { private: typedef typename thrust::detail::eval_if< thrust::detail::is_same::value, thrust::detail::identity_, thrust::detail::identity_ >::type derived_type; // hint for is_wrapped_reference lets it know that this type (or a derived type) // is a wrapped reference struct wrapped_reference_hint {}; template friend struct thrust::detail::is_wrapped_reference; public: typedef Pointer pointer; typedef typename thrust::detail::remove_const::type value_type; __host__ __device__ explicit reference(const pointer &ptr); template __host__ __device__ reference(const reference &other, typename thrust::detail::enable_if_convertible< typename reference::pointer, pointer >::type * = 0); __host__ __device__ derived_type &operator=(const reference &other); // XXX this may need an enable_if template __host__ __device__ derived_type &operator=(const reference &other); __host__ __device__ derived_type &operator=(const value_type &x); __host__ __device__ pointer operator&() const; __host__ __device__ operator value_type () const; __host__ __device__ void swap(derived_type &other); derived_type &operator++(); value_type operator++(int); // XXX parameterize the type of rhs derived_type &operator+=(const value_type &rhs); derived_type &operator--(); value_type operator--(int); // XXX parameterize the type of rhs derived_type &operator-=(const value_type &rhs); // XXX parameterize the type of rhs derived_type &operator*=(const value_type &rhs); // XXX parameterize the type of rhs derived_type &operator/=(const value_type &rhs); // XXX parameterize the type of rhs derived_type &operator%=(const value_type &rhs); // XXX parameterize the type of rhs derived_type &operator<<=(const value_type &rhs); // XXX parameterize the type of rhs derived_type &operator>>=(const value_type &rhs); // XXX parameterize the type of rhs derived_type &operator&=(const value_type &rhs); // XXX parameterize the type of rhs derived_type &operator|=(const value_type &rhs); // XXX parameterize the type of rhs derived_type &operator^=(const value_type &rhs); private: const pointer m_ptr; // allow access to m_ptr for other references template friend class reference; template __host__ __device__ inline value_type strip_const_get_value(const System &system) const; template __host__ __device__ inline void assign_from(OtherPointer src); // XXX this helper exists only to avoid warnings about null references from the other assign_from template inline __host__ __device__ void assign_from(System1 *system1, System2 *system2, OtherPointer src); template __host__ __device__ inline void strip_const_assign_value(const System &system, OtherPointer src); // XXX this helper exists only to avoid warnings about null references from the other swap template inline __host__ __device__ void swap(System *system, derived_type &other); // XXX this helper exists only to avoid warnings about null references from operator value_type () template inline __host__ __device__ value_type convert_to_value_type(System *system) const; }; // end reference } // end thrust #include