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
|
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2011-10-01 18:45:20 +00:00
|
|
|
*
|
2020-12-30 12:35:06 +00:00
|
|
|
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
|
2011-10-01 18:45:20 +00:00
|
|
|
* This file is part of GNSS-SDR.
|
|
|
|
*
|
2020-12-30 12:35:06 +00:00
|
|
|
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
|
2020-02-08 00:20:02 +00:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2011-10-01 18:45:20 +00:00
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2011-10-01 18:45:20 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "in_memory_configuration.h"
|
2020-06-23 07:47:58 +00:00
|
|
|
#include "gnss_sdr_make_unique.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-06-23 07:47:58 +00:00
|
|
|
converter_ = std::make_unique<StringConverter>();
|
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
|
|
|
|
2020-06-23 09:05:31 +00:00
|
|
|
std::string InMemoryConfiguration::property(std::string property_name, std::string default_value) const
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
2020-07-19 23:20:15 +00:00
|
|
|
const 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
|
|
|
|
2020-06-23 09:05:31 +00:00
|
|
|
bool InMemoryConfiguration::property(std::string property_name, bool default_value) const
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
2020-07-19 23:20:15 +00:00
|
|
|
const 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
|
|
|
|
2020-06-23 09:05:31 +00:00
|
|
|
int64_t InMemoryConfiguration::property(std::string property_name, int64_t default_value) const
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
2020-07-19 23:20:15 +00:00
|
|
|
const 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
|
|
|
|
2020-06-23 09:05:31 +00:00
|
|
|
uint64_t InMemoryConfiguration::property(std::string property_name, uint64_t default_value) const
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
2020-07-19 23:20:15 +00:00
|
|
|
const 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
|
|
|
|
2020-06-23 09:05:31 +00:00
|
|
|
int32_t InMemoryConfiguration::property(std::string property_name, int32_t default_value) const
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
2020-07-19 23:20:15 +00:00
|
|
|
const 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
|
|
|
|
2020-06-23 09:05:31 +00:00
|
|
|
uint32_t InMemoryConfiguration::property(std::string property_name, uint32_t default_value) const
|
2016-05-07 10:22:40 +00:00
|
|
|
{
|
2020-07-19 23:20:15 +00:00
|
|
|
const std::string empty;
|
2018-12-02 04:29:11 +00:00
|
|
|
return converter_->convert(property(property_name, empty), default_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-23 09:05:31 +00:00
|
|
|
uint16_t InMemoryConfiguration::property(std::string property_name, uint16_t default_value) const
|
2018-12-02 04:29:11 +00:00
|
|
|
{
|
2020-07-19 23:20:15 +00:00
|
|
|
const std::string empty;
|
2018-12-02 04:29:11 +00:00
|
|
|
return converter_->convert(property(property_name, empty), default_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-23 09:05:31 +00:00
|
|
|
int16_t InMemoryConfiguration::property(std::string property_name, int16_t default_value) const
|
2018-12-02 04:29:11 +00:00
|
|
|
{
|
2020-07-19 23:20:15 +00:00
|
|
|
const std::string empty;
|
2016-05-07 10:22:40 +00:00
|
|
|
return converter_->convert(property(property_name, empty), default_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-23 09:05:31 +00:00
|
|
|
float InMemoryConfiguration::property(std::string property_name, float default_value) const
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
2020-07-19 23:20:15 +00:00
|
|
|
const 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
|
|
|
|
2020-06-23 09:05:31 +00:00
|
|
|
double InMemoryConfiguration::property(std::string property_name, double default_value) const
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
2020-07-19 23:20:15 +00:00
|
|
|
const 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));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-23 09:05:31 +00:00
|
|
|
bool InMemoryConfiguration::is_present(const std::string& property_name) const
|
2011-10-01 18:45:20 +00:00
|
|
|
{
|
|
|
|
return (properties_.find(property_name) != properties_.end());
|
|
|
|
}
|