PDI 1.5.4

the PDI data interface

datatype_template.h
1/*******************************************************************************
2 * Copyright (C) 2015-2021 Commissariat a l'energie atomique et aux energies alternatives (CEA)
3 * Copyright (C) 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_DATATYPE_TEMPLATE_H_
27#define PDI_DATATYPE_TEMPLATE_H_
28
29#include <memory>
30#include <string>
31#include <unordered_map>
32
33#include <paraconf.h>
34
35#include <pdi/expression.h>
36#include <pdi/pdi_fwd.h>
37
38namespace PDI {
39
40using Attributes_map = std::unordered_map<std::string, Expression>;
41
42class PDI_EXPORT Datatype_template: public std::enable_shared_from_this<Datatype_template>
43{
44protected:
46
47public:
52 Datatype_template(const Attributes_map& attributes = {});
53
60 Datatype_template(PC_tree_t datatype_tree);
61
65
71 virtual Datatype_sptr evaluate(Context& ctx) const = 0;
72
78 Expression attribute(const std::string& attribute_name) const;
79
84 const Attributes_map& attributes() const;
85
91 static void load_basic_datatypes(Context& ctx);
92
99 static void load_user_datatypes(Context& ctx, PC_tree_t types_tree);
100
101};
102
103} // namespace PDI
104
105#endif // PDI_DATATYPE_TEMPLATE_H_
106
Definition: context.h:45
Definition: datatype_template.h:43
virtual Datatype_sptr evaluate(Context &ctx) const =0
Creates a new datatype by resolving the value of all metadata references.
Datatype_template(PC_tree_t datatype_tree)
Creates datatype template.
const Attributes_map & attributes() const
Returns all attributes as a unordered map.
Attributes_map m_attributes
Definition: datatype_template.h:45
virtual ~Datatype_template()
Destroys the template.
static void load_basic_datatypes(Context &ctx)
Adds to the context the basic Array, Record, C and Fortran datatypes.
Datatype_template(const Attributes_map &attributes={})
Creates datatype template with given attributes.
static void load_user_datatypes(Context &ctx, PC_tree_t types_tree)
Adds to the context the user defined datatypes.
Expression attribute(const std::string &attribute_name) const
Returns attribute of given name as Expression.
Definition: expression.h:42
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