Subversion Repositories spk

Rev

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

Rev 1 Rev 114
Line 1... Line 1...
1
#include "bob_dom_cut.h"
1
#include "bob_dom_cut.h"
2
#include "../common/indian.h"
2
#include "../common/indian.h"
3
 
-
 
4
static int g_i;
-
 
5
#define BOB_WRITE(fd, i) (g_i=be2le((unsigned int)i), write(fd, &g_i, sizeof(i)))
-
 
6
 
3
 
7
#define max(a, b) (a > b ? a : b)
4
#define max(a, b) (a > b ? a : b)
8
//---------------------------------------------------------------------------------
5
//---------------------------------------------------------------------------------
9
bool bob_dom_name::toFile(bob_dom_otextfilestream& os)
6
bool bob_name::toFile(otextfilestream& os)
10
{
7
{
11
	if(m_text && *m_text!=0) {
8
	if(m_text && *m_text!=0) {
12
		int oldf=os.flags();
9
		int oldf=os.flags();
13
		os << noSemicolons << "N " << autoSemicolons << m_text;
10
		os << noSemicolons << "N " << autoSemicolons << m_text;
14
		os.flags(oldf);
11
		os.flags(oldf);
15
	}
12
	}
16
	return os.good();
13
	return os.good();
17
}
14
}
18
//---------------------------------------------------------------------------------
15
//---------------------------------------------------------------------------------
19
// STAT
-
 
20
#ifdef X2BC_USE_INI_FORMATS
-
 
21
bool bob_dom_stat::load(bob_dom_ibinaryfilestream& is, const Settings *settings)
-
 
22
{
-
 
23
	is >> frameId;
-
 
24
	m_format=settings->findStatFormat(frameId);
-
 
25
	if(m_format==NULL){
-
 
26
		error(s_error, e_format_noStatFormat, "Cannot find STAT format 0x%X", frameId);
-
 
27
		setstate(bob_dom_stat::noFormat);
-
 
28
	}
-
 
29
	else{
-
 
30
		int v;
-
 
31
		for(Settings::StatFormat::const_iterator &it=m_format->tokens.begin(); it!=m_format->tokens.end(); ++it){
-
 
32
			for(int i=0; i < it->count; i++){
-
 
33
				is >> v;
-
 
34
				push_back(v);
-
 
35
			}
-
 
36
			if(is.fail()){
-
 
37
				error(s_error, e_format_notEnoughData, "Not enough data to match format 0x%X", frameId);
-
 
38
				setstate(cannotMatchFormat);
-
 
39
				break;
-
 
40
			}
-
 
41
		}
-
 
42
	}
-
 
43
	return rdstate()==formatted;
-
 
44
}
-
 
45
//---------------------------------------------------------------------------------
-
 
46
bool bob_dom_stat::toFile(bob_dom_obinaryfilestream& os)
-
 
47
{
-
 
48
	os << frameId;
-
 
49
	for(iterator &it=begin(); it!=end(); ++it){
-
 
50
		os << *it;
-
 
51
	}
-
 
52
	return os.good();
-
 
53
}
-
 
54
//---------------------------------------------------------------------------------
-
 
55
bool bob_dom_stat::toFile(bob_dom_otextfilestream& os, const Settings *settings)
-
 
56
{
-
 
57
	os << noSemicolons;
-
 
58
	if(rdstate()!=formatted && settings->outputWarnings()){
-
 
59
		os << "// Error: STAT frame id=" << hex << "0x" << frameId << dec;
-
 
60
		if(rdstate()==noFormat)	
-
 
61
			os << ": cannot find frame format";
-
 
62
		else
-
 
63
			os << ": unable to match frame format";
-
 
64
	}
-
 
65
	else{
-
 
66
		if(settings->statFormatWarnings() && settings->outputWarnings() && m_format->issueWarning)
-
 
67
			os << "// Warning: Format 0x" << hex << m_format->id << " was used and it's marked with warning sign" << endl;
-
 
68
	
-
 
69
		double val;
-
 
70
		os << "{ ";
-
 
71
		
-
 
72
		os << hex << "0x" << frameId << "; " << dec;
-
 
73
		
-
 
74
		iterator &valit=begin();
-
 
75
		
-
 
76
		for(Settings::StatFormat::const_iterator &it=m_format->tokens.begin(); it!=m_format->tokens.end(); ++it){
-
 
77
			for(int i=0; i < it->count; i++){
-
 
78
				val=*valit;
-
 
79
				if(settings->convert())
-
 
80
					val*=it->numFormat->multiplier;
-
 
81
				if(settings->convert() && it->numFormat->outformat==Settings::NumberFormat::Float)
-
 
82
					os << (float)val;
-
 
83
				else
-
 
84
					os << (int)val;
-
 
85
				
-
 
86
				os << ';';
-
 
87
					
-
 
88
				++valit;
-
 
89
			}
-
 
90
			if(it->data)
-
 
91
				os << it->data;
-
 
92
		}
-
 
93
		
-
 
94
		os << noSemicolons << " }";
-
 
95
	}
-
 
96
	return os.good();
-
 
97
}
-
 
