PDI 1.9.0-alpha.2025-01-15

the PDI data interface

context.h
1/*******************************************************************************
2 * Copyright (C) 2015-2024 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_CONTEXT_H_
27#define PDI_CONTEXT_H_
28
29#include <functional>
30#include <memory>
31#include <string>
32#include <unordered_map>
33
34#include <pdi/pdi_fwd.h>
35#include <pdi/callbacks.h>
36#include <pdi/data_descriptor.h>
37#include <pdi/datatype_template.h>
38#include <pdi/logger.h>
39#include <pdi/ref_any.h>
40
41namespace PDI {
42
43class PDI_EXPORT Context
44{
45public:
49 {
50 friend class Context;
52 std::unordered_map<std::string, std::unique_ptr<Data_descriptor>>::iterator m_data;
53 Iterator(const std::unordered_map<std::string, std::unique_ptr<Data_descriptor>>::iterator& data);
54 Iterator(std::unordered_map<std::string, std::unique_ptr<Data_descriptor>>::iterator&& data);
55
56 public:
58 Data_descriptor& operator* ();
59 Iterator& operator++ ();
60 bool operator!= (const Iterator&);
61 bool operator== (const Iterator&);
62 };
63
66 typedef std::function<Datatype_template_sptr(Context&, PC_tree_t)> Datatype_template_parser;
67
68protected:
69 Iterator get_iterator(const std::unordered_map<std::string, std::unique_ptr<Data_descriptor>>::iterator& data);
70
71 Iterator get_iterator(std::unordered_map<std::string, std::unique_ptr<Data_descriptor>>::iterator&& data);
72
73public:
74 virtual ~Context();
75
78 virtual Data_descriptor& desc(const std::string& name) = 0;
79
82 virtual Data_descriptor& desc(const char* name) = 0;
83
86 virtual Data_descriptor& operator[] (const std::string& name) = 0;
87
90 virtual Data_descriptor& operator[] (const char* name) = 0;
91
94 virtual Iterator begin() = 0;
95
98 virtual Iterator end() = 0;
99
105 virtual Iterator find(const std::string& name) = 0;
106
110 virtual void event(const char* name) = 0;
111
115 virtual Logger& logger() = 0;
116
120 virtual Callbacks& callbacks() = 0;
121
127 virtual Datatype_template_sptr datatype(PC_tree_t node) = 0;
128
134 virtual void add_datatype(const std::string& name, Datatype_template_parser parser) = 0;
135
137 virtual void finalize_and_exit() = 0;
138};
139
140} // namespace PDI
141
142#endif // PDI_CONTEXT_H_
Definition callbacks.h:39
An iterator used to go through the descriptor store.
Definition context.h:49
Data_descriptor * operator->()
Definition context.h:44
virtual Data_descriptor & desc(const char *name)=0
Accesses the descriptor for a specific name.
Iterator get_iterator(std::unordered_map< std::string, std::unique_ptr< Data_descriptor > >::iterator &&data)
virtual Iterator find(const std::string &name)=0
Find the Data_descriptor corresponding to a given name.
virtual Data_descriptor & desc(const std::string &name)=0
Accesses the descriptor for a specific name.
virtual Datatype_template_sptr datatype(PC_tree_t node)=0
Creates a new datatype template from a paraconf-style config.
Iterator get_iterator(const std::unordered_map< std::string, std::unique_ptr< Data_descriptor > >::iterator &data)
virtual void add_datatype(const std::string &name, Datatype_template_parser parser)=0
Adds new datatype parser to the context.
virtual Logger & logger()=0
Logger getter.
std::function< Datatype_template_sptr(Context &, PC_tree_t)> Datatype_template_parser
A function that parses a PC_tree_t to create a datatype_template.
Definition context.h:66
virtual ~Context()
virtual Iterator end()=0
Returns an iterator past the last descriptor.
virtual void finalize_and_exit()=0
Finalizes PDI and exits application.
virtual Iterator begin()=0
Returns an iterator on the first descriptor.
virtual void event(const char *name)=0
Triggers a PDI "event".
virtual Callbacks & callbacks()=0
Callbacks of the context.
Definition data_descriptor.h:39
Wrapper for spdlog::logger with additional pattern getter method.
Definition logger.h:42
Definition array_datatype.h:38
std::shared_ptr< const Datatype_template > Datatype_template_sptr
Definition pdi_fwd.h:77