root/trunk/libffado/src/libutil/OptionContainer.h

Revision 864, 4.9 kB (checked in by ppalmers, 16 years ago)

update license to GPLv2 or GPLv3 instead of GPLv2 or any later version. Update copyrights to reflect the new year

Line 
1 /*
2  * Copyright (C) 2005-2008 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 2 of the License, or
12  * (at your option) version 3 of the License.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #ifndef __FFADO_OPTIONCONTAINER__
25 #define __FFADO_OPTIONCONTAINER__
26
27 #include "../debugmodule/debugmodule.h"
28 #include "libutil/serialize.h"
29
30 #include <vector>
31 #include <string>
32
33 namespace Util {
34
35 class OptionContainer {
36
37 protected:
38     class Option {
39     public:
40         enum EType {
41             EInvalid = 0,
42             EString = 1,
43             EBool = 2,
44             EDouble = 3,
45             EInt = 4,
46             EUInt = 5,
47         };
48
49     public:
50         Option();
51         Option(std::string);
52         Option(std::string, std::string);
53         Option(std::string, bool);
54         Option(std::string, double);
55         Option(std::string, int64_t);
56         Option(std::string, uint64_t);
57
58         ~Option() {};
59
60         std::string getName() {return m_Name;};
61         enum EType getType() {return m_Type;};
62
63         void set(std::string v);
64         void set(bool v);
65         void set(double v);
66         void set(int64_t v);
67         void set(uint64_t v);
68
69         std::string getString() {return m_stringValue;};
70         bool getBool() {return m_boolValue;};
71         double getDouble() {return m_doubleValue;};
72         int64_t getInt() {return m_intValue;};
73         uint64_t getUInt() {return m_uintValue;};
74
75     public: // serialization support
76         bool serialize( Glib::ustring basePath, Util::IOSerialize& ser ) const;
77         static Option deserialize( Glib::ustring basePath,
78                                     Util::IODeserialize& deser);
79     private:
80         std::string m_Name;
81
82         std::string m_stringValue;
83
84         bool        m_boolValue;
85         double      m_doubleValue;
86         int64_t     m_intValue;
87         uint64_t    m_uintValue;
88
89         enum EType  m_Type;
90     };
91
92 public:
93
94     OptionContainer();
95     virtual ~OptionContainer();
96
97     bool setOption(std::string name, std::string v);
98     bool setOption(std::string name, bool v);
99     bool setOption(std::string name, double v);
100     bool setOption(std::string name, int64_t v);
101     bool setOption(std::string name, uint64_t v);
102     bool setOption(std::string name, int32_t v);
103     bool setOption(std::string name, uint32_t v);
104     bool setOption(std::string name, int16_t v);
105     bool setOption(std::string name, uint16_t v);
106     bool setOption(std::string name, int8_t v);
107     bool setOption(std::string name, uint8_t v);
108
109     bool getOption(std::string name, std::string &v);
110     bool getOption(std::string name, bool &v);
111     bool getOption(std::string name, double &v);
112     bool getOption(std::string name, float &v);
113     bool getOption(std::string name, int64_t &v);
114     bool getOption(std::string name, uint64_t &v);
115     bool getOption(std::string name, int32_t &v);
116     bool getOption(std::string name, uint32_t &v);
117     bool getOption(std::string name, int16_t &v);
118     bool getOption(std::string name, uint16_t &v);
119     bool getOption(std::string name, int8_t &v);
120     bool getOption(std::string name, uint8_t &v);
121
122     Option::EType getOptionType(std::string name);
123
124     bool hasOption(std::string name);
125
126     int countOptions() {return m_Options.size();};
127
128 protected:
129     bool setOption(Option o);
130     Option getOption(std::string name);
131
132     bool hasOption(Option o);
133
134     bool addOption(Option o);
135
136     bool removeOption(Option o);
137     bool removeOption(std::string name);
138
139     void clearOptions() {m_Options.clear();};
140
141 public: // provide an iterator interface
142
143     typedef std::vector< Option >::iterator iterator;
144     iterator begin()
145     {
146         return(m_Options.begin());
147     }
148
149     iterator end()
150     {
151         return(m_Options.end());
152     }
153
154 protected: // serialization support
155     bool serializeOptions( Glib::ustring basePath,
156                            Util::IOSerialize& ser) const;
157     static bool deserializeOptions( Glib::ustring basePath,
158                                     Util::IODeserialize& deser,
159                                     OptionContainer& container);
160
161 private:
162     int findOption(Option o);
163     int findOption(std::string name);
164
165     typedef std::vector< Option > OptionVector;
166     typedef std::vector< Option >::iterator OptionVectorIterator;
167     OptionVector m_Options;
168
169 protected:
170     DECLARE_DEBUG_MODULE;
171
172 };
173
174 } // end of namespace Util
175
176 #endif /* __FFADO_OPTIONCONTAINER__ */
177
178
Note: See TracBrowser for help on using the browser.