1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_DETAIL_BUFFER_VALUE_HPP
12 #define BOOST_COMPUTE_DETAIL_BUFFER_VALUE_HPP
14 #include <boost/compute/context.hpp>
15 #include <boost/compute/command_queue.hpp>
16 #include <boost/compute/detail/device_ptr.hpp>
17 #include <boost/compute/detail/read_write_single_value.hpp>
33 buffer_value(const value_type &value)
38 // creates a reference for the value in buffer at index (in bytes).
39 buffer_value(const buffer &buffer, size_t index)
40 : m_buffer(buffer.get(), false),
45 buffer_value(const buffer_value<T> &other)
46 : m_buffer(other.m_buffer.get(), false),
47 m_index(other.m_index)
53 // set buffer to null so that its reference count will
54 // not be decremented when its destructor is called
58 operator value_type() const
61 const context &context = m_buffer.get_context();
62 const device &device = context.get_device();
63 command_queue queue(context, device);
65 return detail::read_single_value<T>(m_buffer, m_index / sizeof(T), queue);
72 buffer_value<T> operator-() const
77 bool operator<(const T &value) const
79 return T(*this) < value;
82 bool operator>(const T &value) const
84 return T(*this) > value;
87 bool operator<=(const T &value) const
89 return T(*this) <= value;
92 bool operator>=(const T &value) const
94 return T(*this) <= value;
97 bool operator==(const T &value) const
99 return T(*this) == value;
102 bool operator==(const buffer_value<T> &other) const
104 if(m_buffer.get() != other.m_buffer.get()){
109 return m_index == other.m_index;
112 return m_value == other.m_value;
116 bool operator!=(const T &value) const
118 return T(*this) != value;
121 buffer_value<T>& operator=(const T &value)
124 const context &context = m_buffer.get_context();
125 command_queue queue(context, context.get_device());
127 detail::write_single_value<T>(value, m_buffer, m_index / sizeof(T), queue);
137 buffer_value<T>& operator=(const buffer_value<T> &value)
139 return operator=(T(value));
142 detail::device_ptr<T> operator&() const
144 return detail::device_ptr<T>(m_buffer, m_index);
147 buffer_value<T>& operator++()
161 buffer_value<T> operator++(int)
163 buffer_value<T> result(*this);
169 const buffer m_buffer;
174 } // end detail namespace
175 } // end compute namespace
176 } // end boost namespace
178 #endif // BOOST_COMPUTE_DETAIL_BUFFER_VALUE_HPP