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

Revision 516, 3.7 kB (checked in by wagi, 17 years ago)

- some de/serialing bugs found and fixed
- caching enabled for bebob devices

(finally online again! big thanks to my free wireless internet provider. s/he is finally back from
her/his holiday :)

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 library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License version 2.1, as published by the Free Software Foundation;
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21  * MA 02110-1301 USA
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 #endif
Note: See TracBrowser for help on using the browser.