From 0e03940802cebefdf6b0597a154bd9395e1af4d2 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Wed, 18 Jun 2014 15:45:45 +0200 Subject: Add the vanilla version of the project This version can still be found here: http://www.roland-riegel.de/nload/index.html --- src/setting.h | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/setting.h (limited to 'src/setting.h') diff --git a/src/setting.h b/src/setting.h new file mode 100644 index 0000000..eef52f5 --- /dev/null +++ b/src/setting.h @@ -0,0 +1,88 @@ +/*************************************************************************** + setting.h + ------------------- + begin : Tue Nov 06 2007 + copyright : (C) 2007 - 2012 by Roland Riegel + email : feedback@roland-riegel.de + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef SETTING_H +#define SETTING_H + +#include "stringutils.h" + +#include +#include +#include + +class SettingFilter; + +class Setting +{ + public: + Setting(const std::string& id = "", const std::string& description = "") + : m_id(id), m_description(description), m_value() {} + template + Setting(const std::string& id, const std::string& description, const T& value) + : m_id(id), m_description(description), m_value(toString(value)) {} + ~Setting(); + + const std::string& getId() const { return m_id; } + const std::string& getDescription() const { return m_description; } + const std::string& getValue() const { return m_value; } + + void setId(const std::string& id) { m_id = id; } + void setDescription(const std::string& description) { m_description = description; } + + void pushFilter(SettingFilter* filter); + void popFilter(); + SettingFilter* findFilterWithId(const std::string& id); + const SettingFilter* findFilterWithId(const std::string& id) const; + + std::string getThroughFilter() const; + bool setThroughFilter(const std::string& value); + + template + operator T() { return fromString(m_value); } + + template + Setting& operator=(const T& t) { m_value = toString(t); return *this; } + + template + bool operator==(const T& t) const { return toString(t) == m_value; } + template + bool operator!=(const T& t) const { return toString(t) != m_value; } + template + bool operator<(const T& t) const { return fromString(m_value) < t; } + template + bool operator>(const T& t) const { return fromString(m_value) > t; } + template + bool operator<=(const T& t) const { return fromString(m_value) <= t; } + template + bool operator>=(const T& t) const { return fromString(m_value) >= t; } + + bool operator==(const Setting& s) const { return s.m_value == m_value; } + bool operator!=(const Setting& s) const { return s.m_value != m_value; } + + private: + std::string m_id; + std::string m_description; + std::string m_value; + + std::list m_filters; +}; + +std::istream& operator>>(std::istream& in, Setting& setting); +std::ostream& operator<<(std::ostream& out, const Setting& setting); + +#endif + -- cgit v1.2.3