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 |
#include <stdint.h> |
---|
33 |
|
---|
34 |
namespace Util { |
---|
35 |
|
---|
36 |
class OptionContainer { |
---|
37 |
|
---|
38 |
protected: |
---|
39 |
class Option { |
---|
40 |
public: |
---|
41 |
enum EType { |
---|
42 |
EInvalid = 0, |
---|
43 |
EString = 1, |
---|
44 |
EBool = 2, |
---|
45 |
EDouble = 3, |
---|
46 |
EInt = 4, |
---|
47 |
EUInt = 5, |
---|
48 |
}; |
---|
49 |
|
---|
50 |
public: |
---|
51 |
Option(); |
---|
52 |
Option(std::string); |
---|
53 |
Option(std::string, std::string); |
---|
54 |
Option(std::string, bool); |
---|
55 |
Option(std::string, double); |
---|
56 |
Option(std::string, int64_t); |
---|
57 |
Option(std::string, uint64_t); |
---|
58 |
|
---|
59 |
~Option() {}; |
---|
60 |
|
---|
61 |
std::string getName() {return m_Name;}; |
---|
62 |
enum EType getType() {return m_Type;}; |
---|
63 |
|
---|
64 |
void set(std::string v); |
---|
65 |
void set(bool v); |
---|
66 |
void set(double v); |
---|
67 |
void set(int64_t v); |
---|
68 |
void set(uint64_t v); |
---|
69 |
|
---|
70 |
std::string getString() {return m_stringValue;}; |
---|
71 |
bool getBool() {return m_boolValue;}; |
---|
72 |
double getDouble() {return m_doubleValue;}; |
---|
73 |
int64_t getInt() {return m_intValue;}; |
---|
74 |
uint64_t getUInt() {return m_uintValue;}; |
---|
75 |
|
---|
76 |
public: // serialization support |
---|
77 |
bool serialize( std::string basePath, Util::IOSerialize& ser ) const; |
---|
78 |
static Option deserialize( std::string basePath, |
---|
79 |
Util::IODeserialize& deser); |
---|
80 |
private: |
---|
81 |
std::string m_Name; |
---|
82 |
|
---|
83 |
std::string m_stringValue; |
---|
84 |
|
---|
85 |
bool m_boolValue; |
---|
86 |
double m_doubleValue; |
---|
87 |
int64_t m_intValue; |
---|
88 |
uint64_t m_uintValue; |
---|
89 |
|
---|
90 |
enum EType m_Type; |
---|
91 |
}; |
---|
92 |
|
---|
93 |
public: |
---|
94 |
|
---|
95 |
OptionContainer(); |
---|
96 |
virtual ~OptionContainer(); |
---|
97 |
|
---|
98 |
bool setOption(std::string name, std::string v); |
---|
99 |
bool setOption(std::string name, bool v); |
---|
100 |
bool setOption(std::string name, double v); |
---|
101 |
bool setOption(std::string name, int64_t v); |
---|
102 |
bool setOption(std::string name, uint64_t v); |
---|
103 |
bool setOption(std::string name, int32_t v); |
---|
104 |
bool setOption(std::string name, uint32_t v); |
---|
105 |
bool setOption(std::string name, int16_t v); |
---|
106 |
bool setOption(std::string name, uint16_t v); |
---|
107 |
bool setOption(std::string name, int8_t v); |
---|
108 |
bool setOption(std::string name, uint8_t v); |
---|
109 |
|
---|
110 |
bool getOption(std::string name, std::string &v); |
---|
111 |
bool getOption(std::string name, bool &v); |
---|
112 |
bool getOption(std::string name, double &v); |
---|
113 |
bool getOption(std::string name, float &v); |
---|
114 |
bool getOption(std::string name, int64_t &v); |
---|
115 |
bool getOption(std::string name, uint64_t &v); |
---|
116 |
bool getOption(std::string name, int32_t &v); |
---|
117 |
bool getOption(std::string name, uint32_t &v); |
---|
118 |
bool getOption(std::string name, int16_t &v); |
---|
119 |
bool getOption(std::string name, uint16_t &v); |
---|
120 |
bool getOption(std::string name, int8_t &v); |
---|
121 |
bool getOption(std::string name, uint8_t &v); |
---|
122 |
|
---|
123 |
Option::EType getOptionType(std::string name); |
---|
124 |
|
---|
125 |
bool hasOption(std::string name); |
---|
126 |
|
---|
127 |
int countOptions() {return m_Options.size();}; |
---|
128 |
|
---|
129 |
protected: |
---|
130 |
bool setOption(Option o); |
---|
131 |
Option getOption(std::string name); |
---|
132 |
|
---|
133 |
bool hasOption(Option o); |
---|
134 |
|
---|
135 |
bool addOption(Option o); |
---|
136 |
|
---|
137 |
bool removeOption(Option o); |
---|
138 |
bool removeOption(std::string name); |
---|
139 |
|
---|
140 |
void clearOptions() {m_Options.clear();}; |
---|
141 |
|
---|
142 |
public: // provide an iterator interface |
---|
143 |
|
---|
144 |
typedef std::vector< Option >::iterator iterator; |
---|
145 |
iterator begin() |
---|
146 |
{ |
---|
147 |
return(m_Options.begin()); |
---|
148 |
} |
---|
149 |
|
---|
150 |
iterator end() |
---|
151 |
{ |
---|
152 |
return(m_Options.end()); |
---|
153 |
} |
---|
154 |
|
---|
155 |
protected: // serialization support |
---|
156 |
bool serializeOptions( std::string basePath, |
---|
157 |
Util::IOSerialize& ser) const; |
---|
158 |
static bool deserializeOptions( std::string basePath, |
---|
159 |
Util::IODeserialize& deser, |
---|
160 |
OptionContainer& container); |
---|
161 |
|
---|
162 |
private: |
---|
163 |
int findOption(Option o); |
---|
164 |
int findOption(std::string name); |
---|
165 |
|
---|
166 |
typedef std::vector< Option > OptionVector; |
---|
167 |
typedef std::vector< Option >::iterator OptionVectorIterator; |
---|
168 |
OptionVector m_Options; |
---|
169 |
|
---|
170 |
protected: |
---|
171 |
DECLARE_DEBUG_MODULE; |
---|
172 |
|
---|
173 |
}; |
---|
174 |
|
---|
175 |
} // end of namespace Util |
---|
176 |
|
---|
177 |
#endif /* __FFADO_OPTIONCONTAINER__ */ |
---|
178 |
|
---|
179 |
|
---|