PDI 1.0.1

Data exchange made easy

datatype.h
1 /*******************************************************************************
2  * Copyright (C) 2015-2019 Commissariat a l'energie atomique et aux energies alternatives (CEA)
3  * Copyright (C) 2020 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 
104  ~Datatype() override;
105 
110  virtual Datatype_uptr clone_type() const = 0;
111 
117  virtual bool operator== (const Datatype& other) const = 0;
118 
124  bool operator!=(const Datatype& other) const;
125 
130  virtual Datatype_uptr densify() const = 0;
131 
136  virtual bool dense() const = 0;
137 
143  virtual size_t datasize() const = 0;
144 
150  virtual size_t buffersize() const = 0;
151 
156  virtual size_t alignment() const = 0;
157 
163  virtual bool simple() const = 0;
164 
172  virtual void* data_to_dense_copy(void* to, const void* from) const = 0;
173 
181  virtual void* data_from_dense_copy(void* to, const void* from) const = 0;
182 
190  std::pair<void*, Datatype_uptr> subaccess(void* from, const Accessor_base& accessor) const;
191 
199  std::pair<void*, Datatype_uptr> subaccess(void* from, const std::vector<std::unique_ptr<Accessor_base>>& accessors) const;
200 
209  virtual std::pair<void*, Datatype_uptr> subaccess_by_iterators(void* from,
210  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_begin,
211  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_end) const;
212 
218  virtual void destroy_data(void* ptr) const = 0;
219 
224  virtual std::string debug_string() const = 0;
225 
226 };
227 
228 } // namespace PDI
229 
230 #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:78
A Record_datatype is a Datatype that represents a fixed number of elements of potentially different t...
Definition: record_datatype.h:42
Definition: datatype_template.h:34
Definition: array_datatype.h:37