Indicate that the property method of configuration is a getter

This commit is contained in:
Carles Fernandez 2020-06-23 11:05:31 +02:00
parent 037a1fcb5f
commit bcd5bfa6ff
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
5 changed files with 61 additions and 54 deletions

View File

@ -42,16 +42,16 @@ class ConfigurationInterface
{
public:
virtual ~ConfigurationInterface() = default;
virtual std::string property(std::string property_name, std::string default_value) = 0;
virtual bool property(std::string property_name, bool default_value) = 0;
virtual int64_t property(std::string property_name, int64_t default_value) = 0;
virtual uint64_t property(std::string property_name, uint64_t default_value) = 0;
virtual int32_t property(std::string property_name, int32_t default_value) = 0;
virtual uint32_t property(std::string property_name, uint32_t default_value) = 0;
virtual int16_t property(std::string property_name, int16_t default_value) = 0;
virtual uint16_t property(std::string property_name, uint16_t default_value) = 0;
virtual float property(std::string property_name, float default_value) = 0;
virtual double property(std::string property_name, double default_value) = 0;
virtual std::string property(std::string property_name, std::string default_value) const = 0;
virtual bool property(std::string property_name, bool default_value) const = 0;
virtual int64_t property(std::string property_name, int64_t default_value) const = 0;
virtual uint64_t property(std::string property_name, uint64_t default_value) const = 0;
virtual int32_t property(std::string property_name, int32_t default_value) const = 0;
virtual uint32_t property(std::string property_name, uint32_t default_value) const = 0;
virtual int16_t property(std::string property_name, int16_t default_value) const = 0;
virtual uint16_t property(std::string property_name, uint16_t default_value) const = 0;
virtual float property(std::string property_name, float default_value) const = 0;
virtual double property(std::string property_name, double default_value) const = 0;
virtual void set_property(std::string property_name, std::string value) = 0;
};

View File

