PDI 1.4.3

the PDI data interface

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_DATATYPE_H_
27 #define PDI_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_template.h>
36 
37 
38 namespace PDI {
39 
46 class PDI_EXPORT Datatype:
47  public Datatype_template
48 {
49 public:
52  struct Accessor_base {
60  virtual std::pair<void*, Datatype_uptr> access(const Array_datatype& type,
61  void* from,
62  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_begin,
63  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_end) const;
64 
72  virtual std::pair<void*, Datatype_uptr> access(const Pointer_datatype& type,
73  void* from,
74  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_begin,
75  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_end) const;
76 
84  virtual std::pair<void*, Datatype_uptr> access(const Record_datatype& type,
85  void* from,
86  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_begin,
87  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_end) const;
88 
92  virtual std::string access_kind() const = 0;
93 
97  virtual std::unique_ptr<Accessor_base> clone() const = 0;
98 
101  virtual ~Accessor_base() = default;
102  };
103 
108  Datatype(const Attributes_map& attributes = {});
109 
110  ~Datatype() override;
111 
116  virtual Datatype_uptr clone_type() const = 0;
117 
123  virtual bool operator== (const Datatype& other) const = 0;
124 
130  bool operator!=(const Datatype& other) const;
131 
136  virtual Datatype_uptr densify() const = 0;
137 
142  virtual bool dense() const = 0;
143 
149  virtual size_t datasize() const = 0;
150 
156  virtual size_t buffersize() const = 0;
157 
162  virtual size_t alignment() const = 0;
163 
169  virtual bool simple() const = 0;
170 
178  virtual void* data_to_dense_copy(void* to, const void* from) const = 0;
179 
187  virtual void* data_from_dense_copy(void* to, const void* from) const = 0;
188 
196  std::pair<void*, Datatype_uptr> subaccess(void* from, const Accessor_base& accessor) const;
197 
205  std::pair<void*, Datatype_uptr> subaccess(void* from, const std::vector<std::unique_ptr<Accessor_base>>& accessors) const;
206 
215  virtual std::pair<void*, Datatype_uptr> subaccess_by_iterators(void* from,
216  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_begin,
217  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_end) const;
218 
224  virtual void destroy_data(void* ptr) const = 0;
225 
230  virtual std::string debug_string() const = 0;
231 
232 };
233 
234 } // namespace PDI
235 
236 #endif // PDI_DATATYPE_H_
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
Definition: pointer_datatype.h:37
std::unique_ptr< Datatype > Datatype_uptr
Definition: pdi_fwd.h:74
A Record_datatype is a Datatype that represents a fixed number of elements of potentially different t...
Definition: record_datatype.h:42
std::unordered_map< std::string, Expression > Attributes_map
Definition: datatype_template.h:40
Definition: datatype_template.h:42
Definition: array_datatype.h:37