PDI 1.13.0

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 * Copyright (C) 2026 Julien Bigot <julien@julien-bigot.fr>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * * Neither the name of CEA nor the names of its contributors may be used to
15 * endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 ******************************************************************************/
26
27#ifndef PDI_DATATYPE_TEMPLATE_H_
28#define PDI_DATATYPE_TEMPLATE_H_
29
30#include <memory>
31#include <string>
32#include <unordered_map>
33
34#include <paraconf.h>
35
36#include <pdi/pdi_fwd.h>
37#include <pdi/expression.h>
38
39namespace PDI {
40
41using Attributes_map = std::unordered_map<std::string, Expression>;
42
43class PDI_EXPORT Datatype_template: public std::enable_shared_from_this<Datatype_template>
44{
45protected:
47
48public:
54
61 Datatype_template(PC_tree_t datatype_tree);
62
66
72 virtual Datatype_sptr evaluate(Context& ctx) const = 0;
73
79 Expression attribute(const std::string& attribute_name) const;
80
85 const Attributes_map& attributes() const;
86
93 static void load_basic_datatypes(Logger& logger, Context& ctx);
94
101 static void load_user_datatypes(Context& ctx, PC_tree_t types_tree);
102};
103
104} // namespace PDI
105
106#endif // PDI_DATATYPE_TEMPLATE_H_
Definition context.h:43
static void load_basic_datatypes(Logger &logger, Context &ctx)
Adds to the context the basic Array, Record, C and Fortran datatypes.
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:46
virtual ~Datatype_template()
Destroys the template.
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
Wrapper for spdlog::logger with additional pattern getter method.
Definition logger.h:44
Definition array_datatype.h:38
std::unordered_map< std::string, Expression > Attributes_map
Definition datatype_template.h:41
std::shared_ptr< const Datatype > Datatype_sptr
Definition pdi_fwd.h:81