44 lines
1.3 KiB
C++
44 lines
1.3 KiB
C++
/*
|
|
*******************************************************************************
|
|
* INCLUDE
|
|
*******************************************************************************
|
|
*/
|
|
#include "PocoConfigurationCopier.h"
|
|
#include <Poco/Util/JSONConfiguration.h>
|
|
|
|
namespace Util
|
|
{
|
|
/*
|
|
*******************************************************************************
|
|
* CLASS DEFINE
|
|
*******************************************************************************
|
|
*/
|
|
void PocoConfigurationCopier::copy(Poco::Util::AbstractConfiguration::Ptr& from,
|
|
Poco::Util::AbstractConfiguration::Ptr& to)
|
|
{
|
|
bool usingJSON = false;
|
|
|
|
if (to.isNull())
|
|
{
|
|
to = new Poco::Util::JSONConfiguration();
|
|
usingJSON = true;
|
|
}
|
|
else
|
|
usingJSON = !to.cast<Poco::Util::JSONConfiguration>().isNull();
|
|
|
|
Poco::AutoPtr<Poco::Util::JSONConfiguration> pJConfig = from.cast<Poco::Util::JSONConfiguration>();
|
|
if (pJConfig && usingJSON)
|
|
{
|
|
std::stringstream ss;
|
|
pJConfig->save(ss);
|
|
to.cast<Poco::Util::JSONConfiguration>()->load(ss);
|
|
}
|
|
else
|
|
{
|
|
Poco::Util::AbstractConfiguration::Keys keys;
|
|
from->keys(keys);
|
|
for (const auto& key : keys)
|
|
to->setString(key, from->getString(key));
|
|
}
|
|
}
|
|
}
|