PDI 1.7.0-alpha.2023-10-26

the PDI data interface

array_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_ARRAY_DATATYPE_H_
27#define PDI_ARRAY_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.h>
36#include <pdi/tuple_datatype.h>
37
38namespace PDI {
39
44class PDI_EXPORT Array_datatype: public Datatype
45{
46 // Required to make_shared due to private ctor
47 struct Shared_enabler;
48
50 Datatype_sptr m_subtype;
51
53 size_t m_size;
54
56 size_t m_start;
57
59 size_t m_subsize;
60
61public:
67
71 size_t size() const;
72
77 size_t start() const;
78
83 size_t subsize() const;
84
85 Datatype_sptr densify() const override;
86
87 Datatype_sptr evaluate(Context&) const override;
88
89 bool dense() const override;
90
91 size_t datasize() const override;
92
93 size_t buffersize() const override;
94
95 size_t alignment() const override;
96
97 bool simple() const override;
98
99 void* data_to_dense_copy(void*, const void*) const override;
100
101 void* data_from_dense_copy(void*, const void*) const override;
102
103 Datatype_sptr index(size_t index) const override;
104
105 std::pair<void*, Datatype_sptr> index(size_t index, void* data) const override;
106
107 Datatype_sptr slice(size_t start_index, size_t end_index) const override;
108
109 std::pair<void*, Datatype_sptr> slice(size_t start_index, size_t end_index, void* data) const override;
110
111 void destroy_data(void*) const override;
112
113 std::string debug_string() const override;
114
115 bool operator== (const Datatype&) const override;
116
125 static std::shared_ptr<Array_datatype>
126 make(Datatype_sptr subtype, size_t size, size_t start, size_t subsize, const Attributes_map& attributes = {});
127
134 static std::shared_ptr<Array_datatype> make(Datatype_sptr subtype, size_t size, const Attributes_map& attributes = {});
135
136private:
145 Array_datatype(Datatype_sptr subtype, size_t size, size_t start, size_t subsize, const Attributes_map& attributes = {});
146
153 Array_datatype(Datatype_sptr subtype, size_t size, const Attributes_map& attributes = {});
154};
155
156} // namespace PDI
157
158#endif // PDI_ARRAY_DATATYPE_H_
an Array_datatype is a Datatype that represents an array: i.e storage of multiple elements of the sam...
Definition: array_datatype.h:45
size_t datasize() const override
Computes the data size of a type, excluding potentially unused memory from a sparse type.
size_t size() const
Number of elements the array can store.
bool dense() const override
Indicate if the datatype is dense or not.
static std::shared_ptr< Array_datatype > make(Datatype_sptr subtype, size_t size, const Attributes_map &attributes={})
Construct a new completely filled Array_datatype.
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.
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.
Datatype_sptr index(size_t index) const override
Access the type of the element at the provided index.
void * data_from_dense_copy(void *, const void *) const override
Creates a sparse deep copy of dense data.
bool simple() const override
Tells if data can be copied as bytes (if type is dense) and doesn't need a destroyer.
static std::shared_ptr< Array_datatype > make(Datatype_sptr subtype, size_t size, size_t start, size_t subsize, const Attributes_map &attributes={})
Construct a new partially filled Array_datatype.
Datatype_sptr slice(size_t start_index, size_t end_index) const override
Access the type of the elements slice between the provided indices.
void * data_to_dense_copy(void *, const void *) const override
Creates a dense deep copy of data.
size_t subsize() const
Number of actual elements in the array.
void destroy_data(void *) const override
Delete data whose type is described by the Datatype.
size_t start() const
id of the first actual element of the array
size_t buffersize() const override
Computes the data size of a type, including potentially unused memory from a sparse type.
std::string debug_string() const override
Returns the datatype yaml representation as a string.
size_t alignment() const override
Returns the required alignment for a 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.
Datatype_sptr subtype() const
Type of the elements contained in the array.
Definition: context.h:44
A Datatype is a Datatype_template that accepts no argument.
Definition: datatype.h:47
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