Try work const pointers with AutoPtr:
void LiveTimeConfig::setup(const AbstractConfiguration& cfg){
GetLogger().information("LiveTimeConfig::setup(): init data");
Poco::AutoPtr<const AbstractConfiguration> view =
cfg.createView("live_time");
try {
readExist(view, Field::Token, _token);
readExist(view, Field::Solt, _solt);
} catch (Poco::SyntaxException& ) {
GetLogger().error("LiveTimeConfig::setup(): bad values");
throw Poco::RuntimeException("LiveTimeConfig::setup(): invalid format");
}
}
But I have error on comparison operator.
../../../build/pc/include/Poco/AutoPtr.h: In instantiation of ‘class Poco::AutoPtr<const Poco::Util::AbstractConfiguration>’: src/LiveTimeConfig.cpp:27:54: required from here ../../../../build/pc/include/Poco/AutoPtr.h:263:7: error: ‘bool Poco::AutoPtr<C>::operator==(C*) const [with C = const Poco::Util::AbstractConfiguration]’ cannot be overloaded bool operator == (C* ptr) const
^ ../../../../build/pc/include/Poco/AutoPtr.h:258:7: error: with ‘bool Poco::AutoPtr<C>::operator==(const C*) const [with C = const Poco::Util::AbstractConfiguration]’ bool operator == (const C* ptr) const
^ ../../../../build/pc/include/Poco/AutoPtr.h:278:7: error: ‘bool Poco::AutoPtr<C>::operator!=(C*) const [with C = const Poco::Util::AbstractConfiguration]’ cannot be overloaded bool operator != (C* ptr) const
^ ../../../../build/pc/include/Poco/AutoPtr.h:273:7: error: with ‘bool Poco::AutoPtr<C>::operator!=(const C*) const [with C = const Poco::Util::AbstractConfiguration]’ bool operator != (const C* ptr) const
^ ../../../../build/pc/include/Poco/AutoPtr.h:293:7: error: ‘bool Poco::AutoPtr<C>::operator<(C*) const [with C = const Poco::Util::AbstractConfiguration]’ cannot be overloaded bool operator < (C* ptr) const
^ ../../../../build/pc/include/Poco/AutoPtr.h:288:7: error: with ‘bool Poco::AutoPtr<C>::operator<(const C*) const [with C = const Poco::Util::AbstractConfiguration]’ bool operator < (const C* ptr) const
^ ../../../../build/pc/include/Poco/AutoPtr.h:308:7: error: ‘bool Poco::AutoPtr<C>::operator<=(C*) const [with C = const Poco::Util::AbstractConfiguration]’ cannot be overloaded bool operator <= (C* ptr) const
^ ../../../../build/pc/include/Poco/AutoPtr.h:303:7: error: with ‘bool Poco::AutoPtr<C>::operator<=(const C*) const [with C = const Poco::Util::AbstractConfiguration]’ bool operator <= (const C* ptr) const
^ ../../../../build/pc/include/Poco/AutoPtr.h:323:7: error: ‘bool Poco::AutoPtr<C>::operator>(C*) const [with C = const Poco::Util::AbstractConfiguration]’ cannot be overloaded bool operator > (C* ptr) const
^ ../../../../build/pc/include/Poco/AutoPtr.h:318:7: error: with ‘bool Poco::AutoPtr<C>::operator>(const C*) const [with C = const Poco::Util::AbstractConfiguration]’ bool operator > (const C* ptr) const
^ ../../../../build/pc/include/Poco/AutoPtr.h:338:7: error: ‘bool Poco::AutoPtr<C>::operator>=(C*) const [with C = const Poco::Util::AbstractConfiguration]’ cannot be overloaded bool operator >= (C* ptr) const
^ ../../../../build/pc/include/Poco/AutoPtr.h:333:7: error: with ‘bool Poco::AutoPtr<C>::operator>=(const C*) const [with C = const Poco::Util::AbstractConfiguration]’ bool operator >= (const C* ptr) const
How create AutoPtr for const AbstractConfiguration*
UPD
if using
const Poco::AutoPtr<AbstractConfiguration> view = cfg.createView("live_time");
Error is
/home/evgen/projects/AuthService/Core/Module/src/LiveTimeConfig.cpp:27: error: invalid conversion from ‘const Poco::Util::AbstractConfiguration*’ to ‘Poco::Util::AbstractConfiguration*’ [-fpermissive]
const Poco::AutoPtr<AbstractConfiguration> view = cfg.createView("live_time");
^
Only using const_cast success build and work, but I think is it hack and smell code.
const Poco::AutoPtr<AbstractConfiguration> view = const_cast<AbstractConfiguration*>(cfg.createView("live_time"));