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

Revision 742, 3.8 kB (checked in by ppalmers, 13 years ago)

- Remove some obsolete support files and dirs

- Clean up the license statements in the source files. Everything is

GPL version 3 now.

- Add license and copyright notices to scons scripts

- Clean up some other text files

Line 
1 /*
2  * Copyright (C) 2005-2007 by Daniel Wagner
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 3 of the License, or
12  * (at your option) any later version.
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 bebob_serialize_h
25 #define bebob_serialize_h
26
27 #include "debugmodule/debugmodule.h"
28
29 #include <libxml++/libxml++.h>
30
31 #include <iostream>
32
33 namespace Util {
34
35      class IOSerialize {
36      public:
37          IOSerialize() {}
38          virtual ~IOSerialize() {}
39
40          virtual bool write( std::string strMemberName,
41                              long long value ) = 0;
42          virtual bool write( std::string strMemberName,
43                              Glib::ustring str) = 0;
44
45          template <typename T>  bool write( std::string strMemberName, T value );
46      };
47
48     class IODeserialize {
49     public:
50         IODeserialize() {}
51         virtual ~IODeserialize() {}
52
53         virtual bool read( std::string strMemberName,
54                            long long& value ) = 0;
55         virtual bool read( std::string strMemberName,
56                            Glib::ustring& str ) = 0;
57
58         template <typename T> bool read( std::string strMemberName, T& value );
59
60         virtual bool isExisting( std::string strMemberName ) = 0;
61     };
62
63     class XMLSerialize: public IOSerialize {
64     public:
65         XMLSerialize( Glib::ustring fileName );
66         XMLSerialize( Glib::ustring fileName, int verboseLevel );
67         virtual ~XMLSerialize();
68
69         virtual bool write( std::string strMemberName,
70                             long long value );
71         virtual bool write( std::string strMemberName,
72                             Glib::ustring str);
73     private:
74         Glib::ustring    m_filepath;
75         xmlpp::Document  m_doc;
76         int              m_verboseLevel;
77
78         DECLARE_DEBUG_MODULE;
79
80         xmlpp::Node* getNodePath( xmlpp::Node* pRootNode,
81                                   std::vector<std::string>& tokens );
82     };
83
84     class XMLDeserialize: public IODeserialize {
85     public:
86         XMLDeserialize( Glib::ustring fileName );
87         XMLDeserialize( Glib::ustring fileName, int verboseLevel );
88         virtual ~XMLDeserialize();
89
90         virtual bool read( std::string strMemberName,
91                            long long& value );
92         virtual bool read( std::string strMemberName,
93                            Glib::ustring& str );
94
95         virtual bool isExisting( std::string strMemberName );
96
97     private:
98         Glib::ustring    m_filepath;
99         xmlpp::DomParser m_parser;
100         int              m_verboseLevel;
101
102         DECLARE_DEBUG_MODULE;
103     };
104
105
106 //////////////////////////////////////////
107
108     template <typename T> bool IOSerialize::write( std::string strMemberName,
109                                                    T value )
110     {
111         return write( strMemberName, static_cast<long long>( value ) );
112     }
113
114     template <typename T> bool IODeserialize::read( std::string strMemberName,
115                                                     T& value )
116     {
117         long long tmp;
118         bool result = read( strMemberName, tmp );
119         value = static_cast<T>( tmp );
120         return result;
121     }
122 }
123
124 void tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters = " ");
125
126 #endif
Note: See TracBrowser for help on using the browser.