DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
model_common_operations.hpp
Go to the documentation of this file.
1// DUNE DAQ modification notice:
2// This file has been modified from the original ATLAS dbe source for the DUNE DAQ project.
3// Fork baseline commit: dbe-02-12-17 (2022-05-12).
4// Renamed since fork: yes (from dbe/model_common_operations.hpp to include/dbe/model_common_operations.hpp).
5
6/*
7 * model_common_operations.hpp
8 *
9 * Created on: Dec 7, 2015
10 * Author: lgeorgop
11 */
12
13#ifndef DBE_MODEL_COMMON_OPERATIONS_HPP_
14#define DBE_MODEL_COMMON_OPERATIONS_HPP_
15
18#include "dbe/treenode.hpp"
19
20#include <QUuid>
21
22#include <boost/scope_exit.hpp>
23
24//------------------------------------------------------------------------------------------
29template<typename T>
30inline void
32{
33 static_cast<T*>(this)->connect(&confaccessor::ref(),
34 SIGNAL(object_deleted(QString const&, dref const&)),
35 static_cast<T*>(this),
36 SLOT(slot_remove_object(QString const&, dref const&)));
37 static_cast<T*>(this)->connect(&confaccessor::ref(),
38 SIGNAL(object_renamed(QString const&, dref const&)),
39 static_cast<T*>(this),
40 SLOT(slot_rename_object(QString const&, dref const&)));
41 static_cast<T*>(this)->connect(&confaccessor::ref(),
42 SIGNAL(object_changed(QString const&, dref const&)),
43 static_cast<T*>(this),
44 SLOT(slot_update_object(QString const&, dref const&)));
45 static_cast<T*>(this)->connect(&confaccessor::ref(),
46 SIGNAL(object_created(QString const&, dref const&)),
47 static_cast<T*>(this),
48 SLOT(slot_create_object(QString const&, dref const&)));
49}
50//------------------------------------------------------------------------------------------
51
52//------------------------------------------------------------------------------------------
53template<typename T>
54inline void
56{
57 type_index oid(static_cast<T*>(this)->lookup(obj));
58
59 if (oid.isValid()) {
60 static_cast<T*>(this)->remove_deleted_object(oid);
61 }
62}
63
64template<typename T>
65inline void
67{
68 type_index oid(static_cast<T*>(this)->lookup(obj));
69
70 if (oid.isValid()) {
71 static_cast<T*>(this)->rename_contained_object(oid, obj);
72 }
73}
74
75template<typename T>
76inline void
78{
79 type_index oid(static_cast<T*>(this)->lookup(obj));
80
81 if (oid.isValid()) {
82 static_cast<T*>(this)->update_contained_object(oid, obj);
83 }
84}
85
86template<typename T>
87inline void
88dbe::model_common_async_operations<T>::update_multiple_objects(std::vector<type_object_info> const& objects)
89{
90 BOOST_SCOPE_EXIT_TPL(this_)
91 {
92 emit static_cast<T*>(this_)->layoutChanged();
93 }
94 BOOST_SCOPE_EXIT_END
95
96 static_cast<T*>(this)->layoutAboutToBeChanged();
97
98 {
99 BOOST_SCOPE_EXIT_TPL(this_)
100 {
101 static_cast<T*>(this_)->blockSignals(false);
102 }
103 BOOST_SCOPE_EXIT_END
104
105 static_cast<T*>(this)->blockSignals(true);
106
107 for (const auto& obj : objects) {
108 static_cast<T*>(this)->update_object(obj);
109 }
110 }
111}
112
113template<typename T>
114inline void
116{
117 type_index oid(static_cast<T*>(this)->lookup(obj));
118
119 if (not oid.isValid()) {
120 static_cast<T*>(this)->create_contained_object(oid, obj);
121 }
122}
123
124template<typename T>
127{
128}
129//------------------------------------------------------------------------------------------
130
131//------------------------------------------------------------------------------------------
132// FOR FUTURE USE
133// template<typename T> inline std::vector<dbe::dref> dbe::model_common_impl<T>::filter_indices(
134// type_indices::iterator b, type_indices::iterator e)
135//{
136// typedef std::set<decltype(b->row())> t_qrows;
137// typedef std::vector<dref> t_objects;
138//
139// t_objects objects_to_act_upon;
140// t_indices indices_to_check;
141//
142// for(t_indices::iterator iter = b ; iter != e ; ++iter)
143// {
144// if(iter->isValid() and iter->column() == 0)
145// {
146// dref o = static_cast<T *>(this)->getobject(*iter);
147// if(o.is_valid())
148// {
149// indices_to_check.push_back(*iter);
150// objects_to_act_upon.push_back(o);
151// }
152// }
153// }
154//
155//}
156//------------------------------------------------------------------------------------------
157
158//------------------------------------------------------------------------------------------
159template<typename T>
160inline bool
161dbe::model_common_impl<T>::delete_objects(type_indices::iterator b, type_indices::iterator e)
162{
163 typedef std::set<decltype(b->row())> t_qrows;
164 typedef std::vector<type_object_info> t_objects;
165 t_objects to_remove_objects;
166
167 for (type_indices::iterator iter = b; iter != e; ++iter) {
168 if (iter->isValid() and iter->column() == 0) {
169 dref o = static_cast<T*>(this)->getobject(*iter);
170
171 if (o.is_valid()) {
172 to_remove_objects.push_back(o);
173 }
174 }
175 }
176
177 t_objects removed_objects;
178
179 for (auto const& o : to_remove_objects) {
180 if (dbe::config::api::commands::delobj(o.ref(), static_cast<T*>(this)->uuid)) {
181 removed_objects.push_back(o);
182 }
183 }
184
185 t_qrows to_remove_rows;
186
187 for (auto const& o : removed_objects) {
188 QModelIndex newloc = static_cast<T*>(this)->lookup(o);
189
190 if (newloc.isValid()) {
191 to_remove_rows.insert(newloc.row());
192 }
193 }
194
195 t_qrows::reverse_iterator uend = to_remove_rows.rbegin();
196
197 if (uend != to_remove_rows.rend()) {
198 for (int count = 0, bottom = *uend, last = bottom; uend != to_remove_rows.rend(); count = 0, bottom = *uend) {
199 for (; uend != to_remove_rows.rend() and count == bottom - *uend; last = *uend, ++uend, ++count)
200 ;
201
202 static_cast<T*>(this)->removeRows(last, count, b->parent());
203 }
204
205 return true;
206 }
207
208 return false;
209}
210//------------------------------------------------------------------------------------------
211
212//------------------------------------------------------------------------------------------
213template<typename T>
214inline bool
215dbe::model_common_impl<T>::update_objects(type_indices::iterator b, type_indices::iterator e)
216{
217 Q_UNUSED(b);
218 Q_UNUSED(e);
219 return false;
220}
221//------------------------------------------------------------------------------------------
222
223//------------------------------------------------------------------------------------------
224template<typename T>
225inline bool
226dbe::model_common_impl<T>::create_objects(type_indices::iterator b, type_indices::iterator e)
227{
228 Q_UNUSED(b);
229 Q_UNUSED(e);
230 return false;
232//------------------------------------------------------------------------------------------
233
234#endif /* DBE_MODEL_COMMON_OPERATIONS_HPP_ */
static confaccessor & ref()
inner::configobject::tref ref() const
void update_multiple_objects(std::vector< type_object_info > const &)
void remove_object(type_object_info const &)
void rename_object(type_object_info const &)
void update_object(type_object_info const &)
MODEL_COMMON_TYPES_TOPLEVEL_DEFINITIONS model_common_async_operations()
void create_object(type_object_info const &)
bool create_objects(type_indices::iterator, type_indices::iterator) override
bool delete_objects(type_indices::iterator, type_indices::iterator) override
bool update_objects(type_indices::iterator, type_indices::iterator) override
#define MODEL_COMMON_INTERFACE_UUID_DECL
bool delobj(inner::configobject::tref obj, QUuid const &src)
config_object_description dref