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 |
void writeVersion(); |
---|
75 |
|
---|
76 |
Glib::ustring m_filepath; |
---|
77 |
xmlpp::Document m_doc; |
---|
78 |
int m_verboseLevel; |
---|
79 |
|
---|
80 |
DECLARE_DEBUG_MODULE; |
---|
81 |
|
---|
82 |
xmlpp::Node* getNodePath( xmlpp::Node* pRootNode, |
---|
83 |
std::vector<std::string>& tokens ); |
---|
84 |
}; |
---|
85 |
|
---|
86 |
class XMLDeserialize: public IODeserialize { |
---|
87 |
public: |
---|
88 |
XMLDeserialize( Glib::ustring fileName ); |
---|
89 |
XMLDeserialize( Glib::ustring fileName, int verboseLevel ); |
---|
90 |
virtual ~XMLDeserialize(); |
---|
91 |
|
---|
92 |
virtual bool read( std::string strMemberName, |
---|
93 |
long long& value ); |
---|
94 |
virtual bool read( std::string strMemberName, |
---|
95 |
Glib::ustring& str ); |
---|
96 |
|
---|
97 |
virtual bool isExisting( std::string strMemberName ); |
---|
98 |
bool isValid(); |
---|
99 |
bool checkVersion(); |
---|
100 |
private: |
---|
101 |
Glib::ustring m_filepath; |
---|
102 |
xmlpp::DomParser m_parser; |
---|
103 |
int m_verboseLevel; |
---|
104 |
|
---|
105 |
DECLARE_DEBUG_MODULE; |
---|
106 |
}; |
---|
107 |
|
---|
108 |
|
---|
109 |
////////////////////////////////////////// |
---|
110 |
|
---|
111 |
template <typename T> bool IOSerialize::write( std::string strMemberName, |
---|
112 |
T value ) |
---|
113 |
{ |
---|
114 |
return write( strMemberName, static_cast<long long>( value ) ); |
---|
115 |
} |
---|
116 |
|
---|
117 |
template <typename T> bool IODeserialize::read( std::string strMemberName, |
---|
118 |
T& value ) |
---|
119 |
{ |
---|
120 |
long long tmp; |
---|
121 |
bool result = read( strMemberName, tmp ); |
---|
122 |
value = static_cast<T>( tmp ); |
---|
123 |
return result; |
---|
124 |
} |
---|
125 |
} |
---|
126 |
|
---|
127 |
void tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters = " "); |
---|
128 |
|
---|
129 |
#endif |
---|