]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | //---------------------------------------------------------------------------// |
2 | // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com> | |
3 | // | |
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 | |
7 | // | |
8 | // See http://boostorg.github.com/compute for more information. | |
9 | //---------------------------------------------------------------------------// | |
10 | ||
11 | #ifndef BOOST_COMPUTE_CONTAINER_DETAIL_SCALAR_HPP | |
12 | #define BOOST_COMPUTE_CONTAINER_DETAIL_SCALAR_HPP | |
13 | ||
14 | #include <boost/compute/buffer.hpp> | |
15 | #include <boost/compute/detail/read_write_single_value.hpp> | |
16 | ||
17 | namespace boost { | |
18 | namespace compute { | |
19 | namespace detail { | |
20 | ||
21 | // scalar<T> provides a trivial "container" that stores a | |
22 | // single value in a memory buffer on a compute device | |
23 | template<class T> | |
24 | class scalar | |
25 | { | |
26 | public: | |
27 | typedef T value_type; | |
28 | ||
29 | scalar(const context &context) | |
30 | : m_buffer(context, sizeof(T)) | |
31 | { | |
32 | } | |
33 | ||
34 | ~scalar() | |
35 | { | |
36 | } | |
37 | ||
38 | T read(command_queue &queue) const | |
39 | { | |
40 | return read_single_value<T>(m_buffer, 0, queue); | |
41 | } | |
42 | ||
43 | void write(const T &value, command_queue &queue) | |
44 | { | |
45 | write_single_value<T>(value, m_buffer, 0, queue); | |
46 | } | |
47 | ||
48 | const buffer& get_buffer() const | |
49 | { | |
50 | return m_buffer; | |
51 | } | |
52 | ||
53 | private: | |
54 | buffer m_buffer; | |
55 | }; | |
56 | ||
57 | } // end detail namespace | |
58 | } // end compute namespace | |
59 | } // end boost namespace | |
60 | ||
61 | #endif // BOOST_COMPUTE_CONTAINER_DETAIL_SCALAR_HPP |