root/trunk/libfreebob/src/libfreebobavc/avc_serialize.h

Revision 365, 3.6 kB (checked in by wagi, 17 years ago)

src/libfreebobavc/serialize* moved to src/libfreebob/avc_serialize*, all includes adapted
src/bebob/bebob_serialize* moved to src/libutil/serialize*
src/libutil/serialize: use Glib::ustring instead of std::string.
src/configrom: serialize and deserialize added (not finished)
src/devicemanager: load and save cached functionality added (not finished)

various small whitespace updates (emacs lässt grüssen :))

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /* avc_serialize.h
2  * Copyright (C) 2005,07 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 Serialize_h
22 #define Serialize_h
23
24 #include <libraw1394/raw1394.h> // byte_t and quadlet_t declaration
25 #include <string>
26
27 // Interfaces
28
29 class IOSSerialize {
30 public:
31     IOSSerialize() {}
32     virtual ~IOSSerialize() {}
33
34     virtual bool write( byte_t value, const char* name = "" ) = 0;
35     virtual bool write( quadlet_t value, const char* name = "" ) = 0;
36 };
37
38 class IISDeserialize {
39 public:
40     IISDeserialize() {}
41     virtual ~IISDeserialize() {}
42
43     virtual bool read( byte_t* value ) = 0;
44     virtual bool read( quadlet_t* value ) = 0;
45     virtual bool read( char** value, size_t length ) = 0;
46     virtual bool peek( byte_t* value ) = 0;
47 };
48
49 // Specialized implementations of previously defined interfaces
50
51 class CoutSerializer: public IOSSerialize {
52 public:
53     CoutSerializer()
54         : IOSSerialize()
55         , m_cnt( 0 )
56         {}
57     virtual ~CoutSerializer() {}
58
59     virtual bool write( byte_t value, const char* name = "" );
60     virtual bool write( quadlet_t value,  const char* name = "" );
61
62 private:
63     unsigned int m_cnt;
64
65 };
66
67 class StringSerializer: public IOSSerialize {
68 public:
69     StringSerializer()
70         : IOSSerialize()
71         , m_cnt( 0 )
72         {}
73     virtual ~StringSerializer() {}
74
75     virtual bool write( byte_t value, const char* name = "" );
76     virtual bool write( quadlet_t value,  const char* name = "" );
77     virtual std::string getString( ) { return m_string;};
78
79 private:
80     unsigned int m_cnt;
81     std::string m_string;
82
83 };
84
85 class BufferSerialize: public IOSSerialize {
86 public:
87     BufferSerialize( unsigned char* buffer, size_t length )
88         : IOSSerialize()
89         , m_buffer( buffer )
90         , m_curPos( m_buffer )
91         , m_length( length )
92         {}
93     virtual ~BufferSerialize() {}
94
95     virtual bool write( byte_t value, const char* name = "" );
96     virtual bool write( quadlet_t value,  const char* name = "" );
97
98     int getNrOfProducesBytes() const
99         { return m_curPos - m_buffer; }
100
101 protected:
102     inline bool isCurPosValid() const;
103
104 private:
105     unsigned char* m_buffer;
106     unsigned char* m_curPos;
107     size_t m_length;
108 };
109
110 class BufferDeserialize: public IISDeserialize {
111 public:
112     BufferDeserialize( const unsigned char* buffer, size_t length )
113         : IISDeserialize()
114         , m_buffer( const_cast<unsigned char*>( buffer ) )
115         , m_curPos( m_buffer )
116         , m_length( length )
117         {}
118     virtual ~BufferDeserialize() {}
119
120     virtual bool read( byte_t* value );
121     virtual bool read( quadlet_t* value );
122     virtual bool read( char** value, size_t length );
123     virtual bool peek( byte_t* value );
124
125     int getNrOfConsumedBytes()  const
126         { return m_curPos - m_buffer; }
127
128 protected:
129     inline bool isCurPosValid() const;
130
131 private:
132     unsigned char* m_buffer; // start of the buffer
133     unsigned char* m_curPos; // current read pos
134     size_t m_length;         // size of buffer
135 };
136
137 #endif // Serialize_h
138
Note: See TracBrowser for help on using the browser.