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

Revision 1154, 4.0 kB (checked in by ppalmers, 14 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  * Copyright (C) 2005-2008 by Pieter Palmers
4  *
5  * This file is part of FFADO
6  * FFADO = Free Firewire (pro-)audio drivers for linux
7  *
8  * FFADO is based upon FreeBoB.
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 2 of the License, or
13  * (at your option) version 3 of the License.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24
25 #ifndef __FFADO_UTIL_SERIALIZE_EXPAT_H__
26 #define __FFADO_UTIL_SERIALIZE_EXPAT_H__
27
28 #include "debugmodule/debugmodule.h"
29
30 #include "serialize_expat_xml.h"
31
32 #include <iostream>
33 #include <string>
34
35 namespace Util {
36
37      class IOSerialize {
38      public:
39          IOSerialize() {}
40          virtual ~IOSerialize() {}
41
42          virtual bool write( std::string strMemberName,
43                              long long value ) = 0;
44          virtual bool write( std::string strMemberName,
45                              std::string str) = 0;
46
47          template <typename T>  bool write( std::string strMemberName, T value );
48      };
49
50     class IODeserialize {
51     public:
52         IODeserialize() {}
53         virtual ~IODeserialize() {}
54
55         virtual bool read( std::string strMemberName,
56                            long long& value ) = 0;
57         virtual bool read( std::string strMemberName,
58                            std::string& str ) = 0;
59
60         template <typename T> bool read( std::string strMemberName, T& value );
61
62         virtual bool isExisting( std::string strMemberName ) = 0;
63     };
64
65     class XMLSerialize: public IOSerialize {
66     public:
67         XMLSerialize( std::string fileName );
68         XMLSerialize( std::string fileName, int verboseLevel );
69         virtual ~XMLSerialize();
70
71         virtual bool write( std::string strMemberName,
72                             long long value );
73         virtual bool write( std::string strMemberName,
74                             std::string str);
75     private:
76         void writeVersion();
77
78         std::string      m_filepath;
79         Xml::Document    m_doc;
80         int              m_verboseLevel;
81
82         DECLARE_DEBUG_MODULE;
83
84         Xml::Node* getNodePath( Xml::Node* pRootNode,
85                                 std::vector<std::string>& tokens );
86     };
87
88     class XMLDeserialize: public IODeserialize {
89     public:
90         XMLDeserialize( std::string fileName );
91         XMLDeserialize( std::string fileName, int verboseLevel );
92         virtual ~XMLDeserialize();
93
94         virtual bool read( std::string strMemberName,
95                            long long& value );
96         virtual bool read( std::string strMemberName,
97                            std::string& str );
98
99         virtual bool isExisting( std::string strMemberName );
100         bool isValid();
101         bool checkVersion();
102     private:
103         std::string      m_filepath;
104         Xml::Document    m_doc;
105         int              m_verboseLevel;
106
107         DECLARE_DEBUG_MODULE;
108     };
109
110
111 //////////////////////////////////////////
112
113     template <typename T> bool IOSerialize::write( std::string strMemberName,
114                                                    T value )
115     {
116         return write( strMemberName, static_cast<long long>( value ) );
117     }
118
119     template <typename T> bool IODeserialize::read( std::string strMemberName,
120                                                     T& value )
121     {
122         long long tmp;
123         bool result = read( strMemberName, tmp );
124         value = static_cast<T>( tmp );
125         return result;
126     }
127 }
128
129 void tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters = " ");
130
131 #endif
Note: See TracBrowser for help on using the browser.