root/branches/streaming-rework/src/libutil/OptionContainer.h

Revision 418, 5.2 kB (checked in by pieterpalmers, 17 years ago)

added serialization support to the OptionContainer?

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