PDI 1.5.5

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
37
38namespace PDI {
39
47class PDI_EXPORT Datatype:
49{
50public:
55 Datatype ( const Attributes_map& attributes = {} );
56
57 ~Datatype() override;
58
64 virtual bool operator== ( const Datatype& other ) const = 0;
65
71 bool operator!= ( const Datatype& other ) const;
72
77 virtual Datatype_sptr densify() const = 0;
78
83 virtual bool dense() const = 0;
84
90 virtual size_t datasize() const = 0;
91
97 virtual size_t buffersize() const = 0;
98
103 virtual size_t alignment() const = 0;
104
109 virtual bool simple() const = 0;
110
117 virtual void* data_to_dense_copy ( void* to, const void* from ) const = 0;
118
125 virtual void* data_from_dense_copy ( void* to, const void* from ) const = 0;
126
132 virtual Datatype_sptr index ( size_t index ) const;
133
140 virtual std::pair<void*, Datatype_sptr> index ( size_t index, void* data ) const;
141
148 virtual Datatype_sptr slice ( size_t start_index, size_t end_index ) const;
149
157 virtual std::pair<void*, Datatype_sptr> slice ( size_t start_index, size_t end_index, void* data ) const;
158
164 virtual Datatype_sptr member ( const char* name ) const;
165
172 virtual std::pair<void*, Datatype_sptr> member ( const char* name, void* data ) const;
173
178 virtual Datatype_sptr dereference () const;
179
185 virtual std::pair<void*, Datatype_sptr> dereference ( void* data ) const;
186
193 virtual void destroy_data ( void* ptr ) const = 0;
194
199 virtual std::string debug_string() const = 0;
200
201};
202
203} // namespace PDI
204
205#endif // PDI_DATATYPE_H_
206
207
Definition: datatype_template.h:43
A Datatype is a Datatype_template that accepts no argument.
Definition: datatype.h:49
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