PDI 1.6.0

the PDI data interface

scalar_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_SCALAR_DATATYPE_H_
27#define PDI_SCALAR_DATATYPE_H_
28
29#include <functional>
30#include <string>
31
32#include <pdi/pdi_fwd.h>
33#include <pdi/datatype.h>
34
35
36namespace PDI {
37
38class PDI_EXPORT Scalar_datatype:
39 public Datatype
40{
41 // Required to make_shared due to private ctor
42 struct Shared_enabler;
43
45 size_t m_size;
46
48 size_t m_dense_size;
49
51 size_t m_align;
52
54 Scalar_kind m_kind;
55
57 std::function<void* (void*, const void*)> m_copy;
58
60 std::function<void(void*)> m_destroy;
61
62public:
66
67 Datatype_sptr densify() const override;
68
69 Datatype_sptr evaluate(Context&) const override;
70
71 bool dense() const override;
72
73 size_t datasize() const override;
74
75 size_t buffersize() const override;
76
77 size_t alignment() const override;
78
79 bool simple() const override;
80
81 void* data_to_dense_copy(void* to, const void* from) const override;
82
83 void* data_from_dense_copy(void* to, const void* from) const override;
84
85 void destroy_data(void* ptr) const override;
86
87 std::string debug_string() const override;
88
89 bool operator== (const Datatype&) const override;
90
91private:
98 Scalar_datatype(Scalar_kind kind, size_t size, const Attributes_map& attributes = {});
99
107 Scalar_datatype(Scalar_kind kind, size_t size, size_t align, const Attributes_map& attributes = {});
108
118 Scalar_datatype(Scalar_kind kind, size_t size, size_t align, size_t dense_size, std::function<void* (void*, const void*)> copy, std::function<void(void*)> destroy, const Attributes_map& attributes = {});
119
120public:
127 static std::shared_ptr<Scalar_datatype> make(Scalar_kind kind, size_t size, const Attributes_map& attributes = {});
128
136 static std::shared_ptr<Scalar_datatype> make(Scalar_kind kind, size_t size, size_t align, const Attributes_map& attributes = {});
137
148 static std::shared_ptr<Scalar_datatype> make(Scalar_kind kind, size_t size, size_t align, size_t dense_size, std::function<void* (void*, const void*)> copy, std::function<void(void*)> destroy, const Attributes_map& attributes = {});
149};
150
152
153} // namespace PDI
154
155#endif // PDI_SCALAR_DATATYPE_H_
Definition: context.h:45
A Datatype is a Datatype_template that accepts no argument.
Definition: datatype.h:49
Definition: scalar_datatype.h:40
Datatype_sptr densify() const override
Creates a new datatype as the dense copy of this one.
void * data_from_dense_copy(void *to, const void *from) const override
Creates a sparse deep copy of dense data.
void destroy_data(void *ptr) const override
Delete data whose type is described by the Datatype.
size_t alignment() const override
Returns the required alignment for a type.
static std::shared_ptr< Scalar_datatype > make(Scalar_kind kind, size_t size, size_t align, size_t dense_size, std::function< void *(void *, const void *)> copy, std::function< void(void *)> destroy, const Attributes_map &attributes={})
Creates new scalar datatype.
Scalar_kind kind() const
Interpretation of the content.
std::string debug_string() const override
Returns the datatype yaml representation as a string.
void * data_to_dense_copy(void *to, const void *from) const override
Creates a dense deep copy of data.
size_t buffersize() const override
Computes the data size of a type, including potentially unused memory from a sparse type.
static std::shared_ptr< Scalar_datatype > make(Scalar_kind kind, size_t size, const Attributes_map &attributes={})
Creates new scalar datatype.
bool dense() const override
Indicate if the datatype is dense or not.
static std::shared_ptr< Scalar_datatype > make(Scalar_kind kind, size_t size, size_t align, const Attributes_map &attributes={})
Creates new scalar datatype.
bool simple() const override
Tells if data can be copied as bytes (if type is dense) and doesn't need a destroyer.
size_t datasize() const override
Computes the data size of a type, excluding potentially unused memory from a sparse type.
Datatype_sptr evaluate(Context &) const override
Creates a new datatype by resolving the value of all metadata references.
Definition: array_datatype.h:38
const auto UNDEF_TYPE
Definition: scalar_datatype.h:151
std::unordered_map< std::string, Expression > Attributes_map
Definition: datatype_template.h:40
Scalar_kind
Different possible interpretations for a scalar.
Definition: pdi_fwd.h:101
std::shared_ptr< const Datatype > Datatype_sptr
Definition: pdi_fwd.h:78