98
//---------------------------------------------------------------------------------
-
 
99
#endif // defined(X2BC_USE_INI_FORMATS)
-
 
100
 
-
 
101
// PATH
16
// PATH
102
bool bob_dom_path::load(bob_dom_ibinaryfilestream& is, int version)
17
bool bob_path::load(ibinaryfilestream& is, int version)
103
{
18
{
104
	int hdr;
19
	int hdr;
105
	is >> hdr;
20
	is >> hdr;
106
	if(hdr!=hdr_begin){
21
	if(hdr!=HDR_BEGIN){
107
		error(e_badHeader);
22
		error(e_badHeader);
108
		return false;
23
		return false;
109
	}
24
	}
110
	is >> partIdx;
25
	is >> partIdx;
111
	if(version < 6) {
26
	if(version < 6) {
112
		int bid;
27
		int bid;
113
		is >> bid;
28
		is >> bid;
114
		m_bodyId=new char[20];
29
		m_bodyId=new char[20];
115
		_itoa(bid, m_bodyId, 10);
30
		_itoa(bid, m_bodyId, 10);
116
	}
31
	}
117
	else 
32
	else
118
		is >> m_bodyId;
33
		is >> m_bodyId;
119
		
34
 
120
	is >> cockpitIdx >> parentIdx >> bodyFlags;
35
	is >> cockpitIdx >> parentIdx >> bodyFlags;
121
	
36
 
122
	if(peek(is)==bob_dom_name::hdr_begin){
37
	if(peek(is)==bob_name::HDR_BEGIN){
123
		if(name.load(is)==false){
38
		if(name.load(is)==false){
124
			for(ErrorIterator &it=name.errors.begin(); it!=name.errors.end(); ++it){
39
			for(ErrorIterator &it=name.errors.begin(); it!=name.errors.end(); ++it){
125
				error(it->code, "name: %s", it->text);
40
				error(it->code, "name: %s", it->text);
126
			}
41
			}
127
			return false;
42
			return false;
128
		}
43
		}
129
	}
44
	}
130
 
45
 
131
	if(peek(is)==bob_dom_constants::hdr_begin){
46
	if(peek(is)==bob_constants::HDR_BEGIN){
132
		if(constants.load(is)==false){
47
		if(constants.load(is)==false){
133
			for(ErrorIterator &it=name.errors.begin(); it!=name.errors.end(); ++it){
48
			for(ErrorIterator &it=name.errors.begin(); it!=name.errors.end(); ++it){
134
				error(it->code, "constants: %s", it->text);
49
				error(it->code, "constants: %s", it->text);
135
			}
50
			}
136
			return false;
51
			return false;
137
		}
52
		}
138
	}
53
	}
139
	
54
 
140
	if(peek(is)==bob_dom_bob::hdr_begin){
55
	if(peek(is)==bob_dom_bob::HDR_BEGIN){
141
		bob=new bob_dom_bob(m_settings);
56
		bob=new bob_dom_bob(m_settings);
142
		if(bob->load(is)==false){
57
		if(bob->load(is)==false){
143
			for(ErrorIterator &it=bob->errors.begin(); it!=bob->errors.end(); ++it){
58
			for(ErrorIterator &it=bob->errors.begin(); it!=bob->errors.end(); ++it){
144
				error(it->code, "bob->%s", it->text);
59
				error(it->code, "bob->%s", it->text);
145
			}
60
			}
146
			return false;
61
			return false;
147
		}
62
		}
148
	}
63
	}
149
	int noteLineCount;
64
	int noteLineCount;
150
	is >> noteLineCount;
65
	is >> noteLineCount;
Line 154... Line 69...
154
				error(it->code, "notes->%s", it->text);
69
				error(it->code, "notes->%s", it->text);
155
			}
70
			}
