Subversion Repositories spk

Rev

Rev 1 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1 Rev 114
Line 6... Line 6...
6
#define BOB_DOM_BASE_INCLUDED
6
#define BOB_DOM_BASE_INCLUDED
7
 
7
 
8
#include "../common/ext_list.h"
8
#include "../common/ext_list.h"
9
#include "bob_names.h"
9
#include "bob_names.h"
10
 
10
 
11
#include "bob_dom_stream.h"
11
#include "bob_stream.h"
12
#include "bob_dom_filestream.h"
-
 
13
 
12
 
14
#include <string.h>
13
#include <string.h>
15
#include <stdarg.h>
14
#include <stdarg.h>
16
 
15
 
17
class bob_dom_section;
16
class bob_section;
18
class bob_dom_string;
17
class bob_string;
19
class bob_dom_info;
18
class bob_info;
20
 
19
 
21
enum bob_error_codes
20
enum bob_error_codes
22
{
21
{
23
	e_noError,
22
	e_noError,
24
	e_badHeader,
23
	e_badHeader,
25
	e_badEndHeader,
24
	e_badEndHeader,
26
	e_notEnoughData,
25
	e_notEnoughData,
27
	e_moreData,
26
	e_moreData,
28
	e_unkPointHeader,
27
	e_unkPointFlags,
29
	e_error,
28
	e_error,
30
	e_format_noStatFormat,
29
	e_format_noStatFormat,
31
	e_format_notEnoughData,
30
	e_format_notEnoughData,
32
	e_format_UserWarning,
31
	e_format_UserWarning,
33
	e_pointNotFound,
32
	e_pointNotFound,
Line 41... Line 40...
41
	s_warning,
40
	s_warning,
42
	s_error
41
	s_error
43
};
42
};
44
 
43
 
45
const char* bob_traslate_error(bob_error_codes code);
44
const char* bob_traslate_error(bob_error_codes code);
46
int peek(bob_dom_ibinaryfilestream& is);
45
int peek(ibinaryfilestream& is);
47
 
46
 
48
class bob_with_errors
47
class bob_with_errors
49
{
48
{
50
	protected:
49
	protected:
51
		void error(bob_error_codes code);
50
		void error(bob_error_codes code);
52
		void error(bob_error_severity severity, bob_error_codes code);
51
		void error(bob_error_severity severity, bob_error_codes code);
53
		void error(bob_error_codes code, const char *format, ...);
52
		void error(bob_error_codes code, const char *format, ...);
54
		void error(bob_error_severity severity, bob_error_codes code, const char *format, ...);
53
		void error(bob_error_severity severity, bob_error_codes code, const char *format, ...);
55
		void verror(bob_error_severity severity, bob_error_codes code, const char *format, va_list ap);
54
		void verror(bob_error_severity severity, bob_error_codes code, const char *format, va_list ap);
56
		
55
 
57
	public:
56
	public:
58
		struct bob_error
57
		struct bob_error
59
		{
58
		{
60
			bob_error_codes code;
59
			bob_error_codes code;
61
			bob_error_severity severity;
60
			bob_error_severity severity;
62
			char text[255];
61
			char text[255];
63
		};
62
		};
64
		
63
 
65
		typedef ext::list<bob_error*> ErrorList;
64
		typedef ext::list<bob_error*> ErrorList;
66
		typedef ext::list<bob_error*>::iterator ErrorIterator;
65
		typedef ext::list<bob_error*>::iterator ErrorIterator;
67
		
66
 
68
		ErrorList errors;
67
		ErrorList errors;
69
		
68
 
70
		virtual ~bob_with_errors()
69
		virtual ~bob_with_errors()
71
		{
70
		{
72
			for(ErrorIterator &it=errors.begin(); it!=errors.end(); it++){
71
			for(ErrorIterator &it=errors.begin(); it!=errors.end(); it++){
73
				delete *it;
72
				delete *it;
74
			}
73
			}
75
		}
74
		}
76
};
75
};
77
 
76
 
78
class bob_dom_section : public bob_with_errors
77
class bob_section : public bob_with_errors
79
{
78
{
80
	public:
79
	public:
81
		static const int null_value=-1;
80
		static const int null_value = -1;
82
		
81
 
83
		int peek(bob_dom_ibinaryfilestream& is)
82
		int peek(ibinaryfilestream& is)
84
		{
83
		{
85
			int i;
84
			int i;
86
			is >> i;
85
			is >> i;
87
			is.advance(-(int)sizeof(int));
86
			is.advance(-(int)sizeof(int));
88
			return i;
87
			return i;
89
		}
88
		}
90
};
89
};
91
 
90
 
