DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
change_enum.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/change_enum.hpp to include/dbe/change_enum.hpp).
5
6/*
7 * change_enum.hpp
8 *
9 * Created on: Nov 10, 2015
10 * Author: lgeorgop
11 */
12
13#ifndef DBE_CHANGE_ENUM_HPP_
14#define DBE_CHANGE_ENUM_HPP_
15
16#include "dbe/Command.hpp"
17#include "dbe/Exceptions.hpp"
18#include "dbe/confaccessor.hpp"
21#include "dbe/messenger.hpp"
22
24#include "conffwk/Errors.hpp"
25#include "conffwk/Schema.hpp"
26
27#include <QtCore/qobject.h>
28#include <QtCore/qstring.h>
29#include <QtCore/qstringlist.h>
30
31#include <string>
32
33namespace dbe {
34namespace actions {
35//------------------------------------------------------------------------------------------
36template<typename T>
37class ChangeEnum : public onobject
38{
39public:
40 ChangeEnum(tref Object, dunedaq::conffwk::attribute_t AttributeData, T NewValueData, QUndoCommand* parent = nullptr);
41 void undo();
42 void redo();
43
44private:
48 bool Success;
49};
50
51template<typename T>
54 T NewValueData,
55 QUndoCommand* parent)
56 : onobject(Object, parent)
57 , NewValue(NewValueData)
58 , Attribute(AttributeData)
59 , Success(true)
60{
61 try {
64 } catch (dunedaq::conffwk::Exception const& e) {
65 Q_UNUSED(e)
66 }
67
68 setText(
69 QObject::tr("Attribute %1 of object %2 was updated.").arg(AttributeData.p_name.c_str()).arg(Object.UID().c_str()));
70}
71
72template<typename T>
73void
75{
76 try {
77 if (isvalid()) {
78 failed();
80 toggle();
81 }
82 } catch (dunedaq::conffwk::Exception const& e) {
83 Success = false;
84 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, e);
85 } catch (daq::dbe::config_object_retrieval_result_is_null const& ex) {
86 FAIL("Operation did not complete because a lookup in the underlying database failed", ex.what());
87 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, ex);
88 }
89}
90
91template<typename T>
92void
94{
95 try {
96 if (isvalid()) {
97 failed();
98
100
101 OldValue = convert::to<T>(Data, Attribute.p_int_format);
102
104
105 toggle();
106 }
107 } catch (dunedaq::conffwk::Exception const& e) {
108 Success = false;
109 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, e);
110 } catch (daq::dbe::config_object_retrieval_result_is_null const& ex) {
111 FAIL("Operation did not complete because a lookup in the underlying database failed", ex.what());
112 throw daq::dbe::ObjectChangeWasNotSuccessful(ERS_HERE, ex);
113 }
114}
115//------------------------------------------------------------------------------------------
116}
117} // namespace dbe
118#endif /* DBE_CHANGE_ENUM_HPP_ */
#define ERS_HERE
dunedaq::conffwk::attribute_t Attribute
ChangeEnum(tref Object, dunedaq::conffwk::attribute_t AttributeData, T NewValueData, QUndoCommand *parent=nullptr)
tref checkedref() const
Definition Command.cpp:412
onobject(tref obj, QUndoCommand *parent=nullptr, QUuid const &uuid=0)
Definition Command.cpp:403
bool isvalid() const
Definition Command.cpp:445
void failed() const
Definition Command.cpp:437
static T list(dbe::inner::configobject::tref obj, dunedaq::conffwk::attribute_t const &attr)
#define FAIL(...)
void anenum(inner::configobject::tref Object, dunedaq::conffwk::attribute_t const &AttributeData, T NewValueData, bool NotEmit=false)
T to(QStringList const &DataList)
Include QT Headers.
inner::configobject::tref tref
Definition tref.hpp:36