1 /***************************************************************************
2                                settingfilter.h
3                              -------------------
4     begin                : Wed Nov 28 2007
5     copyright            : (C) 2007 - 2012 by Roland Riegel
6     email                : feedback@roland-riegel.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef SETTINGFILTER_H
19 #define SETTINGFILTER_H
20 
21 #include <map>
22 #include <string>
23 
24 class SettingFilter
25 {
26     public:
~SettingFilter()27         virtual ~SettingFilter() {}
28 
29         virtual std::string getId() const = 0;
30 
31         virtual bool filterWrite(std::string& valueNew) = 0;
32         virtual void filterRead(std::string& value) = 0;
33 };
34 
35 class SettingFilterDefault : public SettingFilter
36 {
37     public:
38         SettingFilterDefault(const std::string& def);
39         ~SettingFilterDefault();
40 
41         std::string getId() const;
42 
43         void setDefault(const std::string& def);
44         const std::string& getDefault() const;
45 
46         bool filterWrite(std::string& valueNew);
47         void filterRead(std::string& value);
48 
49     private:
50         std::string m_default;
51 };
52 
53 class SettingFilterExclusive : public SettingFilter
54 {
55     public:
56         SettingFilterExclusive(const std::string& exclusive);
57         ~SettingFilterExclusive();
58 
59         std::string getId() const;
60 
61         void setExclusive(const std::string& exclusive);
62         const std::string& getExclusive() const;
63 
64         bool filterWrite(std::string& valueNew);
65         void filterRead(std::string& value);
66 
67     private:
68         void substituteExclusive(std::string& value);
69 
70         std::string m_exclusive;
71 };
72 
73 class SettingFilterMap : public SettingFilter
74 {
75     public:
76         SettingFilterMap(const std::map<std::string, std::string>& filterMap);
77         ~SettingFilterMap();
78 
79         std::string getId() const;
80 
81         void setMap(const std::map<std::string, std::string>& filterMap);
82         const std::map<std::string, std::string>& getMap() const;
83 
84         bool filterWrite(std::string& valueNew);
85         void filterRead(std::string& value);
86 
87     private:
88         std::map<std::string, std::string> m_filterMap;
89 };
90 
91 class SettingFilterMin : public SettingFilter
92 {
93     public:
94         SettingFilterMin(int min);
95         ~SettingFilterMin();
96 
97         std::string getId() const;
98 
99         void setMin(int min);
100         int getMin() const;
101 
102         bool filterWrite(std::string& valueNew);
103         void filterRead(std::string& value);
104 
105     private:
106         int m_min;
107 };
108 
109 class SettingFilterMax : public SettingFilter
110 {
111     public:
112         SettingFilterMax(int max);
113         ~SettingFilterMax();
114 
115         std::string getId() const;
116 
117         void setMax(int max);
118         int getMax() const;
119 
120         bool filterWrite(std::string& valueNew);
121         void filterRead(std::string& value);
122 
123     private:
124         int m_max;
125 };
126 
127 #endif
128 
129