root/branches/streaming-rework/src/libutil/serialize.h

Revision 372, 3.4 kB (checked in by wagi, 17 years ago)

AvPlug::serialize: finished implementation (untested yet)
AvPlug::deserialize: likewise
AvPlug::deserializeUpdate: new function. second stage of deserializing
IODeserialize::isExisting: new function

Line 
1 /* serialize.h
2  * Copyright (C) 2007 by Daniel Wagner
3  *
4  * This file is part of FreeBoB.
5  *
6  * FreeBoB is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * FreeBoB is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with FreeBoB; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18  * MA 02111-1307 USA.
19  */
20
21 #ifndef bebob_serialize_h
22 #define bebob_serialize_h
23
24 #include <libxml++/libxml++.h>
25
26 #include <iostream>
27
28 namespace Util {
29
30      class IOSerialize {
31      public:
32          IOSerialize() {}
33          virtual ~IOSerialize() {}
34
35          virtual bool write( std::string strMemberName,
36                              long long value ) = 0;
37          virtual bool write( std::string strMemberName,
38                              Glib::ustring str) = 0;
39
40          template <typename T>  bool write( std::string strMemberName, T value );
41      };
42
43     class IODeserialize {
44     public:
45         IODeserialize() {}
46         virtual ~IODeserialize() {}
47
48         virtual bool read( std::string strMemberName,
49                            long long& value ) = 0;
50         virtual bool read( std::string strMemberName,
51                            Glib::ustring& str ) = 0;
52
53         template <typename T> bool read( std::string strMemberName, T& value );
54
55         virtual bool isExisting( std::string strMemberName ) = 0;
56     };
57
58     class XMLSerialize: public IOSerialize {
59     public:
60         XMLSerialize( Glib::ustring fileName );
61         virtual ~XMLSerialize();
62
63         virtual bool write( std::string strMemberName,
64                             long long value );
65         virtual bool write( std::string strMemberName,
66                             Glib::ustring str);
67     private:
68         Glib::ustring    m_filepath;
69         xmlpp::Document  m_doc;
70
71         xmlpp::Node* getNodePath( xmlpp::Node* pRootNode,
72                                   std::vector<std::string>& tokens );
73     };
74
75     class XMLDeserialize: public IODeserialize {
76     public:
77         XMLDeserialize( Glib::ustring fileName );
78         virtual ~XMLDeserialize();
79
80         virtual bool read( std::string strMemberName,
81                            long long& value );
82         virtual bool read( std::string strMemberName,
83                            Glib::ustring& str );
84
85         virtual bool isExisting( std::string strMemberName );
86
87     private:
88         Glib::ustring    m_filepath;
89         xmlpp::DomParser m_parser;
90     };
91
92
93 //////////////////////////////////////////
94
95     template <typename T> bool IOSerialize::write( std::string strMemberName,
96                                                    T value )
97     {
98         return write( strMemberName, static_cast<long long>( value ) );
99     }
100
101     template <typename T> bool IODeserialize::read( std::string strMemberName,
102                                                     T& value )
103     {
104         long long tmp;
105         bool result = read( strMemberName, tmp );
106         value = static_cast<T>( tmp );
107         return result;
108     }
109 }
110
111 #endif
Note: See TracBrowser for help on using the browser.