PDI 1.7.1

the PDI data interface

callbacks.h
1/*******************************************************************************
2 * Copyright (C) 2020 Institute of Bioorganic Chemistry Polish Academy of Science (PSNC)
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_CALLBACKS_H_
26#define PDI_CALLBACKS_H_
27
28#include <functional>
29#include <list>
30#include <map>
31#include <string>
32
33#include "pdi/pdi_fwd.h"
34#include "pdi/ref_any.h"
35
36namespace PDI {
37
38class PDI_EXPORT Callbacks
39{
41 Context& m_context;
42
48 std::list<std::function<void()>> m_init_callbacks;
49
55 std::list<std::function<void(const std::string&, Ref)>> m_data_callbacks;
56
62 std::multimap<std::string, std::function<void(const std::string&, Ref)>> m_named_data_callbacks;
63
69 std::list<std::function<void(const std::string&, Ref)>> m_data_remove_callbacks;
70
76 std::multimap<std::string, std::function<void(const std::string&, Ref)>> m_named_data_remove_callbacks;
77
83 std::list<std::function<void(const std::string&)>> m_event_callbacks;
84
90 std::multimap<std::string, std::function<void(const std::string&)>> m_named_event_callbacks;
91
97 std::list<std::function<void(const std::string&)>> m_empty_desc_access_callbacks;
98
104 std::multimap<std::string, std::function<void(const std::string&)>> m_named_empty_desc_access_callbacks;
105
106public:
108
115 std::function<void()> add_init_callback(const std::function<void()>& callback);
116
124 std::function<void()> add_data_callback(const std::function<void(const std::string&, Ref)>& callback, const std::string& name = {});
125
133 std::function<void()> add_data_remove_callback(const std::function<void(const std::string&, Ref)>& callback, const std::string& name = {});
134
142 std::function<void()> add_event_callback(const std::function<void(const std::string&)>& callback, const std::string& name = {});
143
151 std::function<void()> add_empty_desc_access_callback(const std::function<void(const std::string&)>& callback, const std::string& name = {});
152
155
160 void call_data_callbacks(const std::string& name, Ref ref) const;
161
166 void call_data_remove_callbacks(const std::string& name, Ref ref) const;
167
171 void call_event_callbacks(const std::string& name) const;
172
176 void call_empty_desc_access_callbacks(const std::string& name) const;
177};
178
179} // namespace PDI
180
181
182#endif //PDI_CALLBACKS_H_
Definition: callbacks.h:39
std::function< void()> add_init_callback(const std::function< void()> &callback)
Adds new init callback to context.
std::function< void()> add_data_callback(const std::function< void(const std::string &, Ref)> &callback, const std::string &name={})
Adds new data callback to context.
std::function< void()> add_data_remove_callback(const std::function< void(const std::string &, Ref)> &callback, const std::string &name={})
Adds new data callback to context.
std::function< void()> add_event_callback(const std::function< void(const std::string &)> &callback, const std::string &name={})
Adds new event callback to context.
void call_data_remove_callbacks(const std::string &name, Ref ref) const
Calls data remove callbacks.
void call_empty_desc_access_callbacks(const std::string &name) const
Calls empty desc callbacks.
Callbacks(Context &ctx)
void call_event_callbacks(const std::string &name) const
Calls event callbacks.
void call_data_callbacks(const std::string &name, Ref ref) const
Calls data callbacks.
std::function< void()> add_empty_desc_access_callback(const std::function< void(const std::string &)> &callback, const std::string &name={})
Adds new empty desc access callback to context.
void call_init_callbacks() const
Calls init callbacks.
Definition: context.h:44
A dynamically typed reference to data with automatic memory management and read/write locking semanti...
Definition: ref_any.h:248
Definition: array_datatype.h:38