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