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

Revision 445, 3.4 kB (checked in by pieterpalmers, 15 years ago)

* name change from FreeBoB to FFADO
* replaced tabs by 4 spaces
* got rid of end-of-line spaces
* made all license and copyrights conform

library becomes LGPL, apps become GPL
explicitly state LGPL v2.1 and GPL v2 (don't like v3 draft)

copyrights are 2005-2007 Daniel & Pieter
except for the MotU stuff (C) Jonathan, Pieter

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 <libxml++/libxml++.h>
28
29 #include <iostream>
30
31 namespace Util {
32
33      class IOSerialize {
34      public:
35          IOSerialize() {}
36          virtual ~IOSerialize() {}
37
38          virtual bool write( std::string strMemberName,
39                              long long value ) = 0;
40          virtual bool write( std::string strMemberName,
41                              Glib::ustring str) = 0;
42
43          template <typename T>  bool write( std::string strMemberName, T value );
44      };
45
46     class IODeserialize {
47     public:
48         IODeserialize() {}
49         virtual ~IODeserialize() {}
50
51         virtual bool read( std::string strMemberName,
52                            long long& value ) = 0;
53         virtual bool read( std::string strMemberName,
54                            Glib::ustring& str ) = 0;
55
56         template <typename T> bool read( std::string strMemberName, T& value );
57
58         virtual bool isExisting( std::string strMemberName ) = 0;
59     };
60
61     class XMLSerialize: public IOSerialize {
62     public:
63         XMLSerialize( Glib::ustring fileName );
64         virtual ~XMLSerialize();
65
66         virtual bool write( std::string strMemberName,
67                             long long value );
68         virtual bool write( std::string strMemberName,
69                             Glib::ustring str);
70     private:
71         Glib::ustring    m_filepath;
72         xmlpp::Document  m_doc;
73
74         xmlpp::Node* getNodePath( xmlpp::Node* pRootNode,
75                                   std::vector<std::string>& tokens );
76     };
77
78     class XMLDeserialize: public IODeserialize {
79     public:
80         XMLDeserialize( Glib::ustring fileName );
81         virtual ~XMLDeserialize();
82
83         virtual bool read( std::string strMemberName,
84                            long long& value );
85         virtual bool read( std::string strMemberName,
86                            Glib::ustring& str );
87
88         virtual bool isExisting( std::string strMemberName );
89
90     private:
91         Glib::ustring    m_filepath;
92         xmlpp::DomParser m_parser;
93     };
94
95
96 //////////////////////////////////////////
97
98     template <typename T> bool IOSerialize::write( std::string strMemberName,
99                                                    T value )
100     {
101         return write( strMemberName, static_cast<long long>( value ) );
102     }
103
104     template <typename T> bool IODeserialize::read( std::string strMemberName,
105                                                     T& value )
106     {
107         long long tmp;
108         bool result = read( strMemberName, tmp );
109         value = static_cast<T>( tmp );
110         return result;
111     }
112 }
113
114 #endif
Note: See TracBrowser for help on using the browser.