PDI 1.3.0-alpha.2021-06-18.f8a290a

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 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:
145  Record_datatype(std::vector<Member>&& members, size_t size);
146 
149  const std::vector<Member>& members() const;
150 
151 
152  Datatype_template_uptr clone() const override;
153 
154  Datatype_uptr clone_type() const override;
155 
156  Datatype_uptr densify() const override;
157 
158  Datatype_uptr evaluate(Context&) const override;
159 
160  bool dense() const override;
161 
162  size_t datasize() const override;
163 
164  size_t buffersize() const override;
165 
166  size_t alignment() const override;
167 
168  bool simple() const override;
169 
170  void* data_to_dense_copy(void* to, const void*) const override;
171 
172  void* data_from_dense_copy(void* to, const void*) const override;
173 
174  std::pair<void*, Datatype_uptr> subaccess_by_iterators(void* from,
175  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_begin,
176  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_end) const override;
177 
178  void destroy_data(void*) const override;
179 
180  std::string debug_string() const override;
181 
182  bool operator== (const Datatype&) const override;
183 
184 };
185 
186 } // namespace PDI
187 
188 #endif // PDI_RECORD_DATATYPE_H_
Definition: context.h:42
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:74
std::unique_ptr< Datatype > Datatype_uptr
Definition: pdi_fwd.h:78
A Record_datatype is a Datatype that represents a fixed number of elements of potentially different t...
Definition: record_datatype.h:42
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