PDI 1.4.3

the PDI data interface

record_datatype.h
1 /*******************************************************************************
2  * Copyright (C) 2015-2019 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 
36 namespace PDI {
37 
42 class PDI_EXPORT Record_datatype:
43  public Datatype
44 {
45 public:
48  class Member_accessor : public Accessor_base
49  {
51  std::string m_member_name;
52 
53  std::string access_kind() const override;
54  public:
59  Member_accessor(const std::string& member_name);
60 
61  std::pair<void*, Datatype_uptr> access(const Record_datatype& record_type,
62  void* from,
63  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_begin,
64  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_end) const override;
65 
66  std::unique_ptr<Accessor_base> clone() const override;
67  };
68 
71  class Member
72  {
74  size_t m_displacement;
75 
77  Datatype_uptr m_type;
78 
80  std::string m_name;
81 
82  public:
89  Member(size_t displacement, Datatype_uptr type, const std::string& name);
90 
95  Member(const Member& o);
96 
101  size_t displacement() const;
102 
107  const Datatype& type() const;
108 
113  const std::string& name() const;
114 
120  bool operator==(const Member& rhs) const;
121 
127  bool operator!=(const Member& rhs) const;
128 
129  };
130 
131 private:
133  std::vector<Member> m_members;
134 
136  size_t m_buffersize;
137 
138 public:
146  Record_datatype(std::vector<Member>&& members, size_t size, const Attributes_map& attributes = {});
147 
150  const std::vector<Member>& members() const;
151 
152 
153  Datatype_template_uptr clone() const override;
154 
155  Datatype_uptr clone_type() const override;
156 
157  Datatype_uptr densify() const override;
158 
159  Datatype_uptr evaluate(Context&) const override;
160 
161  bool dense() const override;
162 
163  size_t datasize() const override;
164 
165  size_t buffersize() const override;
166 
167  size_t alignment() const override;
168 
169  bool simple() const override;
170 
171  void* data_to_dense_copy(void* to, const void*) const override;
172 
173  void* data_from_dense_copy(void* to, const void*) const override;
174 
175  std::pair<void*, Datatype_uptr> subaccess_by_iterators(void* from,
176  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_begin,
177  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_end) const override;
178 
179  void destroy_data(void*) const override;
180 
181  std::string debug_string() const override;
182 
183  bool operator== (const Datatype&) const override;
184 
185 };
186 
187 } // namespace PDI
188 
189 #endif // PDI_RECORD_DATATYPE_H_
Definition: context.h:44
A Datatype is a Datatype_template that accepts no argument.
Definition: datatype.h:46
std::unique_ptr< Datatype_template > Datatype_template_uptr
Definition: pdi_fwd.h:70
std::unique_ptr< Datatype > Datatype_uptr
Definition: pdi_fwd.h:74
A Record_datatype is a Datatype that represents a fixed number of elements of potentially different t...
Definition: record_datatype.h:42
std::unordered_map< std::string, Expression > Attributes_map
Definition: datatype_template.h:40
Definition: array_datatype.h:37
A Member is one of the elements inside a Record_datatype.
Definition: record_datatype.h:71
Member accessor for record datatype.
Definition: record_datatype.h:48