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