Subversion Repositories spk

Rev

Rev 1 | Details | Compare with Previous | Last modification | View Log | RSS feed

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