PDI 0.4.1

Data exchange made easy

scalar_datatype.h
1 /*******************************************************************************
2  * Copyright (C) 2015-2019 Commissariat a l'energie atomique et aux energies alternatives (CEA)
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_SCALAR_DATATYPE_H_
26 #define PDI_SCALAR_DATATYPE_H_
27 
28 #include <functional>
29 
30 #include <pdi/pdi_fwd.h>
31 #include <pdi/datatype.h>
32 
33 
34 namespace PDI {
35 
36 class PDI_EXPORT Scalar_datatype:
37  public Datatype
38 {
40  size_t m_size;
41 
43  size_t m_dense_size;
44 
46  size_t m_align;
47 
49  Scalar_kind m_kind;
50 
52  std::function<void* (void*, const void*)> m_copy;
53 
55  std::function<void(void*)> m_destroy;
56 
57 public:
58  Scalar_datatype(Scalar_kind kind, size_t size);
59 
60  Scalar_datatype(Scalar_kind kind, size_t size, size_t align);
61 
62  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);
63 
66  Scalar_kind kind() const;
67 
68  Datatype_template_uptr clone() const override;
69 
70  Datatype_uptr clone_type() const override;
71 
72  Datatype_uptr densify() const override;
73 
74  Datatype_uptr evaluate(Context&) const override;
75 
76  bool dense() const override;
77 
78  size_t datasize() const override;
79 
80  size_t buffersize() const override;
81 
82  size_t alignment() const override;
83 
84  bool simple() const override;
85 
86  void* data_to_dense_copy(void* to, const void* from) const override;
87 
88  void* data_from_dense_copy(void* to, const void* from) const override;
89 
90  void destroy_data(void* ptr) const override;
91 
92  std::string debug_string() const override;
93 
94  bool operator== (const Datatype&) const override;
95 
96 };
97 
99 
100 } // namespace PDI
101 
102 #endif // PDI_SCALAR_DATATYPE_H_
Definition: context.h:44
Definition: scalar_datatype.h:36
A Datatype is a Datatype_template that accepts no argument.
Definition: datatype.h:40
std::unique_ptr< Datatype_template > Datatype_template_uptr
Definition: pdi_fwd.h:58
std::unique_ptr< Datatype > Datatype_uptr
Definition: pdi_fwd.h:62
Scalar_kind
Different possible interpretations for a scalar.
Definition: pdi_fwd.h:89
const Scalar_datatype UNDEF_TYPE
Definition: scalar_datatype.h:98
Definition: array_datatype.h:31