PDI 0.6.1

Data exchange made easy

context.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_CONTEXT_H_
26 #define PDI_CONTEXT_H_
27 
28 #include <functional>
29 #include <memory>
30 #include <string>
31 #include <unordered_map>
32 
33 #include <pdi/pdi_fwd.h>
34 #include <pdi/data_descriptor.h>
35 #include <pdi/datatype_template.h>
36 #include <pdi/ref_any.h>
37 
38 
39 namespace PDI {
40 
41 class PDI_EXPORT Context
42 {
43 public:
46  class Iterator
47  {
48  friend class Context;
50  std::unordered_map<std::string, std::unique_ptr<Data_descriptor>>::iterator m_data;
51  Iterator(const std::unordered_map<std::string, std::unique_ptr<Data_descriptor>>::iterator& data);
52  Iterator(std::unordered_map<std::string, std::unique_ptr<Data_descriptor>>::iterator&& data);
53  public:
54  Data_descriptor* operator-> ();
55  Data_descriptor& operator* ();
56  Iterator& operator++ ();
57  bool operator!= (const Iterator&);
58  };
59 
62  typedef std::function<Datatype_template_uptr(Context&, PC_tree_t)> Datatype_template_parser;
63 
64 protected:
65  Iterator get_iterator(const std::unordered_map<std::string, std::unique_ptr<Data_descriptor>>::iterator& data);
66 
67  Iterator get_iterator(std::unordered_map<std::string, std::unique_ptr<Data_descriptor>>::iterator&& data);
68 
69 public:
70  virtual ~Context();
71 
74  virtual Data_descriptor& desc(const std::string& name) = 0;
75 
78  virtual Data_descriptor& desc(const char* name) = 0;
79 
82  virtual Data_descriptor& operator[](const std::string& name) = 0;
83 
86  virtual Data_descriptor& operator[](const char* name) = 0;
87 
90  virtual Iterator begin() = 0;
91 
94  virtual Iterator end() = 0;
95 
99  virtual void event(const char* name) = 0;
100 
101  virtual Logger_sptr logger() const = 0;
102 
108  virtual Datatype_template_uptr datatype(PC_tree_t node) = 0;
109 
115  virtual void add_datatype(const std::string& name, Datatype_template_parser parser) = 0;
116 
123  virtual std::function<void()> add_init_callback(const std::function<void()>& callback) = 0;
124 
132  virtual std::function<void()> add_data_callback(const std::function<void(const std::string&, Ref)>& callback, const std::string& name = {}) = 0;
133 
141  virtual std::function<void()> add_event_callback(const std::function<void(const std::string&)>& callback, const std::string& name = {}) = 0;
142 
150  virtual std::function<void()> add_empty_desc_access_callback(const std::function<void(const std::string&)>& callback, const std::string& name = {}) = 0;
151 
152 };
153 
154 } // namespace PDI
155 
156 #endif // PDI_CONTEXT_H_
Definition: context.h:41
std::shared_ptr< spdlog::logger > Logger_sptr
A shared pointer to a logger instance.
Definition: pdi_fwd.h:67
A dynamically typed reference to data with automatic memory management and read/write locking semanti...
Definition: pdi_fwd.h:77
std::unique_ptr< Datatype_template > Datatype_template_uptr
Definition: pdi_fwd.h:58
Definition: data_descriptor.h:39
An iterator used to go through the descriptor store.
Definition: context.h:46
Definition: array_datatype.h:33
std::function< Datatype_template_uptr(Context &, PC_tree_t)> Datatype_template_parser
A function that parses a PC_tree_t to create a datatype_template.
Definition: context.h:62