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

Revision 1154, 3.9 kB (checked in by ppalmers, 16 years ago)

add expat based parsing of the device cache. add compile-time selection between libxml++ and expat. will allow to get rid of the libxml++ dependency on the long run. scons SERIALIZE_USE_EXPAT=0Only compile testedscons SERIALIZE_USE_EXPAT=0

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