156
			return false;
71
			return false;
157
		}
72
		}
158
	}
73
	}
159
	
74
 
160
	int statCount;
75
	int statCount;
161
	is >> statCount;
76
	is >> statCount;
162
	if(loadStatValues(is, statCount)==false) return false;
77
	if(loadStatValues(is, statCount)==false) return false;
163
	
78
 
164
	is >> hdr;
79
	is >> hdr;
165
	if(is.fail())
80
	if(is.fail())
166
		error(e_notEnoughData);
81
		error(e_notEnoughData);
167
	else if(hdr!=hdr_end)
82
	else if(hdr!=HDR_END)
168
		error(e_badEndHeader);
83
		error(e_badEndHeader);
169
	
84
 
170
	/////////////////
85
	/////////////////
171
	//if(hdr==hdr_end) formatStats();
86
	//if(hdr==HDR_END) formatStats();
172
	////////////////
87
	////////////////
173
	return hdr==hdr_end && !is.fail();
88
	return hdr==HDR_END && !is.fail();
174
}
89
}
175
//---------------------------------------------------------------------------------
90
//---------------------------------------------------------------------------------
176
bool bob_dom_path::loadStatValues(bob_dom_ibinaryfilestream& is, int count)
91
bool bob_path::loadStatValues(ibinaryfilestream& is, int count)
177
{
92
{
178
	int hdr;
93
	int hdr;
179
	is >> hdr;
94
	is >> hdr;
180
	if(hdr!=hdr_stat_begin){
95
	if(hdr!=HDR_STAT_BEGIN){
181
		error(e_badHeader, "Expected STAT header.");
96
		error(e_badHeader, "Expected STAT header.");
182
		return false;
97
		return false;
183
	}
98
	}
184
	
99
 
185
	child_type *ch;
100
	child_type *ch;
186
	bool bRes;
101
	bool bRes;
187
	
102
 
188
	for(int i=0; i < count; i++){
103
	for(int i=0; i < count; i++){
189
		ch=createChild();
104
		ch=createChild();
190
#ifdef X2BC_USE_INI_FORMATS
-
 
191
		bRes=ch->load(is, m_settings);
-
 
192
#else
-
 
193
		bRes=ch->load(is);
105
		bRes=ch->load(is);
194
#endif
106
 
195
		for(ErrorIterator &it=ch->errors.begin(); it!=ch->errors.end(); ++it){
107
		for(ErrorIterator &it=ch->errors.begin(); it!=ch->errors.end(); ++it){
196
			error(it->severity, it->code, "stat->frame[%d]: %s", i, it->text);
108
			error(it->severity, it->code, "stat->frame[%d]: %s", i, it->text);
197
		}
109
		}
198
		if(bRes==false) break;
110
		if(bRes==false) break;
199
	}
111
	}
200
	
112
 
201
	is >> hdr;
113
	is >> hdr;
202
	if(hdr!=hdr_stat_end){
114
	if(hdr!=HDR_STAT_END){
203
		error(s_error, e_moreData, "More data in STAT section than expected - skipping");
115
		error(s_error, e_moreData, "More data in STAT section than expected - skipping");
204
		do{
116
		do{
205
			is >> hdr;
117
			is >> hdr;
206
		}
118
		}
207
		while(hdr!=hdr_stat_end && is.good());
119
		while(hdr!=HDR_STAT_END && is.good());
208
	}
120
	}
209
	
121
 
210
	if(hdr!=hdr_stat_end)
122
	if(hdr!=HDR_STAT_END)
211
		error(e_notEnoughData);
123
		error(e_notEnoughData);
212
	return hdr==hdr_stat_end;
124
	return hdr==HDR_STAT_END;
213
}
125
}
214
//---------------------------------------------------------------------------------
126
//---------------------------------------------------------------------------------
215
bool bob_dom_path::toFile(bob_dom_obinaryfilestream& os, int cutVersion)
127
bool bob_path::toFile(obinaryfilestream& os, int cutVersion)
216
{
128
{
217
	os << hdr_begin;
129
	os << HDR_BEGIN;
218
	os << partIdx;
130
	os << partIdx;
219
	if(cutVersion >= 6)
131
	if(cutVersion >= 6)
220
		os << bodyId();
132
		os << bodyId();
221
	else
133
	else
222
		os << atoi(bodyId());
134
		os << atoi(bodyId());
223
	
135
 
224
	os << cockpitIdx;
136
	os << cockpitIdx;
225
	os << parentIdx;
137
	os << parentIdx;
226
	os << bodyFlags;
138
	os << bodyFlags;
227
	os << name;
139
	os << name;
228
	constants.toFile(os);
140
	constants.toFile(os);
229
	if(bob) bob->toFile(os);
141
	if(bob) bob->toFile(os);
230
	os << (int)m_notes.size();
142
	os << (int)m_notes.size();
231
	m_notes.toFile(os);
143
	m_notes.toFile(os);
232
	os << (int)size();
144
	os << (int)size();
233
	
145
 
234
	os << hdr_stat_begin;
146
	os << HDR_STAT_BEGIN;
235
	for(iterator &it=begin(); it!=end(); ++it){
147
	for(iterator &it=begin(); it!=end(); ++it){
236
		it->toFile(os);
148
		it->toFile(os);
237
	}
149
	}
238
	os << hdr_stat_end << hdr_end;
150
	os << HDR_STAT_END << HDR_END;
239
	return true;
151
	return true;
240
}
152
}
241
//---------------------------------------------------------------------------------
153
//---------------------------------------------------------------------------------
242
bool bob_dom_path::toFile(bob_dom_otextfilestream& os, int idx)
154
bool bob_path::toFile(otextfilestream& os, int idx)
243
{
155
{
244
	os << noSemicolons << "P " << partIdx << "; B " << bodyId() << "; ";
156
	os << noSemicolons << "P " << partIdx << "; B " << bodyId() << "; ";
245
	if(parentIdx!=-1)
157
	if(parentIdx!=-1)
246
		os << "F " << parentIdx << "; ";
158
		os << "F " << parentIdx << "; ";
247
	
159
 
248
	if(cockpitIdx > 0)
160
	if(cockpitIdx > 0)
249
		os << "C " << cockpitIdx << "; ";
161
		os << "C " << cockpitIdx << "; ";
250
		
162
 
251
	os << name;
163
	os << name;
252
	
164
 
253
	constants.toFile(os);
165
	constants.toFile(os);
254
 
166
 
255
	/*
167
	/*
256
		we've got old x2 flags and new x3 flags
168
		we've got old x2 flags and new x3 flags
257
		these 2 can be mixed together
169
		these 2 can be mixed together
258
		
170
 
259
		for example body || light
171
		for example body || light
260
		
172
 
261
		only the body (64) and scene (128) can be mixed with anything else imho
173
		only the body (64) and scene (128) can be mixed with anything else imho
262
	*/
174
	*/
263
	if(bodyFlags!=0) {
175
	if(bodyFlags!=0) {
264
		if(bodyFlags & BodyFlags::fBody)
176
		if(bodyFlags & fBody)
265
			os << "b ";
177
			os << "b ";
266
		if(bodyFlags & BodyFlags::fScene)
178
		if(bodyFlags & fScene)
267
			os << "j ";
179
			os << "j ";
268
		int i=bodyFlags & 0x3F;
180
		int i=bodyFlags & 0x3F;
269
		if(i) 
181
		if(i)
270
			os << (char) ('b' + i) << ' ';
182
			os << (char) ('b' + i) << ' ';
271
	}
183
	}
272
	
184
 
273
	os << "// idx " << idx << ", flags: " << bodyFlags << endl;
185
	os << "// idx " << idx << ", flags: " << bodyFlags << endl;
274
	
186
 
275
	if(m_notes.size())
187
	if(m_notes.size())
276
		m_notes.toFile(os);
188
		m_notes.toFile(os);
277
	
189
 
278
	if(bob){
190
	if(bob){
279
		os << noSemicolons << "L { // beginning of embedded BOB" << endl;
191
		os << noSemicolons << "L { // beginning of embedded BOB" << endl;
280
		os << *bob << "} // end of embedded BOB" << endl << endl;
192
		os << *bob << "} // end of embedded BOB" << endl << endl;
281
	}
193
	}
282
	
194
 
283
	int i=0;
195
	int i=0;
284
	for(iterator &it=begin(); it!=end(); ++it, ++i){
196
	for(iterator &it=begin(); it!=end(); ++it, ++i){
285
#ifdef X2BC_USE_INI_FORMATS
-
 
286
		it->toFile(os, m_settings);
-
 
287
#else
-
 
288
		it->toFile(os);
197
		it->toFile(os);
289
#endif
198
 
290
		os << " // " << i << endl;
199
		os << " // " << i << endl;
291
	}
200
	}
292
	os << endl;
201
	os << endl;
293
	
202
 
294
	return os.good();
203
	return os.good();
295
}
204
}
296
//---------------------------------------------------------------------------------
205
//---------------------------------------------------------------------------------
297
// CUT file
206
// CUT file
298
bool bob_dom_cut::load(bob_dom_ibinaryfilestream& is)
207
bool bob_dom_cut::load(ibinaryfilestream& is)
299
{
208
{
300
	int hdr;
209
	int hdr;
301
	is >> hdr;
210
	is >> hdr;
302
	if(hdr!=hdr_begin){
211
	if(hdr!=HDR_BEGIN){
303
		error(e_badHeader);
212
		error(e_badHeader);
304
		return false;
213
		return false;
305
	}
214
	}
306
	
215
 
307
	if(peek(is)==bob_dom_info::hdr_begin){
216
	if(peek(is)==bob_info::HDR_BEGIN){
308
		if(!info.load(is)){
217
		if(!info.load(is)){
309
			for(ErrorIterator &it=info.errors.begin(); it!=info.errors.end(); ++it){
218
			for(ErrorIterator &it=info.errors.begin(); it!=info.errors.end(); ++it){
310
				error(it->code, "info: %s", it->text);
219
				error(it->code, "info: %s", it->text);
311
			}
220
			}
312
			return false;
221
			return false;
313
		}
222
		}
314
	}
223
	}
315
	
224
 
316
	is >> version;
225
	is >> version;
317
	
226
 
318
	if(version!=supported_version)
227
	if(version!=supported_version)
319
		error(s_warning, e_badVersion, "Unsupported CUT1 version, loading might fail");
228
		error(s_warning, e_badVersion, "Unsupported CUT1 version, loading might fail");
320
	
229
 
321
	is >> m_storedPathCount;
230
	is >> m_storedPathCount;
322
	
231
 
323
	child_type *ch;
232
	child_type *ch;
324
	for(int i=0; i < m_storedPathCount; i++){
233
	for(int i=0; i < m_storedPathCount; i++){
325
		ch=createChild();
234
		ch=createChild();
326
		bool bRes=ch->load(is, version);
235
		bool bRes=ch->load(is, version);
327
		for(ErrorIterator &it=ch->errors.begin(); it!=ch->errors.end(); ++it){
236
		for(ErrorIterator &it=ch->errors.begin(); it!=ch->errors.end(); ++it){
328
			error(it->code, "path[%d]->%s", i, it->text);
237
			error(it->code, "path[%d]->%s", i, it->text);
329
		}
238
		}
330
		if(bRes==false) return false;
239
		if(bRes==false) return false;
331
	}
240
	}
332
	
241
 
333
	is >> hdr;
242
	is >> hdr;
334
	if(hdr!=hdr_end)
243
	if(hdr!=HDR_END)
335
		error(e_badEndHeader);
244
		error(e_badEndHeader);
336
	return hdr==hdr_end;
245
	return hdr==HDR_END;
337
}
246
}
338
//---------------------------------------------------------------------------------
247
//---------------------------------------------------------------------------------
339
bool bob_dom_cut::convert(bob_dom_ibinaryfilestream& is, bob_dom_otextfilestream& os)
248
bool bob_dom_cut::convert(ibinaryfilestream& is, otextfilestream& os)
340
{
249
{
341
	int hdr;
250
	int hdr;
342
	is >> hdr;
251
	is >> hdr;
343
	if(hdr!=hdr_begin){
252
	if(hdr!=HDR_BEGIN){
344
		error(e_badHeader);
253
		error(e_badHeader);
345
		return false;
254
		return false;
346
	}
255
	}
347
	
256
 
348
	if(peek(is)==bob_dom_info::hdr_begin){
257
	if(peek(is)==bob_info::HDR_BEGIN){
349
		if(!info.load(is)){
258
		if(!info.load(is)){
350
			for(ErrorIterator &it=info.errors.begin(); it!=info.errors.end(); ++it){
259
			for(ErrorIterator &it=info.errors.begin(); it!=info.errors.end(); ++it){
351
				error(it->code, "info: %s", it->text);
260
				error(it->code, "info: %s", it->text);
352
			}
261
			}
353
			return false;
262
			return false;
354
		}
263
		}
355
	}
264
	}
356
	
265
 
357
	is >> version;
266
	is >> version;
358
	
267
 
359
	os << info << endl << "VER: " << autoSemicolons << version << endl << endl;
268
	os << info << endl << "VER: " << autoSemicolons << version << endl << endl;
360
	
269
 
361
	is >> m_storedPathCount;
270
	is >> m_storedPathCount;
362
	
271
 
363
	child_type *ch;
272
	child_type *ch;
364
	for(int i=0; i < m_storedPathCount; i++){
273
	for(int i=0; i < m_storedPathCount; i++){
365
		ch=new bob_dom_path(m_settings);
274
		ch=new bob_path(m_settings);
366
		bool bRes=ch->load(is, version);
275
		bool bRes=ch->load(is, version);
367
			
276
 
368
		for(ErrorIterator &it=ch->errors.begin(); it!=ch->errors.end(); ++it){
277
		for(ErrorIterator &it=ch->errors.begin(); it!=ch->errors.end(); ++it){
369
			error(it->code, "path[%d]->%s", i, it->text);
278
			error(it->code, "path[%d]->%s", i, it->text);
370
		}
279
		}
371
		
280
 
372
		if(bRes)
281
		if(bRes)
373
			ch->toFile(os, i);
282
			ch->toFile(os, i);
374
			
283
 
375
		delete ch;
284
		delete ch;
376
		if(bRes==false) return false;
285
		if(bRes==false) return false;
377
	}
286
	}
378
	
287
 
379
	is >> hdr;
288
	is >> hdr;
380
	if(hdr!=hdr_end)
289
	if(hdr!=HDR_END)
381
		error(e_badEndHeader);
290
		error(e_badEndHeader);
382
	return hdr==hdr_end;
291
	return hdr==HDR_END;
383
}
292
}
384
//---------------------------------------------------------------------------------
293
//---------------------------------------------------------------------------------
385
bool bob_dom_cut::toFile(bob_dom_obinaryfilestream& os)
294
bool bob_dom_cut::toFile(obinaryfilestream& os)
386
{
295
{
387
	os << hdr_begin << info << version << (int)size();
296
	os << HDR_BEGIN << info << version << (int)size();
388
 
297
 
389
	for(iterator &it=begin(); it!=end(); ++it){
298
	for(iterator &it=begin(); it!=end(); ++it){
390
		it->toFile(os, version);
299
		it->toFile(os, version);
391
	}
300
	}
392
	os << hdr_end;
301
	os << HDR_END;
393
	
302
 
394
	return os.good();
303
	return os.good();
395
}
304
}
396
//---------------------------------------------------------------------------------
305
//---------------------------------------------------------------------------------
397
bool bob_dom_cut::toFile(bob_dom_otextfilestream& os)
306
bool bob_dom_cut::toFile(otextfilestream& os)
398
{
307
{
399
	os << noSemicolons << info << endl;
308
	os << noSemicolons << info << endl;
400
	os << "VER: " << autoSemicolons << version << endl << endl;
309
	os << "VER: " << autoSemicolons << version << endl << endl;
401
	
310
 
402
	int idx=0;
311
	int idx=0;
403
	for(iterator &it=begin(); it!=end(); ++it){
312
	for(iterator &it=begin(); it!=end(); ++it){
404
		it->toFile(os, idx++);
313
		it->toFile(os, idx++);
405
		os << endl;
314
		os << endl;
406
	}
315
	}
407
	
316
 
408
	return os.good();
317
	return os.good();
409
}
318
}
410
//---------------------------------------------------------------------------------
319
//---------------------------------------------------------------------------------
411
// NOTES - section NOTE
320
// NOTES - section NOTE
412
bool bob_dom_notes::load(bob_dom_ibinaryfilestream& is, int lineCount)
321
bool bob_notes::load(ibinaryfilestream& is, int lineCount)
413
{
322
{
414
	int hdr;
323
	int hdr;
415
	
324
 
416
	is >> hdr;
325
	is >> hdr;
417
	if(hdr!=hdr_begin){
326
	if(hdr!=HDR_BEGIN){
418
		error(e_badHeader);
327
		error(e_badHeader);
419
		return false;
328
		return false;
420
	}
329
	}
421
	child_type *ch;
330
	child_type *ch;
422
	for(int i=0; i < lineCount; i++){
331
	for(int i=0; i < lineCount; i++){
Line 425... Line 334...
425
			error(ch->errorCode, "line[%d]: %s", i, bob_traslate_error(ch->errorCode));
334
			error(ch->errorCode, "line[%d]: %s", i, bob_traslate_error(ch->errorCode));
426
			return false;
335
			return false;
427
		}
336
		}
428
	}
337
	}
