chore(LocalConfigurationView): fix style #3529

This commit is contained in:
Alex Fabijanic 2022-06-20 17:48:53 +02:00
parent a843c63bf2
commit 41f11b02bc
2 changed files with 86 additions and 72 deletions

View File

@ -20,9 +20,10 @@
#include "Poco/Util/Util.h" #include "Poco/Util/Util.h"
namespace Poco { namespace Poco {
namespace Util { namespace Util {
class Util_API LocalConfigurationView : public AbstractConfiguration
class Util_API LocalConfigurationView : public AbstractConfiguration
/// This configuration implements a "view" into a sub-hierarchy /// This configuration implements a "view" into a sub-hierarchy
/// of another configuration. /// of another configuration.
/// ///
@ -42,31 +43,29 @@ namespace Poco {
/// LayeredConfiguration. /// LayeredConfiguration.
/// ///
/// The LocalConfigurationView only searches for the properties in the viewed Space. /// The LocalConfigurationView only searches for the properties in the viewed Space.
{ {
public: public:
LocalConfigurationView(const std::string& prefix, AbstractConfiguration::Ptr pConfig); LocalConfigurationView(const std::string& prefix, AbstractConfiguration::Ptr pConfig);
/// Creates the LocalConfigurationView. The LocalConfigurationView /// Creates the LocalConfigurationView. The LocalConfigurationView
/// retains (shared) ownership of the passed configuration. /// retains (shared) ownership of the passed configuration.
protected: protected:
bool getRaw(const std::string& key, std::string& value) const; bool getRaw(const std::string& key, std::string& value) const;
void setRaw(const std::string& key, const std::string& value); void setRaw(const std::string& key, const std::string& value);
void enumerate(const std::string& key, Keys& range) const; void enumerate(const std::string& key, Keys& range) const;
void removeRaw(const std::string& key); void removeRaw(const std::string& key);
std::string translateKey(const std::string& key) const; std::string translateKey(const std::string& key) const;
~LocalConfigurationView(); ~LocalConfigurationView();
private: private:
LocalConfigurationView(const LocalConfigurationView&); LocalConfigurationView(const LocalConfigurationView&);
LocalConfigurationView& operator=(const LocalConfigurationView&); LocalConfigurationView& operator=(const LocalConfigurationView&);
std::string _prefix; std::string _prefix;
AbstractConfiguration::Ptr _pConfig; AbstractConfiguration::Ptr _pConfig;
}; };
}} // namespace Poco::Util
} // namespace Util
} // namespace Poco
#endif // Util_LocalConfigurationView_INCLUDED #endif // Util_LocalConfigurationView_INCLUDED

View File

@ -13,43 +13,58 @@
#include "Poco/Util/LocalConfigurationView.h" #include "Poco/Util/LocalConfigurationView.h"
namespace Poco { namespace Poco {
namespace Util { namespace Util {
LocalConfigurationView::LocalConfigurationView(const std::string& prefix, AbstractConfiguration::Ptr pConfig) : _prefix(prefix),
_pConfig(pConfig) { LocalConfigurationView::LocalConfigurationView(const std::string& prefix, AbstractConfiguration::Ptr pConfig) :
_prefix(prefix), _pConfig(pConfig)
{
poco_check_ptr(pConfig); poco_check_ptr(pConfig);
} }
LocalConfigurationView::~LocalConfigurationView() {
}
bool LocalConfigurationView::getRaw(const std::string& key, std::string& value) const { LocalConfigurationView::~LocalConfigurationView()
{
}
bool LocalConfigurationView::getRaw(const std::string& key, std::string& value) const
{
std::string translatedKey = translateKey(key); std::string translatedKey = translateKey(key);
return _pConfig->getRaw(translatedKey, value); return _pConfig->getRaw(translatedKey, value);
} }
void LocalConfigurationView::setRaw(const std::string& key, const std::string& value) {
void LocalConfigurationView::setRaw(const std::string& key, const std::string& value)
{
std::string translatedKey = translateKey(key); std::string translatedKey = translateKey(key);
_pConfig->setRaw(translatedKey, value); _pConfig->setRaw(translatedKey, value);
} }
void LocalConfigurationView::enumerate(const std::string& key, Keys& range) const {
void LocalConfigurationView::enumerate(const std::string& key, Keys& range) const
{
std::string translatedKey = translateKey(key); std::string translatedKey = translateKey(key);
_pConfig->enumerate(translatedKey, range); _pConfig->enumerate(translatedKey, range);
} }
void LocalConfigurationView::removeRaw(const std::string& key) {
void LocalConfigurationView::removeRaw(const std::string& key)
{
std::string translatedKey = translateKey(key); std::string translatedKey = translateKey(key);
_pConfig->remove(translatedKey); _pConfig->remove(translatedKey);
} }
std::string LocalConfigurationView::translateKey(const std::string& key) const {
std::string LocalConfigurationView::translateKey(const std::string& key) const
{
std::string result = _prefix; std::string result = _prefix;
if (!result.empty() && !key.empty() && key[0] != '[') result += '.'; if (!result.empty() && !key.empty() && key[0] != '[') result += '.';
result += key; result += key;
return result; return result;
} }
} // namespace Util
} // namespace Poco }} // namespace Poco::Util