PDI 1.4.3

the PDI data interface

array_datatype.h
1 /*******************************************************************************
2  * Copyright (C) 2015-2019 Commissariat a l'energie atomique et aux energies alternatives (CEA)
3  * Copyright (C) 2020-2021 Institute of Bioorganic Chemistry Polish Academy of Science (PSNC)
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of CEA nor the names of its contributors may be used to
14  * endorse or promote products derived from this software without specific
15  * prior written permission.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23  * THE SOFTWARE.
24  ******************************************************************************/
25 
26 #ifndef PDI_ARRAY_DATATYPE_H_
27 #define PDI_ARRAY_DATATYPE_H_
28 
29 #include <memory>
30 #include <string>
31 #include <utility>
32 #include <vector>
33 
34 #include <pdi/pdi_fwd.h>
35 #include <pdi/datatype.h>
36 
37 namespace PDI {
38 
43 class PDI_EXPORT Array_datatype:
44  public Datatype
45 {
47  Datatype_uptr m_subtype;
48 
50  size_t m_size;
51 
53  size_t m_start;
54 
56  size_t m_subsize;
57 
58 public:
62  {
64  size_t m_index;
65 
66  std::string access_kind() const override;
67  public:
72  Index_accessor(size_t index);
73 
74  std::pair<void*, Datatype_uptr> access(const Array_datatype& array_type,
75  void* from,
76  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_begin,
77  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_end) const override;
78 
79  std::unique_ptr<Accessor_base> clone() const override;
80  };
81 
85  {
87  size_t m_start;
88 
90  size_t m_end;
91 
95  size_t size() const;
96 
97  std::string access_kind() const override;
98  public:
104  Slice_accessor(size_t start, size_t end);
105 
106  std::pair<void*, Datatype_uptr> access(const Array_datatype& array_type,
107  void* from,
108  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_begin,
109  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_end) const override;
110 
111  std::unique_ptr<Accessor_base> clone() const override;
112  };
113 
122  Array_datatype(Datatype_uptr subtype, size_t size, size_t start, size_t subsize, const Attributes_map& attributes = {});
123 
130  Array_datatype(Datatype_uptr subtype, size_t size, const Attributes_map& attributes = {});
131 
136  const Datatype& subtype() const;
137 
141  size_t size() const;
142 
147  size_t start() const;
148 
153  size_t subsize() const;
154 
155  Datatype_template_uptr clone() const override;
156 
157  Datatype_uptr clone_type() const override;
158 
159  Datatype_uptr densify() const override;
160 
161  Datatype_uptr evaluate(Context&) const override;
162 
163  bool dense() const override;
164 
165  size_t datasize() const override;
166 
167  size_t buffersize() const override;
168 
169  size_t alignment() const override;
170 
171  bool simple() const override;
172 
173  void* data_to_dense_copy(void*, const void*) const override;
174 
175  void* data_from_dense_copy(void*, const void*) const override;
176 
177  std::pair<void*, Datatype_uptr> subaccess_by_iterators(void* from,
178  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_begin,
179  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_end) const override;
180 
181  void destroy_data(void*) const override;
182 
183  std::string debug_string() const override;
184 
185  bool operator== (const Datatype&) const override;
186 
187 };
188 
189 } // namespace PDI
190 
191 #endif // PDI_ARRAY_DATATYPE_H_
Definition: context.h:44
Accessor to get single element from array.
Definition: array_datatype.h:61
A Datatype is a Datatype_template that accepts no argument.
Definition: datatype.h:46
Base class for datatype accesssors, that allow to get pointer to subtype.
Definition: datatype.h:52
an Array_datatype is a Datatype that represents an array: i.e storage of multiple elements of the sam...
Definition: array_datatype.h:43
Accessor to get a slice of an array, returns array of the same subtype.
Definition: array_datatype.h:84
std::unique_ptr< Datatype_template > Datatype_template_uptr
Definition: pdi_fwd.h:70
std::unique_ptr< Datatype > Datatype_uptr
Definition: pdi_fwd.h:74
std::unordered_map< std::string, Expression > Attributes_map
Definition: datatype_template.h:40
Definition: array_datatype.h:37