Interface Documentation
Version: invalid
accessor.hh
Go to the documentation of this file.
1 /*
2  @@@@@@@@ @@ @@@@@@ @@@@@@@@ @@
3  /@@///// /@@ @@////@@ @@////// /@@
4  /@@ /@@ @@@@@ @@ // /@@ /@@
5  /@@@@@@@ /@@ @@///@@/@@ /@@@@@@@@@/@@
6  /@@//// /@@/@@@@@@@/@@ ////////@@/@@
7  /@@ /@@/@@//// //@@ @@ /@@/@@
8  /@@ @@@//@@@@@@ //@@@@@@ @@@@@@@@ /@@
9  // /// ////// ////// //////// //
10 
11  Copyright (c) 2016, Triad National Security, LLC
12  All rights reserved.
13  */
14 #pragma once
15 
22 #if !defined(__FLECSI_PRIVATE__)
23 #error Do not include this file directly!
24 #endif
25 
26 #include "flecsi/data/reference.hh"
27 #include "flecsi/exec/launch.hh"
28 #include <flecsi/data/field.hh>
29 
30 namespace flecsi {
31 namespace data {
32 
33 template<typename DATA_TYPE, size_t PRIVILEGES>
34 struct accessor<singular, DATA_TYPE, PRIVILEGES> {
35  using value_type = DATA_TYPE;
37  using element_type = typename base_type::element_type;
38 
39  accessor(const base_type & b) : base(b) {}
40 
41  element_type & get() const {
42  return base(0);
43  } // data
44  operator element_type &() const {
45  return get();
46  } // value
47 
48  const accessor & operator=(const DATA_TYPE & value) const {
49  return const_cast<accessor &>(*this) = value;
50  } // operator=
51  accessor & operator=(const DATA_TYPE & value) {
52  get() = value;
53  return *this;
54  } // operator=
55 
56  base_type & get_base() {
57  return base;
58  }
59  const base_type & get_base() const {
60  return base;
61  }
62  friend base_type * get_null_base(accessor *) { // for task_prologue_t
63  return nullptr;
64  }
65 
66 private:
67  base_type base;
68 }; // struct accessor
69 
70 template<typename DATA_TYPE, size_t PRIVILEGES>
71 struct accessor<dense, DATA_TYPE, PRIVILEGES> : reference_base {
72  using value_type = DATA_TYPE;
73  using element_type = std::
74  conditional_t<privilege_write(PRIVILEGES), value_type, const value_type>;
75 
76  explicit accessor(std::size_t f) : reference_base(f) {}
77 
85  element_type & operator()(size_t index) const {
86  flog_assert(index < size_, "index out of range");
87  return data_[index];
88  } // operator()
89 
90  element_type * data() const {
91  return data_;
92  } // data
93 
94 private:
95  friend void bind(accessor & a, size_t size, element_type * data) {
96  a.size_ = size;
97  a.data_ = data;
98  }
99 
100  // These must be initialized to copy into a user's accessor parameter.
101  size_t size_ = 0;
102  element_type * data_ = nullptr;
103 
104 }; // struct accessor
105 
106 } // namespace data
107 
108 template<class T, std::size_t S>
109 struct exec::detail::task_param<data::accessor<data::dense, T, S>> {
110  template<class Topo, topo::index_space_t<Topo> Space>
111  static auto replace(
113  return data::accessor<data::dense, T, S>(r.fid());
114  }
115 };
116 template<class T, std::size_t S>
117 struct exec::detail::task_param<data::accessor<data::singular, T, S>> {
119  template<class Topo, topo::index_space_t<Topo> Space>
120  static type replace(
122  return exec::replace_argument<typename type::base_type>(
123  r.template cast<data::dense>());
124  }
125 };
126 
127 } // namespace flecsi
element_type & operator()(size_t index) const
Definition: accessor.hh:85
Definition: reference.hh:43
Definition: field.hh:83
Access to the single element of an array.
Definition: layout.hh:39
#define flog_assert(test, message)
Definition: flog.hh:411
Definition: field.hh:32
Definition: launch.hh:35
Definition: control.hh:31