PDI 1.5.5

the PDI data interface

record_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_RECORD_DATATYPE_H_
27#define PDI_RECORD_DATATYPE_H_
28
29#include <string>
30#include <vector>
31
32#include <pdi/pdi_fwd.h>
33#include <pdi/datatype.h>
34
35
36namespace PDI {
37
42class PDI_EXPORT Record_datatype:
43 public Datatype
44{
45 // Required to make_shared due to private ctor
46 struct Shared_enabler;
47
48public:
51 class Member
52 {
54 size_t m_displacement;
55
57 Datatype_sptr m_type;
58
60 std::string m_name;
61
62 public:
69 Member(size_t displacement, Datatype_sptr type, const std::string& name);
70
75 Member(const Member& o);
76
81 size_t displacement() const;
82
88
93 const std::string& name() const;
94
100 bool operator==(const Member& rhs) const;
101
107 bool operator!=(const Member& rhs) const;
108
109 };
110
111private:
113 std::vector<Member> m_members;
114
116 size_t m_buffersize;
117
118public:
121 const std::vector<Member>& members() const;
122
123 Datatype_sptr densify() const override;
124
126
127 bool dense() const override;
128
129 size_t datasize() const override;
130
131 size_t buffersize() const override;
132
133 size_t alignment() const override;
134
135 bool simple() const override;
136
137 void* data_to_dense_copy(void* to, const void*) const override;
138
139 void* data_from_dense_copy(void* to, const void*) const override;
140
141 Datatype_sptr member ( const char* name ) const override;
142
143 std::pair<void*, Datatype_sptr> member ( const char* name, void* data ) const override;
144
145 void destroy_data(void*) const override;
146
147 std::string debug_string() const override;
148
149 bool operator== (const Datatype&) const override;
150
151private:
159 Record_datatype(std::vector<Member>&& members, size_t size, const Attributes_map& attributes = {});
160
161public:
169 static std::shared_ptr<Record_datatype> make(std::vector<Member>&& members, size_t size, const Attributes_map& attributes = {});
170
171};
172
173} // namespace PDI
174
175#endif // PDI_RECORD_DATATYPE_H_
Definition: context.h:45
A Datatype is a Datatype_template that accepts no argument.
Definition: datatype.h:49
A Member is one of the elements inside a Record_datatype.
Definition: record_datatype.h:52
Member(const Member &o)
Construct a new member by copy.
bool operator==(const Member &rhs) const
Tests another member for equality.
const std::string & name() const
Access the name of this specific member.
Datatype_sptr type() const
Access the type of the contained member.
size_t displacement() const
Access the offset or distance in byte from the Record_datatype start.
bool operator!=(const Member &rhs) const
Tests another member for inequality.
Member(size_t displacement, Datatype_sptr type, const std::string &name)
Construct a new member.
A Record_datatype is a Datatype that represents a fixed number of elements of potentially different t...
Definition: record_datatype.h:44
static std::shared_ptr< Record_datatype > make(std::vector< Member > &&members, size_t size, const Attributes_map &attributes={})
Constructs a new Record_datatype.
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.
void * data_to_dense_copy(void *to, const void *) const override
Creates a dense deep copy of data.
bool simple() const override
Tells if data can be copied as bytes (if type is dense) and doesn't need a destroyer.
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.
Datatype_sptr evaluate(Context &) const override
Creates a new datatype by resolving the value of all metadata references.
Datatype_sptr densify() const override
Creates a new datatype as the dense copy of this one.
bool dense() const override
Indicate if the datatype is dense or not.
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.
void destroy_data(void *) const override
Delete data whose type is described by the Datatype.
const std::vector< Member > & members() const
Accesses the members in increasing displacement order.
size_t buffersize() const override
Computes the data size of a type, including potentially unused memory from a sparse type.
void * data_from_dense_copy(void *to, const void *) const override
Creates a sparse deep copy of dense data.
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