PDI 1.7.1

the PDI data interface

pointer_datatype.h
1/*******************************************************************************
2 * Copyright (C) 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_POINTER_DATATYPE_H_
27#define PDI_POINTER_DATATYPE_H_
28
29#include <functional>
30#include <vector>
31
32#include <pdi/pdi_fwd.h>
33#include <pdi/datatype.h>
34
35namespace PDI {
36
37class PDI_EXPORT Pointer_datatype: public Datatype
38{
39 // Required to make_shared due to private ctor
40 struct Shared_enabler;
41
43 Datatype_sptr m_subtype;
44
46 std::function<void* (void*, const void*)> m_copy;
47
49 std::function<void(void*)> m_destroy;
50
51public:
57
58 Datatype_sptr densify() const override;
59
60 Datatype_sptr evaluate(Context&) const override;
61
62 bool dense() const override;
63
64 size_t datasize() const override;
65
66 size_t buffersize() const override;
67
68 size_t alignment() const override;
69
70 bool simple() const override;
71
72 void* data_to_dense_copy(void* to, const void* from) const override;
73
74 void* data_from_dense_copy(void* to, const void* from) const override;
75
76 Datatype_sptr index(size_t index) const override;
77
78 std::pair<void*, Datatype_sptr> index(size_t index, void* data) const override;
79
80 Datatype_sptr slice(size_t start_index, size_t end_index) const override;
81
82 std::pair<void*, Datatype_sptr> slice(size_t start_index, size_t end_index, void* data) const override;
83
84 Datatype_sptr member(const char* name) const override;
85
86 std::pair<void*, Datatype_sptr> member(const char* name, void* data) const override;
87
88 Datatype_sptr dereference() const override;
89
90 std::pair<void*, Datatype_sptr> dereference(void* data) const override;
91
92 void destroy_data(void* ptr) const override;
93
94 std::string debug_string() const override;
95
96 bool operator== (const Datatype&) const override;
97
98private:
104 Pointer_datatype(Datatype_sptr subtype, const Attributes_map& attributes = {});
105
114 Datatype_sptr subtype,
115 std::function<void* (void*, const void*)> copy,
116 std::function<void(void*)> destroy,
117 const Attributes_map& attributes = {}
118 );
119
120public:
126 static std::shared_ptr<Pointer_datatype> make(Datatype_sptr subtype, const Attributes_map& attributes = {});
127
135 static std::shared_ptr<Pointer_datatype> make(
136 Datatype_sptr subtype,
137 std::function<void* (void*, const void*)> copy,
138 std::function<void(void*)> destroy,
139 const Attributes_map& attributes = {}
140 );
141};
142
143} // namespace PDI
144
145#endif // PDI_POINTER_DATATYPE_H_
Definition: context.h:44
A Datatype is a Datatype_template that accepts no argument.
Definition: datatype.h:47
Definition: pointer_datatype.h:38
Datatype_sptr subtype() const
Type of the pointed element.
static std::shared_ptr< Pointer_datatype > make(Datatype_sptr subtype, const Attributes_map &attributes={})
Creates new pointer datatype.
void destroy_data(void *ptr) const override
Delete data whose type is described by the Datatype.
Datatype_sptr densify() const override
Creates a new datatype as the dense copy of this one.
Datatype_sptr evaluate(Context &) const override
Creates a new datatype by resolving the value of all metadata references.
void * data_from_dense_copy(void *to, const void *from) const override
Creates a sparse deep copy of dense data.
size_t alignment() const override
Returns the required alignment for a type.
std::string debug_string() const override
Returns the datatype yaml representation as a string.
std::pair< void *, Datatype_sptr > member(const char *name, void *data) const override
Access the type and value of the member with the provided name.
size_t buffersize() const override
Computes the data size of a type, including potentially unused memory from a sparse type.
std::pair< void *, Datatype_sptr > slice(size_t start_index, size_t end_index, void *data) const override
Access the type and value of the elements slice between the provided indices.
bool dense() const override
Indicate if the datatype is dense or not.
void * data_to_dense_copy(void *to, const void *from) const override
Creates a dense deep copy of data.
Datatype_sptr slice(size_t start_index, size_t end_index) const override
Access the type of the elements slice between the provided indices.
bool simple() const override
Tells if data can be copied as bytes (if type is dense) and doesn't need a destroyer.
std::pair< void *, Datatype_sptr > index(size_t index, void *data) const override
Access the type and value of the element at the provided index.
static std::shared_ptr< Pointer_datatype > make(Datatype_sptr subtype, std::function< void *(void *, const void *)> copy, std::function< void(void *)> destroy, const Attributes_map &attributes={})
Creates new pointer datatype.
Datatype_sptr index(size_t index) const override
Access the type of the element at the provided index.
Datatype_sptr member(const char *name) const override
Access the type of the member with the provided name.
size_t datasize() const override
Computes the data size of a type, excluding potentially unused memory from a sparse type.
std::pair< void *, Datatype_sptr > dereference(void *data) const override
Access the type and value referenced by this.
Datatype_sptr dereference() const override
Access the type referenced by this.
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