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/confaccessor.hpp"
19#include "dbe/Command.hpp"
20#include "dbe/Exceptions.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
34{
35namespace actions
36{
37//------------------------------------------------------------------------------------------
38template<typename T>
40 public onobject
41{
42public:
43 ChangeEnum ( tref Object, dunedaq::conffwk::attribute_t AttributeData, T NewValueData,
44 QUndoCommand * parent = nullptr );
45 void undo();
46 void redo();
47
48private:
52 bool Success;
53};
54
55template<typename T>
57 T NewValueData, QUndoCommand * parent )
58 : onobject ( Object, parent ),
59 NewValue ( NewValueData ),
60 Attribute ( AttributeData ),
61 Success ( true )
62{
63 try
64 {
65 QStringList Data
67 OldValue = convert::to<T> ( Data );
68 }
69 catch ( dunedaq::conffwk::Exception const & e )
70 {
71 Q_UNUSED ( e )
72 }
73
74 setText (
75 QObject::tr ( "Attribute %1 of object %2 was updated." ).arg (
76 AttributeData.p_name.c_str() ).arg ( Object.UID().c_str() ) );
77}
78
79template<typename T>
81{
82 try
83 {
84 if ( isvalid() )
85 {
86 failed();
88 toggle();
89 }
90 }
91 catch ( dunedaq::conffwk::Exception const & e )
92 {
93 Success = false;
94 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, e );
95 }
96 catch ( daq::dbe::config_object_retrieval_result_is_null const & ex )
97 {
98 FAIL ( "Operation did not complete because a lookup in the underlying database failed",
99 ex.what() );
100 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, ex );
101 }
102
103}
104
105template<typename T>
107{
108 try
109 {
110 if ( isvalid() )
111 {
112 failed();
113
114 QStringList Data
116
117 OldValue = convert::to<T> ( Data, Attribute.p_int_format );
118
120
121 toggle();
122 }
123 }
124 catch ( dunedaq::conffwk::Exception const & e )
125 {
126 Success = false;
127 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, e );
128 }
129 catch ( daq::dbe::config_object_retrieval_result_is_null const & ex )
130 {
131 FAIL ( "Operation did not complete because a lookup in the underlying database failed",
132 ex.what() );
133 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, ex );
134 }
135
136}
137//------------------------------------------------------------------------------------------
138}
139} // namespace dbe
140#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:518
onobject(tref obj, QUndoCommand *parent=nullptr, QUuid const &uuid=0)
Definition Command.cpp:510
bool isvalid() const
Definition Command.cpp:548
void failed() const
Definition Command.cpp:541
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:35