PDI 1.7.0-alpha.2023-10-26

the PDI data interface

datatype.h
1/*******************************************************************************
2 * Copyright (C) 2015-2021 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
37namespace PDI {
38
46class PDI_EXPORT Datatype: public Datatype_template
47{
48public:
53 Datatype(const Attributes_map& attributes = {});
54
55 ~Datatype() override;
56
62 virtual bool operator== (const Datatype& other) const = 0;
63
69 bool operator!= (const Datatype& other) const;
70
75 virtual Datatype_sptr densify() const = 0;
76
81 virtual bool dense() const = 0;
82
88 virtual size_t datasize() const = 0;
89
95 virtual size_t buffersize() const = 0;
96
101 virtual size_t alignment() const = 0;
102
107 virtual bool simple() const = 0;
108
115 virtual void* data_to_dense_copy(void* to, const void* from) const = 0;
116
123 virtual void* data_from_dense_copy(void* to, const void* from) const = 0;
124
130 virtual Datatype_sptr index(size_t index) const;
131
138 virtual std::pair<void*, Datatype_sptr> index(size_t index, void* data) const;
139
146 virtual Datatype_sptr slice(size_t start_index, size_t end_index) const;
147
155 virtual std::pair<void*, Datatype_sptr> slice(size_t start_index, size_t end_index, void* data) const;
156
162 virtual Datatype_sptr member(const char* name) const;
163
170 virtual std::pair<void*, Datatype_sptr> member(const char* name, void* data) const;
171
176 virtual Datatype_sptr dereference() const;
177
183 virtual std::pair<void*, Datatype_sptr> dereference(void* data) const;
184
191 virtual void destroy_data(void* ptr) const = 0;
192
197 virtual std::string debug_string() const = 0;
198};
199
200} // namespace PDI
201
202#endif // PDI_DATATYPE_H_
Definition: datatype_template.h:43
A Datatype is a Datatype_template that accepts no argument.
Definition: datatype.h:47
virtual void * data_to_dense_copy(void *to, const void *from) const =0
Creates a dense deep copy of data.
virtual bool dense() const =0
Indicate if the datatype is dense or not.
virtual size_t alignment() const =0
Returns the required alignment for a type.
virtual size_t buffersize() const =0
Computes the data size of a type, including potentially unused memory from a sparse type.
virtual Datatype_sptr slice(size_t start_index, size_t end_index) const
Access the type of the elements slice between the provided indices.
virtual std::pair< void *, Datatype_sptr > slice(size_t start_index, size_t end_index, void *data) const
Access the type and value of the elements slice between the provided indices.
virtual Datatype_sptr member(const char *name) const
Access the type of the member with the provided name.
virtual void destroy_data(void *ptr) const =0
Delete data whose type is described by the Datatype.
virtual void * data_from_dense_copy(void *to, const void *from) const =0
Creates a sparse deep copy of dense data.
Datatype(const Attributes_map &attributes={})
Creates a new datatype.
virtual std::pair< void *, Datatype_sptr > dereference(void *data) const
Access the type and value referenced by this.
virtual size_t datasize() const =0
Computes the data size of a type, excluding potentially unused memory from a sparse type.
virtual Datatype_sptr densify() const =0
Creates a new datatype as the dense copy of this one.
virtual Datatype_sptr dereference() const
Access the type referenced by this.
~Datatype() override
virtual Datatype_sptr index(size_t index) const
Access the type of the element at the provided index.
virtual bool simple() const =0
Tells if data can be copied as bytes (if type is dense) and doesn't need a destroyer.
virtual std::pair< void *, Datatype_sptr > member(const char *name, void *data) const
Access the type and value of the member with the provided name.
virtual std::pair< void *, Datatype_sptr > index(size_t index, void *data) const
Access the type and value of the element at the provided index.
virtual std::string debug_string() const =0
Returns the datatype yaml representation as a string.
Definition: array_datatype.h:38
std::unordered_map< std::string, Expression > Attributes_map
Definition: datatype_template.h:40
std::shared_ptr< const Datatype > Datatype_sptr
Definition: pdi_fwd.h:78