429
	is >> hdr;
338
	is >> hdr;
430
	if(hdr!=hdr_end)
339
	if(hdr!=HDR_END)
431
		error(e_badEndHeader);
340
		error(e_badEndHeader);
432
		
341
 
433
	return hdr==hdr_end && !is.fail();
342
	return hdr==HDR_END && !is.fail();
434
}
343
}
435
//---------------------------------------------------------------------------------
344
//---------------------------------------------------------------------------------
436
bool bob_dom_notes::toFile(bob_dom_obinaryfilestream& os)
345
bool bob_notes::toFile(obinaryfilestream& os)
437
{
346
{
438
	if(size()==0) return true;
347
	if(size()==0) return true;
439
	
348
 
440
	os << hdr_begin;
349
	os << HDR_BEGIN;
441
	for(iterator &it=begin(); it!=end(); ++it){
350
	for(iterator &it=begin(); it!=end(); ++it){
442
		it->toFile(os);
351
		it->toFile(os);
443
	}
352
	}
444
	os << hdr_end;
353
	os << HDR_END;
445
	return os.good();
354
	return os.good();
446
}
355
}
447
//---------------------------------------------------------------------------------
356
//---------------------------------------------------------------------------------
448
bool bob_dom_notes::toFile(bob_dom_otextfilestream& os)
357
bool bob_notes::toFile(otextfilestream& os)
449
{
358
{
450
 os << noSemicolons << "T // Notes" << endl;
359
 os << noSemicolons << "T // Notes" << endl;
451
	for(iterator &it=begin(); it!=end(); ++it){
360
	for(iterator &it=begin(); it!=end(); ++it){
452
		it->toFile(os);
361
		it->toFile(os);
453
		os << endl;
362
		os << endl;
Line 455... Line 364...
455
	os << -1 << " // end of Notes" << endl;
364
	os << -1 << " // end of Notes" << endl;
456
	return os.good();
365
	return os.good();
457
}
366
}
458
//---------------------------------------------------------------------------------
367
//---------------------------------------------------------------------------------
459
// NOTE - object
368
// NOTE - object
460
bool bob_note::load(bob_dom_ibinaryfilestream& is)
369
bool bob_note::load(ibinaryfilestream& is)
461
{
370
{
462
	is >> value;
371
	is >> value;
463
	is >> text;
372
	is >> text;
464
	if(is.fail())
373
	if(is.fail())
465
		errorCode=e_notEnoughData;
374
		errorCode=e_notEnoughData;
466
	return !is.fail();
375
	return !is.fail();
467
}
376
}
468
//---------------------------------------------------------------------------------
377
//---------------------------------------------------------------------------------
469
bool bob_note::toFile(bob_dom_obinaryfilestream& os)
378
bool bob_note::toFile(obinaryfilestream& os)
470
{
379
{
471
	os << value << text;
380
	os << value << text;
472
	return os.good();
381
	return os.good();
473
}
382
}
474
//---------------------------------------------------------------------------------
383
//---------------------------------------------------------------------------------
475
bool bob_note::toFile(bob_dom_otextfilestream& os)
384
bool bob_note::toFile(otextfilestream& os)
476
{
385
{
477
	os << autoSemicolons << value << text;
386
	os << autoSemicolons << value << text;
478
	return os.good();
387
	return os.good();
479
}
388
}
480
//---------------------------------------------------------------------------------
389
//---------------------------------------------------------------------------------
481
bool bob_dom_constants::load(bob_dom_ibinaryfilestream& is)
390
bool bob_constants::load(ibinaryfilestream& is)
482
{
391
{
483
	int hdr, count;
392
	int hdr, count;
484
	is >> hdr;
393
	is >> hdr;
485
	if(hdr!=hdr_begin){
394
	if(hdr!=HDR_BEGIN){
486
		error(e_badHeader);
395
		error(e_badHeader);
487
		return false;
396
		return false;
488
	}
397
	}
489
	
398
 
490
	is >> count;
399
	is >> count;
491
	
400
 
492
	constant c;
401
	constant c;
493
	for(int i=0; i < count; i++){
402
	for(int i=0; i < count; i++){
494
		c.load(is);
403
		c.load(is);
495
		values.push_back(c);
404
		values.push_back(c);
496
	}
405
	}
497
	is >> hdr;
406
	is >> hdr;
498
	if(hdr!=hdr_end){
407
	if(hdr!=HDR_END){
499
		error(e_badEndHeader);
408
		error(e_badEndHeader);
500
		return false;
409
		return false;
501
	}
410
	}
502
	return is.good();
411
	return is.good();
503
}
412
}
504
//---------------------------------------------------------------------------------
413
//---------------------------------------------------------------------------------
505
bool bob_dom_constants::toFile(bob_dom_obinaryfilestream& os)
414
bool bob_constants::toFile(obinaryfilestream& os)
506
{
415
{
507
	if(values.size()==0) return true;
416
	if(values.size()==0) return true;
508
	
417
 
509
	os << hdr_begin << (int)values.size();
418
	os << HDR_BEGIN << (int)values.size();
510
	
419
 
511
	for(iterator &it=values.begin(); it!=values.end(); ++it){
420
	for(iterator &it=values.begin(); it!=values.end(); ++it){
512
		(*it).toFile(os);
421
		(*it).toFile(os);
513
	}
422
	}
514
	os << hdr_end;
423
	os << HDR_END;
515
	return os.good();
424
	return os.good();
516
}
425
}
517
//---------------------------------------------------------------------------------
426
//---------------------------------------------------------------------------------
518
bool bob_dom_constants::toFile(bob_dom_otextfilestream& os)
427
bool bob_constants::toFile(otextfilestream& os)
519
{
428
{
520
	if(values.size()==0) return true;
429
	if(values.size()==0) return true;
521
	
430
 
522
	os << noSemicolons << "K " << autoSemicolons << (int)values.size();
431
	os << noSemicolons << "K " << autoSemicolons << (int)values.size();
523
	for(iterator &it=values.begin(); it!=values.end(); ++it){
432
	for(iterator &it=values.begin(); it!=values.end(); ++it){
524
		(*it).toFile(os);
433
		(*it).toFile(os);
525
	}
434
	}
526
	os << noSemicolons;
435
	os << noSemicolons;
527
	return os.good();
436
	return os.good();
528
}
437
}
529
//---------------------------------------------------------------------------------
438
//---------------------------------------------------------------------------------
530
bool bob_dom_constants::constant::load(bob_dom_ibinaryfilestream& is)
439
bool bob_constants::constant::load(ibinaryfilestream& is)
531
{
440
{
532
	is >> a >> b;
441
	is >> a >> b;
533
	return is.good();
442
	return is.good();
534
}
443
}
535
//---------------------------------------------------------------------------------
444
//---------------------------------------------------------------------------------
536
bool bob_dom_constants::constant::toFile(bob_dom_obinaryfilestream& os)
445
bool bob_constants::constant::toFile(obinaryfilestream& os)
537
{
446
{
538
	os << a << b;
447
	os << a << b;
539
	return os.good();
448
	return os.good();
540
}
449
}
541
//---------------------------------------------------------------------------------
450
//---------------------------------------------------------------------------------
542
bool bob_dom_constants::constant::toFile(bob_dom_otextfilestream& os)
451
bool bob_constants::constant::toFile(otextfilestream& os)
543
{
452
{
544
	os << a << b;
453
	os << a << b;
545
	return os.good();
454
	return os.good();
546
}
455
}
547
//---------------------------------------------------------------------------------
456
//---------------------------------------------------------------------------------