92
template <class Ty>
91
template <class Ty>
93
class bob_dom_cantainer
92
class bob_cantainer
94
{
93
{
95
	private:
94
	private:
96
		typedef ext::list<Ty*> list_type;
95
		typedef ext::list<Ty*> list_type;
97
	
96
 
98
	public:
97
	public:
99
		typedef Ty value_type;
98
		typedef Ty value_type;
100
		typedef Ty* value_type_ptr;
99
		typedef Ty* value_type_ptr;
101
		typedef value_type child_type;
100
		typedef value_type child_type;
102
		typedef typename list_type::size_type size_type;
101
		typedef typename list_type::size_type size_type;
103
		typedef typename list_type::iterator iterator;
102
		typedef typename list_type::iterator iterator;
104
		typedef typename list_type::const_iterator const_iterator;
103
		typedef typename list_type::const_iterator const_iterator;
105
		
104
 
106
	protected:
105
	protected:
107
		list_type children;
106
		list_type children;
108
	
107
 
109
	public:
108
	public:
110
		const_iterator begin() const { return children.begin(); }
109
		const_iterator begin() const { return children.begin(); }
111
		iterator begin() { return children.begin(); }
110
		iterator begin() { return children.begin(); }
112
		const_iterator end() const { return children.end(); }
111
		const_iterator end() const { return children.end(); }
113
		iterator end() { return children.end(); }
112
		iterator end() { return children.end(); }
114
		
113
 
115
		virtual ~bob_dom_cantainer()
114
		virtual ~bob_cantainer()
116
		{
115
		{
117
			removeChildren();
116
			removeChildren();
118
		}
117
		}
119
		
118
 
120
		void removeChildren()
119
		void removeChildren()
121
		{
120
		{
122
			for(iterator &it=children.begin(); it!=children.end(); ++it){
121
			for(iterator &it=children.begin(); it!=children.end(); ++it){
123
				delete *it;
122
				delete *it;
124
			}
123
			}
125
			children.clear();
124
			children.clear();
126
		}
125
		}
127
		
126
 
128
		size_type size() const { return children.size(); }
127
		size_type size() const { return children.size(); }
129
		
128
 
130
		value_type_ptr createChild() { return *(children.push_back(new value_type())); }
129
		value_type_ptr createChild() { return *(children.push_back(new value_type())); }
131
		
130
 
132
		value_type_ptr front() { return children.front(); }
131
		value_type_ptr front() { return children.front(); }
133
		value_type_ptr back() { return children.back(); }
132
		value_type_ptr back() { return children.back(); }
134
		
133
 
135
		void removeChild(iterator &where) 
134
		void removeChild(iterator &where)
136
		{
135
		{
137
			delete *where;
136
			delete *where;
138
			children.erase(where);
137
			children.erase(where);
139
		}
138
		}
140
		
139
 
141
		void removeChild(value_type_ptr child) 
140
		void removeChild(value_type_ptr child)
142
		{
141
		{
143
			iterator it, old;
142
			iterator it, old;
144
			while((it=children.find(child))!=children.end()){
143
			while((it=children.find(child))!=children.end()){
145
				old=it - 1;
144
				old=it - 1;
146
				delete *it;
145
				delete *it;
Line 148... Line 147...
148
				it=old;
147
				it=old;
149
			}
148
			}
150
		}
149
		}
151
};
150
};
152
 
151
 
153
class bob_dom_string : public bob_dom_section
152
class bob_string : public bob_section
154
{
153
{
155
	public:
154
	public:
156
		char *m_text;
155
		char *m_text;
157
		
156
 
158
		const char *text() const { return m_text; }
157
		const char *text() const { return m_text; }
159
		void text(const char *str) { text(str, strlen(str));	}
158
		void text(const char *str) { text(str, strlen(str));	}
160
		void text(const char *str, size_t size) 
159
		void text(const char *str, size_t size)
161
		{
160
		{
162
			delete[] m_text;
161
			delete[] m_text;
163
			m_text=new char[size + 1];
162
			m_text=new char[size + 1];
164
			memcpy(m_text, str, size);
163
			memcpy(m_text, str, size);
165
			m_text[size]=0;
164
			m_text[size]=0;
166
		}
165
		}
167
		
166
 
168
		bob_dom_string() { m_text=0; }
167
		bob_string() { m_text=0; }
169
		virtual ~bob_dom_string() { delete[] m_text; }
168
		virtual ~bob_string() { delete[] m_text; }
170
		
169
 
171
		bool load(unsigned char *data, size_t size, int startHeader, int endHeader);
-
 
172
		bool load(bob_dom_ibinaryfilestream& is, int startHeader, int endHeader);
170
		bool load(ibinaryfilestream& is, int startHeader, int endHeader);
173
		bool toFile(bob_dom_obinaryfilestream& os, int begin, int end);
171
		bool toFile(obinaryfilestream& os, int begin, int end);
174
};
172
};
175
 
173
 
176
class bob_dom_info : public bob_dom_string
174
class bob_info : public bob_string
177
{
175
{
178
	public:
176
	public:
179
		static const int hdr_begin=BOB_SECTION_NAME_INFO_BEGIN;
177
		static const int HDR_BEGIN = BOB_SECTION_NAME_INFO_BEGIN;
180
		static const int hdr_end=BOB_SECTION_NAME_INFO_END;
178
		static const int HDR_END = BOB_SECTION_NAME_INFO_END;
181
		
179
 
182
		bool load(unsigned char *data, size_t size) { return bob_dom_string::load(data, size, hdr_begin, hdr_end); }
-
 
183
		bool load(bob_dom_ibinaryfilestream& is) { return bob_dom_string::load(is, hdr_begin, hdr_end); }
180
		bool load(ibinaryfilestream& is) { return bob_string::load(is, HDR_BEGIN, HDR_END); }
184
		bool toFile(bob_dom_obinaryfilestream& os) { return bob_dom_string::toFile(os, hdr_begin, hdr_end); }
181
		bool toFile(obinaryfilestream& os) { return bob_string::toFile(os, HDR_BEGIN, HDR_END); }
185
		bool toFile(bob_dom_otextfilestream& os);
182
		bool toFile(otextfilestream& os);
186
};
183
};
187
 
184
 
188
#endif // !defined(BOB_DOM_BASE_INCLUDED)
185
#endif // !defined(BOB_DOM_BASE_INCLUDED)