DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
change_enum.hpp
Go to the documentation of this file.
1/*
2 * change_enum.hpp
3 *
4 * Created on: Nov 10, 2015
5 * Author: lgeorgop
6 */
7
8#ifndef DBE_CHANGE_ENUM_HPP_
9#define DBE_CHANGE_ENUM_HPP_
10
11#include "dbe/confaccessor.hpp"
14#include "dbe/Command.hpp"
15#include "dbe/Exceptions.hpp"
16#include "dbe/messenger.hpp"
17
19#include "conffwk/Errors.hpp"
20#include "conffwk/Schema.hpp"
21
22#include <QtCore/qobject.h>
23#include <QtCore/qstring.h>
24#include <QtCore/qstringlist.h>
25
26#include <string>
27
28namespace dbe
29{
30namespace actions
31{
32//------------------------------------------------------------------------------------------
33template<typename T>
35 public onobject
36{
37public:
38 ChangeEnum ( tref Object, dunedaq::conffwk::attribute_t AttributeData, T NewValueData,
39 QUndoCommand * parent = nullptr );
40 void undo();
41 void redo();
42
43private:
47 bool Success;
48};
49
50template<typename T>
52 T NewValueData, QUndoCommand * parent )
53 : onobject ( Object, parent ),
54 NewValue ( NewValueData ),
55 Attribute ( AttributeData ),
56 Success ( true )
57{
58 try
59 {
60 QStringList Data
62 OldValue = convert::to<T> ( Data );
63 }
64 catch ( dunedaq::conffwk::Exception const & e )
65 {
66 Q_UNUSED ( e )
67 }
68
69 setText (
70 QObject::tr ( "Attribute %1 of object %2 was updated." ).arg (
71 AttributeData.p_name.c_str() ).arg ( Object.UID().c_str() ) );
72}
73
74template<typename T>
76{
77 try
78 {
79 if ( isvalid() )
80 {
81 failed();
82 dbe::config::api::set::noactions::anenum ( this->checkedref(), Attribute, OldValue );
83 toggle();
84 }
85 }
86 catch ( dunedaq::conffwk::Exception const & e )
87 {
88 Success = false;
89 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, e );
90 }
91 catch ( daq::dbe::config_object_retrieval_result_is_null const & ex )
92 {
93 FAIL ( "Operation did not complete because a lookup in the underlying database failed",
94 ex.what() );
95 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, ex );
96 }
97
98}
99
100template<typename T>
102{
103 try
104 {
105 if ( isvalid() )
106 {
107 failed();
108
109 QStringList Data
110 { dbe::config::api::get::attribute::list<QStringList> ( this->checkedref(), Attribute ) };
111
112 OldValue = convert::to<T> ( Data, Attribute.p_int_format );
113
114 dbe::config::api::set::noactions::anenum ( this->checkedref(), Attribute, NewValue );
115
116 toggle();
117 }
118 }
119 catch ( dunedaq::conffwk::Exception const & e )
120 {
121 Success = false;
122 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, e );
123 }
124 catch ( daq::dbe::config_object_retrieval_result_is_null const & ex )
125 {
126 FAIL ( "Operation did not complete because a lookup in the underlying database failed",
127 ex.what() );
128 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, ex );
129 }
130
131}
132//------------------------------------------------------------------------------------------
133}
134} // namespace dbe
135#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)
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.