@ -63,7 +63,7 @@ void FileConfiguration::init()
}
std::string FileConfiguration::property(std::string property_name, std::string default_value)
std::string FileConfiguration::property(std::string property_name, std::string default_value) const
{
if (overrided_->is_present(property_name))
{
@ -73,7 +73,7 @@ std::string FileConfiguration::property(std::string property_name, std::string d
}
bool FileConfiguration::property(std::string property_name, bool default_value)
bool FileConfiguration::property(std::string property_name, bool default_value) const
{
if (overrided_->is_present(property_name))
{
@ -84,7 +84,7 @@ bool FileConfiguration::property(std::string property_name, bool default_value)
}
int64_t FileConfiguration::property(std::string property_name, int64_t default_value)
int64_t FileConfiguration::property(std::string property_name, int64_t default_value) const
{
if (overrided_->is_present(property_name))
{
@ -95,7 +95,7 @@ int64_t FileConfiguration::property(std::string property_name, int64_t default_v
}
uint64_t FileConfiguration::property(std::string property_name, uint64_t default_value)
uint64_t FileConfiguration::property(std::string property_name, uint64_t default_value) const
{
if (overrided_->is_present(property_name))
{
@ -106,7 +106,7 @@ uint64_t FileConfiguration::property(std::string property_name, uint64_t default
}
int FileConfiguration::property(std::string property_name, int default_value)
int FileConfiguration::property(std::string property_name, int default_value) const
{
if (overrided_->is_present(property_name))
{
@ -117,7 +117,7 @@ int FileConfiguration::property(std::string property_name, int default_value)
}
unsigned int FileConfiguration::property(std::string property_name, unsigned int default_value)
unsigned int FileConfiguration::property(std::string property_name, unsigned int default_value) const
{
if (overrided_->is_present(property_name))
{
@ -128,7 +128,7 @@ unsigned int FileConfiguration::property(std::string property_name, unsigned int
}
uint16_t FileConfiguration::property(std::string property_name, uint16_t default_value)
uint16_t FileConfiguration::property(std::string property_name, uint16_t default_value) const
{
if (overrided_->is_present(property_name))
{
@ -139,7 +139,7 @@ uint16_t FileConfiguration::property(std::string property_name, uint16_t default
}
int16_t FileConfiguration::property(std::string property_name, int16_t default_value)
int16_t FileConfiguration::property(std::string property_name, int16_t default_value) const
{
if (overrided_->is_present(property_name))
{
@ -150,7 +150,7 @@ int16_t FileConfiguration::property(std::string property_name, int16_t default_v
}
float FileConfiguration::property(std::string property_name, float default_value)
float FileConfiguration::property(std::string property_name, float default_value) const
{
if (overrided_->is_present(property_name))
{
@ -161,7 +161,7 @@ float FileConfiguration::property(std::string property_name, float default_value
}
double FileConfiguration::property(std::string property_name, double default_value)
double FileConfiguration::property(std::string property_name, double default_value) const
{
if (overrided_->is_present(property_name))
{
@ -176,3 +176,9 @@ void FileConfiguration::set_property(std::string property_name, std::string valu
{
overrided_->set_property(property_name, value);
}
bool FileConfiguration::is_present(const std::string& property_name) const
{
return (overrided_->is_present(property_name));
}

View File

@ -48,17 +48,18 @@ public:
explicit FileConfiguration(std::string filename);
FileConfiguration();
~FileConfiguration() = default;
std::string property(std::string property_name, std::string default_value);
bool property(std::string property_name, bool default_value);
int64_t property(std::string property_name, int64_t default_value);
uint64_t property(std::string property_name, uint64_t default_value);
int32_t property(std::string property_name, int32_t default_value);
uint32_t property(std::string property_name, uint32_t default_value);
int16_t property(std::string property_name, int16_t default_value);
uint16_t property(std::string property_name, uint16_t default_value);
float property(std::string property_name, float default_value);
double property(std::string property_name, double default_value);
void set_property(std::string property_name, std::string value);
std::string property(std::string property_name, std::string default_value) const override;
bool property(std::string property_name, bool default_value) const override;
int64_t property(std::string property_name, int64_t default_value) const override;
uint64_t property(std::string property_name, uint64_t default_value) const override;
int32_t property(std::string property_name, int32_t default_value) const override;
uint32_t property(std::string property_name, uint32_t default_value) const override;
int16_t property(std::string property_name, int16_t default_value) const override;
uint16_t property(std::string property_name, uint16_t default_value) const override;
float property(std::string property_name, float default_value) const override;
double property(std::string property_name, double default_value) const override;
void set_property(std::string property_name, std::string value) override;
bool is_present(const std::string& property_name) const;
private:
void init();

View File

@ -36,7 +36,7 @@ InMemoryConfiguration::~InMemoryConfiguration()
}
std::string InMemoryConfiguration::property(std::string property_name, std::string default_value)
std::string InMemoryConfiguration::property(std::string property_name, std::string default_value) const
{
auto iter = properties_.find(property_name);
if (iter != properties_.end())
@ -47,63 +47,63 @@ std::string InMemoryConfiguration::property(std::string property_name, std::stri
}
bool InMemoryConfiguration::property(std::string property_name, bool default_value)
bool InMemoryConfiguration::property(std::string property_name, bool default_value) const
{
std::string empty;
return converter_->convert(property(property_name, empty), default_value);
}
int64_t InMemoryConfiguration::property(std::string property_name, int64_t default_value)
int64_t InMemoryConfiguration::property(std::string property_name, int64_t default_value) const
{
std::string empty;
return converter_->convert(property(property_name, empty), default_value);
}
uint64_t InMemoryConfiguration::property(std::string property_name, uint64_t default_value)
uint64_t InMemoryConfiguration::property(std::string property_name, uint64_t default_value) const
{
std::string empty;
return converter_->convert(property(property_name, empty), default_value);
}
int32_t InMemoryConfiguration::property(std::string property_name, int32_t default_value)
int32_t InMemoryConfiguration::property(std::string property_name, int32_t default_value) const
{
std::string empty;
return converter_->convert(property(property_name, empty), default_value);
}
uint32_t InMemoryConfiguration::property(std::string property_name, uint32_t default_value)
uint32_t InMemoryConfiguration::property(std::string property_name, uint32_t default_value) const
{
std::string empty;
return converter_->convert(property(property_name, empty), default_value);
}
uint16_t InMemoryConfiguration::property(std::string property_name, uint16_t default_value)
uint16_t InMemoryConfiguration::property(std::string property_name, uint16_t default_value) const
{
std::string empty;
return converter_->convert(property(property_name, empty), default_value);
}
int16_t InMemoryConfiguration::property(std::string property_name, int16_t default_value)
int16_t InMemoryConfiguration::property(std::string property_name, int16_t default_value) const
{
std::string empty;
return converter_->convert(property(property_name, empty), default_value);
}
float InMemoryConfiguration::property(std::string property_name, float default_value)
float InMemoryConfiguration::property(std::string property_name, float default_value) const
{
std::string empty;
return converter_->convert(property(property_name, empty), default_value);
}
double InMemoryConfiguration::property(std::string property_name, double default_value)
double InMemoryConfiguration::property(std::string property_name, double default_value) const
{
std::string empty;
return converter_->convert(property(property_name, empty), default_value);
@ -123,7 +123,7 @@ void InMemoryConfiguration::supersede_property(const std::string& property_name,
}
bool InMemoryConfiguration::is_present(const std::string& property_name)
bool InMemoryConfiguration::is_present(const std::string& property_name) const
{
return (properties_.find(property_name) != properties_.end());
}

View File

@ -43,19 +43,19 @@ class InMemoryConfiguration : public ConfigurationInterface
public:
InMemoryConfiguration();
~InMemoryConfiguration();
std::string property(std::string property_name, std::string default_value);
bool property(std::string property_name, bool default_value);
int64_t property(std::string property_name, int64_t default_value);
uint64_t property(std::string property_name, uint64_t default_value);
int32_t property(std::string property_name, int32_t default_value);
uint32_t property(std::string property_name, uint32_t default_value);
int16_t property(std::string property_name, int16_t default_value);
uint16_t property(std::string property_name, uint16_t default_value);
float property(std::string property_name, float default_value);
double property(std::string property_name, double default_value);
void set_property(std::string property_name, std::string value);
std::string property(std::string property_name, std::string default_value) const override;
bool property(std::string property_name, bool default_value) const override;
int64_t property(std::string property_name, int64_t default_value) const override;
uint64_t property(std::string property_name, uint64_t default_value) const override;
int32_t property(std::string property_name, int32_t default_value) const override;
uint32_t property(std::string property_name, uint32_t default_value) const override;
int16_t property(std::string property_name, int16_t default_value) const override;
uint16_t property(std::string property_name, uint16_t default_value) const override;
float property(std::string property_name, float default_value) const override;
double property(std::string property_name, double default_value) const override;
void set_property(std::string property_name, std::string value) override;
void supersede_property(const std::string& property_name, const std::string& value);
bool is_present(const std::string& property_name);
bool is_present(const std::string& property_name) const;
private:
std::map<std::string, std::string> properties_;