1 #ifndef JWTYPE_HEAD
2 #define JWTYPE_HEAD
3 #include <iomanip>
4 #include <iostream>
5 #include <fstream>
6 #include <string>
7 #include <algorithm>
8 #include <vector>
9 #include<list>
10 #include <iterator>
11 
12 #ifdef _WINDOWS
13 #include <windows.h>
14 typedef double jwDOUBLE;
15 typedef DWORD jwDWORD;
16 typedef WORD jwWORD;
17 typedef BYTE jwBYTE;
18 typedef BOOL jwBOOL;
19 #else
20 typedef double jwDOUBLE;
21 typedef unsigned int jwDWORD;
22 typedef unsigned short jwWORD;
23 typedef unsigned char jwBYTE;
24 typedef bool jwBOOL;
25 #endif
26 
27 typedef	long double	LDouble;
28 
29 using namespace std;
30 
31 #ifdef USE_INTEGER
32 /////////////////////////////////////////////////////////
33 class Integer
34 {
35  private:
36 	INT data;
37  public:
38 	Integer(const INT& ival=0)
39 	{
40 	data = ival;
41 	}
~Integer()42 	~Integer(){;}
Value()43 	INT Value(){return data;}
44 	INT operator=(Integer& val)
45 		{
46 			return val.data;
47 		}
48 	Integer& operator=(INT val)
49 		{
50 			data = val;
51 			return *this;
52 		}
53 //	Integer& operator=(Integer& val)
54 //		{
55 //			data = val.data;
56 //			return *this;
57 //		}
58 	friend inline ofstream& operator<<(ofstream&, const Integer&);
59 	friend inline ifstream& operator>>(ifstream&, Integer&);
60 	friend inline ostream& operator<<(ostream&, const Integer&);
61 	friend inline istream& operator>>(istream&, Integer&);
62 };
63 inline ofstream& operator<< (ofstream& ofstr, const Integer& output)
64 {
65 	ofstr.write((char*)&(output.data), sizeof(INT));
66 	return ofstr;
67 }
68 
69 inline ifstream& operator>> (ifstream& ifstr, Integer& input)
70 {
71 	ifstr.read((char*)&(input.data), sizeof(INT));
72 	return ifstr;
73 }
74 
75 inline ostream& operator<< (ostream& ostr, const Integer& output)
76 {
77 	return ostr << output.data;
78 }
79 
80 inline istream& operator>> (istream& istr, Integer& input)
81 {
82 	return istr >> input.data;
83 }
84 /////////////////////////////////////////////////////////
85 class DWord
86 {
87  private:
88 	jwDWORD data;
89  public:
90 	DWord(const jwDWORD& ulval=0)
91 	{
92 		data = ulval;
93 	}
~DWord()94 	~DWord(){;}
Value()95 	jwDWORD Value(){return data;}
96 	jwDWORD operator=(DWord& val)
97 		{
98 			return val.data;
99 		}
100 //	DWord& operator=(DWord& val)
101 //		{
102 //			data =  val.data;
103 //			return *this;
104 //		}
105 	DWord& operator=(jwDWORD val)
106 		{
107 			data = val;
108 			return *this;
109 		}
110 	friend inline ofstream& operator<<(ofstream&, const DWord&);
111 	friend inline ifstream& operator>>(ifstream&, DWord&);
112 	friend inline ostream& operator<<(ostream&, const DWord&);
113 	friend inline istream& operator>>(istream&, DWord&);
114 };
115 inline ofstream& operator<< (ofstream& ofstr, const DWord& output)
116 {
117 	ofstr.write((char*)&(output.data), sizeof(jwDWORD));
118 	return ofstr;
119 }
120 
121 inline ifstream& operator>> (ifstream& ifstr, DWord& input)
122 {
123 	ifstr.read((char*)&(input.data), sizeof(jwDWORD));
124 	return ifstr;
125 }
126 
127 inline ostream& operator<< (ostream& ostr, const DWord& output)
128 {
129 	return ostr << output.data;
130 }
131 
132 inline istream& operator>> (istream& istr, DWord& input)
133 {
134 	return istr >> input.data;
135 }
136 
137 /////////////////////////////////////////////////////////
138 class Word
139 {
140  private:
141 	jwWORD data;
142  public:
143 	Word(const jwWORD& uval=0)
144 	{
145 		data = uval;
146 	}
~Word()147 	~Word(){;}
Value()148 	jwWORD Value(){return data;}
149 	jwWORD operator=(Word& val)
150 		{
151 			return val.data;
152 		}
153 	Word& operator=(jwWORD val)
154 		{
155 			data = val;
156 			return *this;
157 		}
158 //	Word& operator=(Word& val)
159 //		{
160 //			data = val.data;
161 //			return *this;
162 //		}
163 	friend inline ofstream& operator<<(ofstream&, const Word&);
164 	friend inline ifstream& operator>>(ifstream&, Word&);
165 	friend inline ostream& operator<<(ostream&, const Word&);
166 	friend inline istream& operator>>(istream&, Word&);
167 };
168 inline ofstream& operator<< (ofstream& ofstr, const Word& output)
169 {
170 	ofstr.write((char*)&(output.data), sizeof(jwWORD));
171 	return ofstr;
172 }
173 
174 inline ifstream& operator>> (ifstream& ifstr, Word& input)
175 {
176 	ifstr.read((char*)&(input.data), sizeof(jwWORD));
177 	return ifstr;
178 }
179 
180 inline ostream& operator<< (ostream& ostr, const Word& output)
181 {
182 	return ostr << output.data;
183 }
184 
185 inline istream& operator>> (istream& istr, Word& input)
186 {
187 	return istr >> input.data;
188 }
189 
190 /////////////////////////////////////////////////////////
191 class Byte
192 {
193  private:
194 	jwBYTE data;
195  public:
196 	Byte(const jwBYTE& bval=0)
197 	{
198 		data = bval;
199 	}
~Byte()200 	~Byte(){;}
Value()201 	jwBYTE Value(){return data;}
202 	jwBYTE operator=(Byte& val)
203 		{
204 			return val.data;
205 		}
206 	Byte& operator=(jwBYTE val)
207 		{
208 			data = val;
209 			return *this;
210 		}
211 //	Byte& operator=(Byte& val)
212 //		{
213 //			data = val.data;
214 //			return *this;
215 //		}
216 	friend inline ofstream& operator<<(ofstream&, const Byte&);
217 	friend inline ifstream& operator>>(ifstream&, Byte&);
218 	friend inline ostream& operator<<(ostream&, const Byte&);
219 	friend inline istream& operator>>(istream&, Byte&);
220     friend inline bool operator==( char ch, Byte& c );
221     friend inline bool operator==( Byte& c, char ch );
222     friend inline bool operator==( Byte& c1, Byte& c2 );
223     friend inline bool operator!=( Byte& c1, Byte& c2 );
224     friend inline bool operator!=( char ch, Byte& c );
225     friend inline bool operator!=( Byte& c, char ch );
226     friend inline bool operator<=( Byte& c, char ch );
227     friend inline bool operator<=( char ch, Byte& c );
228     friend inline bool operator<=( Byte& c1, Byte& c2 );
229 
230 };
231 inline ofstream& operator<< (ofstream& ofstr, const Byte& output)
232 {
233 	ofstr.write((char*)&(output.data), sizeof(jwBYTE));
234 	return ofstr;
235 }
236 
237 inline ifstream& operator>> (ifstream& ifstr, Byte& input)
238 {
239 	ifstr.read((char*)&(input.data), sizeof(jwBYTE));
240 	return ifstr;
241 }
242 
243 inline ostream& operator<< (ostream& ostr, const Byte& output)
244 {
245 	return ostr << output.data;
246 }
247 
248 inline istream& operator>> (istream& istr, Byte& input)
249 {
250 	return istr >> input.data;
251 }
252 
253 inline bool operator==( char ch, Byte& c )
254 {
255     return ((jwBYTE) ch) == c.data;
256 }
257 
258 inline bool operator==( Byte& c, char ch )
259 {
260     return ((jwBYTE) ch) == c.data;
261 }
262 
263 inline bool operator==( Byte& c1, Byte& c2 )
264 {
265     return c1.data == c2.data;
266 }
267 
268 inline bool operator!=( Byte& c1, Byte& c2 )
269 {
270     return c1.data != c2.data;
271 }
272 
273 inline bool operator!=( char ch, Byte& c )
274 {
275     return ((jwBYTE)ch) != c.data;
276 }
277 
278 inline bool operator!=( Byte& c, char ch )
279 {
280     return ((jwBYTE) ch) != c.data;
281 }
282 
283 inline bool operator<=( Byte& c, char ch )
284 {
285     return c.data <= ((jwBYTE) ch);
286 }
287 
288 inline bool operator<=( char ch, Byte& c )
289 {
290     return ((jwBYTE) ch) <= c.data;
291 }
292 
293 inline bool operator<=( Byte& c1, Byte& c2 )
294 {
295     return c1.data <= c2.data;
296 }
297 
298 /////////////////////////////////////////////////////////
299 class Double
300 {
301  private:
302 	jwDOUBLE data;
303  public:
304 	Double(const jwDOUBLE& db=0.0)
305 		{
306 			data = db;
307 		}
Value()308 	jwDOUBLE Value(){return data;}
309 	Double& operator+(Double& val)
310 		{
311 			data += val.data;
312 			return *this;
313 		}
314 	Double& operator+(LDouble& val)
315 		{
316 			data += val;
317 			return *this;
318 		}
319 	Double& operator+=(Double& val)
320 		{
321 			data += val.data;
322 			return *this;
323 		}
324 	Double& operator=(Double& val)
325 		{
326 			data = val.data;
327 			return *this;
328 		}
329 	Double& operator=(jwDOUBLE& val)
330 		{
331 			data = val;
332 			return *this;
333 		}
334 
335 	friend inline ofstream& operator<<(ofstream&, const Double&);
336 	friend inline ifstream& operator>>(ifstream&, Double&);
337 	friend inline ostream& operator<<(ostream&, const Double&);
338 	friend inline istream& operator>>(istream&, Double&);
339 };
340 
341 inline ofstream& operator<< (ofstream& ofstr, const Double& output)
342 {
343 	ofstr.write((char*)&(output.data), sizeof(jwDOUBLE));
344 	return ofstr;
345 }
346 
347 inline ifstream& operator>> (ifstream& ifstr, Double& input)
348 {
349 	ifstr.read((char*)&(input.data), sizeof(jwDOUBLE));
350 	return ifstr;
351 }
352 
353 inline ostream& operator<< (ostream& ostr, const Double& output)
354 {
355 	return ostr << output.data;
356 }
357 
358 inline istream& operator>> (istream& istr, Double& input)
359 {
360 	return istr >> input.data;
361 }
362 #endif
363 
364 inline ofstream& operator<< (ofstream& ofstr, const jwDOUBLE& output)
365 {
366 	ofstr.write((char*)&output, sizeof(jwDOUBLE));
367     return ofstr;
368 }
369 
370 inline ifstream& operator>> (ifstream& ifstr, jwDOUBLE& input)
371 {
372 	ifstr.read((char*)&input, sizeof(jwDOUBLE));
373     return ifstr;
374 }
375 
376 inline ofstream& operator<< (ofstream& ofstr, const jwDWORD& output)
377 {
378 	ofstr.write((char*)&output, sizeof(jwDWORD));
379     return ofstr;
380 }
381 
382 inline ifstream& operator>> (ifstream& ifstr, jwDWORD& input)
383 {
384 	ifstr.read((char*)&input, sizeof(jwDWORD));
385     return ifstr;
386 }
387 
388 inline ofstream& operator<< (ofstream& ofstr, const jwWORD& output)
389 {
390 	ofstr.write((char*)&output, sizeof(jwWORD));
391     return ofstr;
392 }
393 
394 inline ifstream& operator>> (ifstream& ifstr, jwWORD& input)
395 {
396 	ifstr.read((char*)&input, sizeof(jwWORD));
397     return ifstr;
398 }
399 
400 inline ofstream& operator<< (ofstream& ofstr, const jwBYTE& output)
401 {
402 	ofstr.write((char*)&output, sizeof(jwBYTE));
403     return ofstr;
404 }
405 
406 inline ifstream& operator>> (ifstream& ifstr, jwBYTE& input)
407 {
408 	ifstr.read((char*)&input, sizeof(jwBYTE));
409     return ifstr;
410 }
411 
412 inline ofstream& operator<< (ofstream& ofstr, const int& output)
413 {
414 	ofstr.write((char*)&output, sizeof(int));
415     return ofstr;
416 }
417 
418 inline ifstream& operator>> (ifstream& ifstr, int& input)
419 {
420 	ifstr.read((char*)&input, sizeof(int));
421     return ifstr;
422 }
423 
424 /*
425 class String {
426  private:
427 	char* data;
428 	size_t size;
429  public:
430 	String(const char* str = 0)
431 	{
432 		if( str ){
433 			data = new char[strlen(str)+1];
434 			strcpy(data, str);
435 			size = strlen(str);
436 		}else{
437 			data = NULL;
438 			size = 0;
439 		}
440 	}
441 	~String()
442 	{
443 		if(data)
444 			delete data;
445 		size = 0;
446 	}
447 	char*	ascii(){return data;}
448 	int	length(){return size;}
449 	String& operator=(String& str)
450 	{
451 		if(str.length()==0)
452 			return *this;
453 		if(data)
454 			delete data;
455 		data = new char[str.length()+1];
456 		strcpy(data, str.ascii());
457 		size = str.size;
458 		return *this;
459 	}
460 	String& operator=(char *str)
461 	{
462 		if(strlen(str)==0)
463 			return *this;
464 		if(data)
465 			delete data;
466 		size = strlen(str);
467 		data = new char[size+1];
468 		strcpy(data, str);
469 		return *this;
470 	}
471 	friend inline ofstream& operator<<(ofstream&, const String&);
472 	friend inline ifstream& operator>>(ifstream&, String&);
473 	friend inline ostream& operator<<(ostream&, const String&);
474 	friend inline istream& operator>>(istream&, String&);
475 };
476 
477 inline ofstream& operator<< (ofstream& ofstr, const String& output)
478 {
479 	ofstr.write((char*)&(output.size), sizeof(size_t));
480 	ofstr.write(output.data, output.size);
481 	return ofstr;
482 }
483 
484 inline ostream& operator<< (ostream& ostr, const String& output)
485 {
486 	return ostr << output.data;
487 }
488 
489 inline ifstream& operator>> (ifstream& ifstr, String& input)
490 {
491 	ifstr.read((char*)&(input.size), sizeof(size_t));
492 	input.data = new char[input.size+1];
493 	ifstr.read(input.data, input.size);
494 	input.data[input.size] = (char)NULL;
495 	return ifstr;
496 }
497 
498 inline istream& operator>> (istream& istr, String& input)
499 {
500 	const int maxline = 512;
501 	char holder[maxline];
502 	istr.get(holder, maxline, '\n');
503 	input = holder;
504 	return istr;
505 }
506 */
507 #endif//JWTYPE_HEAD
508