2011-10-01 18:45:20 +00:00
|
|
|
/*!
|
2011-12-28 21:36:45 +00:00
|
|
|
* \file in_memory_configuration.cc
|
|
|
|
* \brief This implementation accepts configuration parameters upon instantiation and
|
|
|
|
* it is intended to be used in unit testing.
|
2011-10-01 18:45:20 +00:00
|
|
|
* \author Carlos Aviles, 2010. carlos.avilesr(at)googlemail.com
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*
|
2019-07-26 10:38:20 +00:00
|
|
|
* Copyright (C) 2010-2019 (see AUTHORS file for a list of contributors)
|
2011-10-01 18:45:20 +00:00
|
|
|
*
|
|
|
|
* GNSS-SDR is a software defined Global Navigation
|
|
|
|
* Satellite Systems receiver
|
|
|
|
*
|
|
|
|
* This file is part of GNSS-SDR.
|
|
|
|
*
|
2020-02-08 00:20:02 +00:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2011-10-01 18:45:20 +00:00
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "in_memory_configuration.h"
|
2018-02-26 02:15:53 +00:00
|
|
|
#include "string_converter.h"
|
2011-10-01 18:45:20 +00:00
|
|
|
#include <utility>
|
2018-02-26 02:15:53 +00:00
|
|
|
|
2011-10-01 18:45:20 +00:00
|
|
|
|
|
|
|
InMemoryConfiguration::InMemoryConfiguration()
|
2016-10-02 00:03:59 +00:00
|
|
|
{
|
2020-02-26 21:40:00 +00:00
|
|
|
std::unique_ptr<StringConverter> converter_aux(new StringConverter);
|
|
|
|
converter_ = std::move(converter_aux);
|
2016-10-02 00:03:59 +00:00
|
|
|
}
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2012-11-01 18:26:58 +00:00
|
|
|
|
2011-10-01 18:45:20 +00:00
|
|
|
InMemoryConfiguration::~InMemoryConfiguration()
|
|
|
|
{
|
|
|
|
properties_.clear();
|
|
|
|
}
|
|
|
|
|
2012-11-01 18:26:58 +00:00
|
|
|
|
2011-10-01 18:45:20 +00:00
|
|
|
std::string InMemoryConfiguration::property(std::string property_name, std::string default_value)
|
|
|
|
{
|
2018-12-03 15:25:11 +00:00
|
|
|
auto iter = properties_.find(property_name);
|
2018-03-03 01:03:39 +00:00
|
|
|
if (iter != properties_.end())
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
|
|
|
return iter->second;
|
|
|
|
}
|
2018-12-03 21:08:19 +00:00
|
|
|
return default_value;
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2012-11-01 18:26:58 +00:00
|
|
|
|
2011-10-01 18:45:20 +00:00
|
|
|
bool InMemoryConfiguration::property(std::string property_name, bool default_value)
|
|
|
|
{
|
2018-12-02 04:29:11 +00:00
|
|
|
std::string empty;
|
2011-10-01 18:45:20 +00:00
|
|
|
return converter_->convert(property(property_name, empty), default_value);
|
|
|
|
}
|
|
|
|
|
2012-11-01 18:26:58 +00:00
|
|
|
|
2018-12-02 04:29:11 +00:00
|
|
|
int64_t InMemoryConfiguration::property(std::string property_name, int64_t default_value)
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
2018-12-02 04:29:11 +00:00
|
|
|
std::string empty;
|
2011-10-01 18:45:20 +00:00
|
|
|
return converter_->convert(property(property_name, empty), default_value);
|
|
|
|
}
|
|
|
|
|
2012-11-01 18:26:58 +00:00
|
|
|
|
2018-12-02 04:29:11 +00:00
|
|
|
uint64_t InMemoryConfiguration::property(std::string property_name, uint64_t default_value)
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
2018-12-02 04:29:11 +00:00
|
|
|
std::string empty;
|
2011-10-01 18:45:20 +00:00
|
|
|
return converter_->convert(property(property_name, empty), default_value);
|
|
|
|
}
|
|
|
|
|
2012-11-01 18:26:58 +00:00
|
|
|
|
2018-12-02 04:29:11 +00:00
|
|
|
int32_t InMemoryConfiguration::property(std::string property_name, int32_t default_value)
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
2018-12-02 04:29:11 +00:00
|
|
|
std::string empty;
|
2011-10-01 18:45:20 +00:00
|
|
|
return converter_->convert(property(property_name, empty), default_value);
|
|
|
|
}
|
|
|
|
|
2012-11-01 18:26:58 +00:00
|
|
|
|
2018-12-02 04:29:11 +00:00
|
|
|
uint32_t InMemoryConfiguration::property(std::string property_name, uint32_t default_value)
|
2016-05-07 10:22:40 +00:00
|
|
|
{
|
2018-12-02 04:29:11 +00:00
|
|
|
std::string empty;
|
|
|
|
return converter_->convert(property(property_name, empty), default_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t InMemoryConfiguration::property(std::string property_name, uint16_t default_value)
|
|
|
|
{
|
|
|
|
std::string empty;
|
|
|
|
return converter_->convert(property(property_name, empty), default_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int16_t InMemoryConfiguration::property(std::string property_name, int16_t default_value)
|
|
|
|
{
|
|
|
|
std::string empty;
|
2016-05-07 10:22:40 +00:00
|
|
|
return converter_->convert(property(property_name, empty), default_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-01 18:45:20 +00:00
|
|
|
float InMemoryConfiguration::property(std::string property_name, float default_value)
|
|
|
|
{
|
2018-12-02 04:29:11 +00:00
|
|
|
std::string empty;
|
2011-10-01 18:45:20 +00:00
|
|
|
return converter_->convert(property(property_name, empty), default_value);
|
|
|
|
}
|
|
|
|
|
2012-11-01 18:26:58 +00:00
|
|
|
|
2011-10-01 18:45:20 +00:00
|
|
|
double InMemoryConfiguration::property(std::string property_name, double default_value)
|
|
|
|
{
|
2018-12-02 04:29:11 +00:00
|
|
|
std::string empty;
|
2011-10-01 18:45:20 +00:00
|
|
|
return converter_->convert(property(property_name, empty), default_value);
|
|
|
|
}
|
|
|
|
|
2012-11-01 18:26:58 +00:00
|
|
|
|
2011-10-01 18:45:20 +00:00
|
|
|
void InMemoryConfiguration::set_property(std::string property_name, std::string value)
|
|
|
|
{
|
|
|
|
properties_.insert(std::make_pair(property_name, value));
|
|
|
|
}
|
|
|
|
|
2012-11-01 18:26:58 +00:00
|
|
|
|
2019-06-29 20:04:03 +00:00
|
|
|
void InMemoryConfiguration::supersede_property(const std::string& property_name, const std::string& value)
|
2018-06-28 07:20:38 +00:00
|
|
|
{
|
|
|
|
properties_.erase(property_name);
|
|
|
|
properties_.insert(std::make_pair(property_name, value));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-02 04:29:11 +00:00
|
|
|
bool InMemoryConfiguration::is_present(const std::string& property_name)
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
|
|
|
return (properties_.find(property_name) != properties_.end());
|
|
|
|
}
|