PDI 1.3.0-alpha.2021-07-23.5e78c33

the PDI data interface

pointer_datatype.h
1 /*******************************************************************************
2  * Copyright (C) 2020-2021 Institute of Bioorganic Chemistry Polish Academy of Science (PSNC)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of CEA nor the names of its contributors may be used to
13  * endorse or promote products derived from this software without specific
14  * prior written permission.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  ******************************************************************************/
24 
25 #ifndef PDI_POINTER_DATATYPE_H_
26 #define PDI_POINTER_DATATYPE_H_
27 
28 #include <functional>
29 #include <vector>
30 
31 #include <pdi/pdi_fwd.h>
32 #include <pdi/datatype.h>
33 
34 
35 namespace PDI {
36 
37 class PDI_EXPORT Pointer_datatype:
38  public Datatype
39 {
41  Datatype_uptr m_subtype;
42 
44  std::function<void* (void*, const void*)> m_copy;
45 
47  std::function<void(void*)> m_destroy;
48 
49 public:
52  class Accessor: public Accessor_base
53  {
54  std::string access_kind() const override;
55 
56  public:
57  std::pair<void*, Datatype_uptr> access(const Pointer_datatype& pointer_type,
58  void* from,
59  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_begin,
60  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_end) const override;
61 
62  std::unique_ptr<Accessor_base> clone() const override;
63  };
64 
70  Pointer_datatype(Datatype_uptr subtype, const Attributes_map& attributes = {});
71 
79  Pointer_datatype(Datatype_uptr subtype, std::function<void* (void*, const void*)> copy, std::function<void(void*)> destroy, const Attributes_map& attributes = {});
80 
85  const Datatype& subtype() const;
86 
87  Datatype_template_uptr clone() const override;
88 
89  Datatype_uptr clone_type() const override;
90 
91  Datatype_uptr densify() const override;
92 
93  Datatype_uptr evaluate(Context&) const override;
94 
95  bool dense() const override;
96 
97  size_t datasize() const override;
98 
99  size_t buffersize() const override;
100 
101  size_t alignment() const override;
102 
103  bool simple() const override;
104 
105  void* data_to_dense_copy(void* to, const void* from) const override;
106 
107  void* data_from_dense_copy(void* to, const void* from) const override;
108 
109  std::pair<void*, Datatype_uptr> subaccess_by_iterators(void* from,
110  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_begin,
111  std::vector<std::unique_ptr<Accessor_base>>::const_iterator remaining_end) const override;
112 
113  void destroy_data(void* ptr) const override;
114 
115  std::string debug_string() const override;
116 
117  bool operator== (const Datatype&) const override;
118 
119  Datatype_uptr dereference() const;
120 
121 };
122 
123 } // namespace PDI
124 
125 #endif // PDI_POINTER_DATATYPE_H_
Definition: context.h:42
A Datatype is a Datatype_template that accepts no argument.
Definition: datatype.h:46
Definition: pointer_datatype.h:37
std::unique_ptr< Datatype_template > Datatype_template_uptr
Definition: pdi_fwd.h:74
std::unique_ptr< Datatype > Datatype_uptr
Definition: pdi_fwd.h:78
Accessor for pointer datatype.
Definition: pointer_datatype.h:52
std::unordered_map< std::string, Expression > Attributes_map
Definition: datatype_template.h:40
Definition: array_datatype.h:37