ACF $AcfVersion:0$
TParamsPtr.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// Qt includes
6#include <QtCore/QtGlobal>
7#include <QtCore/QStringList>
8#include <QtCore/QtDebug>
9
10// ACF includes
11#include <istd/TPointerBase.h>
12#include <iattr/TAttribute.h>
15#include <iprm/IParamsSet.h>
16
17
18namespace iprm
19{
20
21
25template <class ParamsSet, class ParameterInterace>
26class TParamsPtrBase: public istd::TPointerBase<ParameterInterace>
27{
28public:
30 using NonConstParameterInterface = std::remove_const_t<ParameterInterace>;
31
32 TParamsPtrBase(ParameterInterace* ptr = NULL);
33
40 TParamsPtrBase(ParamsSet* parameterSetPtr, const QByteArray& parameterId, bool isObligatory = true);
41
49 TParamsPtrBase(ParamsSet* parameterSetPtr,
50 const icomp::TAttributeMember<iattr::CIdAttribute>& parameterIdAttribute,
52 bool isObligatory = true);
53
60 void Init(ParamsSet* parameterSetPtr, const QByteArray& parameterId, bool isObligatory = true);
61
69 void Init(ParamsSet* parameterSetPtr,
70 const icomp::TAttributeMember<iattr::CIdAttribute>& parameterIdAttribute,
72 bool isObligatory = true);
73};
74
75
76// public methods
77
78template <class ParamsSet, class ParameterInterace>
83
84
85template <class ParamsSet, class ParameterInterace>
87 ParamsSet* parameterSetPtr, const QByteArray& parameterId, bool isObligatory)
88{
89 Init(parameterSetPtr, parameterId, isObligatory);
90}
91
92
93template <class ParamsSet, class ParameterInterace>
95 ParamsSet* parameterSetPtr,
96 const icomp::TAttributeMember<iattr::CIdAttribute>& parameterIdAttribute,
98 bool isObligatory)
99{
100 Init(parameterSetPtr, parameterIdAttribute, defaultRef, isObligatory);
101}
102
103
104template <class ParamsSet, class ParameterInterace>
106 ParamsSet* parameterSetPtr, const QByteArray& parameterId, bool isObligatory)
107{
108 Q_UNUSED(isObligatory);
109 Q_STATIC_ASSERT(std::is_const<ParamsSet>{} == std::is_const<ParameterInterace>{});
110
111 BaseClass::Reset();
112
113 if ((parameterSetPtr != NULL) && !parameterId.isEmpty()){
114 const iser::ISerializable* constParameterPtr = nullptr;
115
116 if constexpr (std::is_const<ParamsSet>{}){
117 constParameterPtr = parameterSetPtr->GetParameter(parameterId);
118 BaseClass::SetPtr(dynamic_cast<ParameterInterace*>(constParameterPtr));
119 }
120 else{
121 iser::ISerializable* parameterPtr = parameterSetPtr->GetEditableParameter(parameterId);
122 BaseClass::SetPtr(dynamic_cast<ParameterInterace*>(parameterPtr));
123
124 constParameterPtr = parameterPtr;
125 }
126
127#if QT_VERSION >= 0x040800
129 if (!BaseClass::IsValid() && isObligatory){
130 iprm::IParamsSet::Ids existingParamIds = parameterSetPtr->GetParamIds();
131 QStringList existingIds;
132 for (iprm::IParamsSet::Ids::ConstIterator index = existingParamIds.constBegin(); index != existingParamIds.constEnd(); index++){
133 existingIds.push_back(*index);
134 }
135
136 QString idList = existingIds.join(", ");
137
138 if (constParameterPtr == NULL){
139 qDebug("Parameter %s was not found in the parameter set. Following parameter IDs are registered: %s", qPrintable(parameterId), qPrintable(idList));
140 }
141 else{
142 qDebug("Parameter %s was found in the parameter set, but it doesn't implement the required interface: %s", qPrintable(parameterId), qPrintable(typeid(ParameterInterace).name()));
143 }
144 }
145 )
146#endif
147 }
148 else{
149 BaseClass::Reset();
150 }
151}
152
153
154template <class ParamsSet, class ParameterInterace>
156 ParamsSet* parameterSetPtr,
157 const icomp::TAttributeMember<iattr::CIdAttribute>& parameterIdAttribute,
159 bool isObligatory)
160{
161 Q_UNUSED(isObligatory);
162 Q_STATIC_ASSERT(std::is_const<ParamsSet>{} == std::is_const<ParameterInterace>{});
163
164 BaseClass::Reset();
165
166 if (parameterIdAttribute.IsValid()){
167 if (parameterSetPtr != NULL){
168 const iser::ISerializable* constParameterPtr = nullptr;
169
170 if constexpr (std::is_const<ParamsSet>{}){
171 constParameterPtr = parameterSetPtr->GetParameter(*parameterIdAttribute);
172 BaseClass::SetPtr(dynamic_cast<ParameterInterace*>(constParameterPtr));
173 }
174 else{
175 iser::ISerializable* parameterPtr = parameterSetPtr->GetEditableParameter(*parameterIdAttribute);
176 BaseClass::SetPtr(dynamic_cast<ParameterInterace*>(parameterPtr));
177
178 constParameterPtr = parameterPtr;
179 }
180
181#if QT_VERSION >= 0x050000
182#ifndef QT_NO_DEBUG
183 if ((!BaseClass::IsValid()) && (constParameterPtr != NULL)){
184 qDebug("Parameter %s in parameter set is not compatible, should be %s", qPrintable(*parameterIdAttribute), qPrintable(istd::CClassInfo::GetName<ParameterInterace>()));
185 }
186#endif
187#endif
188 }
189#if QT_VERSION >= 0x050000
190#ifndef QT_NO_DEBUG
191 else if (isObligatory){
192 qDebug("Parameter set unavailable, cannot extract obligatory parameter %s", qPrintable(*parameterIdAttribute));
193 }
194#endif
195#endif
196 }
197
198 if (!BaseClass::IsValid() && defaultRef.IsValid()){
199 BaseClass::SetPtr(defaultRef.GetPtr());
200 }
201
202#if QT_VERSION >= 0x040800
203#ifndef QT_NO_DEBUG
204 if (!BaseClass::IsValid() && isObligatory){
205 QString debugMessage;
206
207 if (parameterSetPtr == NULL){
208 debugMessage = QString("There is no parameter set and no default parameter is active");
209 }
210 else if (parameterIdAttribute.IsValid()){
211 iprm::IParamsSet::Ids existingParamIds = parameterSetPtr->GetParamIds();
212 QStringList existingIds;
213 for (iprm::IParamsSet::Ids::ConstIterator index = existingParamIds.constBegin(); index != existingParamIds.constEnd(); index++){
214 existingIds.push_back(*index);
215 }
216
217 QString idList = existingIds.join(", ");
218
219 debugMessage = QString("Parameter %1 was not found in the parameter set and no default parameter is active. Following parameter IDs are registered: %2").arg(QString(*parameterIdAttribute)).arg(idList);
220 }
221 else{
222 debugMessage = QString("Parameter was not specified and no default parameter is active");
223 }
224
225 qDebug() << debugMessage;
226 }
227#endif
228#endif
229}
230
231
232template <class ParameterInterace>
233class TParamsPtr: public TParamsPtrBase<const IParamsSet, const ParameterInterace>{
234public:
236
237 TParamsPtr(const ParameterInterace* ptr = NULL)
238 :BaseClass(ptr)
239 {
240 }
241
242 TParamsPtr(const IParamsSet* parameterSetPtr, const QByteArray& parameterId, bool isObligatory = true)
243 :BaseClass(parameterSetPtr, parameterId, isObligatory)
244 {
245 }
246
248 const IParamsSet* parameterSetPtr,
249 const icomp::TAttributeMember<iattr::CIdAttribute>& parameterIdAttribute,
251 bool isObligatory = true)
252 :BaseClass(parameterSetPtr, parameterIdAttribute, defaultRef, isObligatory)
253 {
254 }
255
256 void Init(const IParamsSet* parameterSetPtr, const QByteArray& parameterId, bool isObligatory = true)
257 {
258 BaseClass::Init(parameterSetPtr, parameterId, isObligatory);
259 }
260
261 void Init(const IParamsSet* parameterSetPtr,
262 const icomp::TAttributeMember<iattr::CIdAttribute>& parameterIdAttribute,
264 bool isObligatory = true)
265 {
266 BaseClass::Init(parameterSetPtr, parameterIdAttribute, defaultRef, isObligatory);
267 }
268};
269
270
271template <class ParameterInterace>
272class TEditableParamsPtr : public TParamsPtrBase<IParamsSet, ParameterInterace>
273{
274public:
276
277 TEditableParamsPtr(ParameterInterace* ptr = NULL)
278 :BaseClass(ptr)
279 {
280 }
281
282 TEditableParamsPtr(IParamsSet* parameterSetPtr, const QByteArray& parameterId, bool isObligatory = true)
283 :BaseClass(parameterSetPtr, parameterId, isObligatory)
284 {
285 }
286
288 IParamsSet* parameterSetPtr,
289 const icomp::TAttributeMember<iattr::CIdAttribute>& parameterIdAttribute,
291 bool isObligatory = true)
292 :BaseClass(parameterSetPtr, parameterIdAttribute, defaultRef, isObligatory)
293 {
294 }
295
296 void Init(IParamsSet* parameterSetPtr, const QByteArray& parameterId, bool isObligatory = true)
297 {
298 BaseClass::Init(parameterSetPtr, parameterId, isObligatory);
299 }
300
301 void Init(IParamsSet* parameterSetPtr,
302 const icomp::TAttributeMember<iattr::CIdAttribute>& parameterIdAttribute,
304 bool isObligatory = true)
305 {
306 BaseClass::Init(parameterSetPtr, parameterIdAttribute, defaultRef, isObligatory);
307 }
308};
309
310
311} // namespace iprm
312
313
Pointer to component attribute.
bool IsValid() const
Check if this attribute is valid.
Pointer to referenced component object.
Interface * GetPtr() const
Direct cccess to internal pointer.
bool IsValid() const
Check if this reference can be resolved.
Set of general parameters.
Definition IParamsSet.h:81
QSet< QByteArray > Ids
Definition IParamsSet.h:83
TEditableParamsPtr(ParameterInterace *ptr=NULL)
Definition TParamsPtr.h:277
TEditableParamsPtr(IParamsSet *parameterSetPtr, const icomp::TAttributeMember< iattr::CIdAttribute > &parameterIdAttribute, const icomp::TReferenceMember< ParameterInterace > &defaultRef, bool isObligatory=true)
Definition TParamsPtr.h:287
TParamsPtrBase< IParamsSet, ParameterInterace > BaseClass
Definition TParamsPtr.h:275
void Init(IParamsSet *parameterSetPtr, const icomp::TAttributeMember< iattr::CIdAttribute > &parameterIdAttribute, const icomp::TReferenceMember< ParameterInterace > &defaultRef, bool isObligatory=true)
Definition TParamsPtr.h:301
TEditableParamsPtr(IParamsSet *parameterSetPtr, const QByteArray &parameterId, bool isObligatory=true)
Definition TParamsPtr.h:282
void Init(IParamsSet *parameterSetPtr, const QByteArray &parameterId, bool isObligatory=true)
Definition TParamsPtr.h:296
Help pointer wrapper for management of a parameter from the parameter set.
Definition TParamsPtr.h:27
TParamsPtrBase(ParamsSet *parameterSetPtr, const QByteArray &parameterId, bool isObligatory=true)
Construct and initialize the pointer with the given parameter set and parameter ID.
Definition TParamsPtr.h:86
void Init(ParamsSet *parameterSetPtr, const QByteArray &parameterId, bool isObligatory=true)
Initialize the pointer with the given parameter set and parameter ID.
Definition TParamsPtr.h:105
void Init(ParamsSet *parameterSetPtr, const icomp::TAttributeMember< iattr::CIdAttribute > &parameterIdAttribute, const icomp::TReferenceMember< NonConstParameterInterface > &defaultRef, bool isObligatory=true)
Initialize the pointer with the component parameters.
Definition TParamsPtr.h:155
TParamsPtrBase(ParamsSet *parameterSetPtr, const icomp::TAttributeMember< iattr::CIdAttribute > &parameterIdAttribute, const icomp::TReferenceMember< NonConstParameterInterface > &defaultRef, bool isObligatory=true)
Construct and initialize the pointer with the component parameters.
Definition TParamsPtr.h:94
istd::TPointerBase< ParameterInterace > BaseClass
Definition TParamsPtr.h:29
std::remove_const_t< ParameterInterace > NonConstParameterInterface
Definition TParamsPtr.h:30
TParamsPtrBase(ParameterInterace *ptr=NULL)
Definition TParamsPtr.h:79
TParamsPtr(const IParamsSet *parameterSetPtr, const QByteArray &parameterId, bool isObligatory=true)
Definition TParamsPtr.h:242
TParamsPtrBase< const IParamsSet, const ParameterInterace > BaseClass
Definition TParamsPtr.h:235
TParamsPtr(const IParamsSet *parameterSetPtr, const icomp::TAttributeMember< iattr::CIdAttribute > &parameterIdAttribute, const icomp::TReferenceMember< ParameterInterace > &defaultRef, bool isObligatory=true)
Definition TParamsPtr.h:247
TParamsPtr(const ParameterInterace *ptr=NULL)
Definition TParamsPtr.h:237
void Init(const IParamsSet *parameterSetPtr, const icomp::TAttributeMember< iattr::CIdAttribute > &parameterIdAttribute, const icomp::TReferenceMember< ParameterInterace > &defaultRef, bool isObligatory=true)
Definition TParamsPtr.h:261
void Init(const IParamsSet *parameterSetPtr, const QByteArray &parameterId, bool isObligatory=true)
Definition TParamsPtr.h:256
Common class for all classes which objects can be archived or restored from archive.
Implementation of pointer wrapper.
#define NULL
Definition istd.h:74
#define I_IF_DEBUG(instructions)
Definition istd.h:59
Contains interfaces and implementations of flexible parameter concept.