00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00045 #ifndef __PERRCH__
00046 #define __PERRCH__
00047
00048 #include <memory.h>
00049
00050 #ifdef _WIN32
00051 #define HOME "USERPROFILE"
00052 #else
00053 #define HOME "HOME"
00054 #endif
00055
00056 #define PANDORE_TMP "PANDORE_TMP"
00057
00058 namespace pandore {
00060 typedef enum { FAILURE = 0, SUCCESS } FS_t;
00061
00062 class Errc;
00063
00075 void Exit( const Errc &e );
00076
00088 void Exit( FS_t v );
00089
00101 void Exit( int v );
00102
00114 void Exit( Char v );
00115
00127 void Exit( Uchar v );
00128
00140 void Exit( Short v );
00141
00153 void Exit( Ushort v );
00154
00166 void Exit( Long v );
00167
00179 void Exit( Ulong v );
00180
00192 void Exit( Llong v );
00193
00205 void Exit( Ullong v );
00206
00218 void Exit( Float v );
00219
00231 void Exit( Double v );
00232
00233
00256 class Errc {
00257 private:
00258 enum { FS_RET
00259 , Char_RET
00260 , Uchar_RET
00261 , Short_RET
00262 , Ushort_RET
00263 , Long_RET
00264 , Ulong_RET
00265 , Llong_RET
00266 , Ullong_RET
00267 , Float_RET
00268 , Double_RET
00269 } _ret;
00270
00271 public :
00272
00273
00274
00275
00276
00277
00278 Errc( const FS_t value = SUCCESS ) {
00279 _ret = FS_RET;
00280 _val.fs = value;
00281 }
00282
00283
00284
00285
00286
00287 Errc( bool value ) {
00288 _ret = FS_RET;
00289 _val.fs = (value) ? SUCCESS : FAILURE;
00290 }
00291
00292
00293
00294
00295
00296 Errc( Char value ) {
00297 _ret = Char_RET;
00298 _val.v_Char = value;
00299 }
00300
00301
00302
00303
00304 Errc( Uchar value ) {
00305 _ret = Uchar_RET;
00306 _val.v_Uchar = value;
00307 }
00308
00309
00310
00311
00312 Errc( Short value ) {
00313 _ret = Short_RET;
00314 _val.v_Short = value;
00315 }
00316
00317
00318
00319
00320 Errc( Ushort value ) {
00321 _ret = Ushort_RET;
00322 _val.v_Ushort = value;
00323 }
00324
00325
00326
00327
00328 Errc( Long value ) {
00329 _ret = Long_RET;
00330 _val.v_Long = value;
00331 }
00332
00333
00334
00335
00336 Errc( Ulong value ) {
00337 _ret = Ulong_RET;
00338 _val.v_Ulong = value;
00339 }
00340
00341
00342
00343
00344 Errc( Llong value ) {
00345 _ret = Llong_RET;
00346 _val.v_Llong = value;
00347 }
00348
00349
00350
00351
00352 Errc( Ullong value ) {
00353 _ret = Ullong_RET;
00354 _val.v_Ullong = value;
00355 }
00356
00357
00358
00359
00360 Errc( Float value ) {
00361 _ret = Float_RET;
00362 _val.v_Float = value;
00363 }
00364
00365
00366
00367
00368 Errc( Double value ) {
00369 _ret = Double_RET;
00370 _val.v_Double = value;
00371 }
00372
00373
00374
00375
00376
00377 Errc( const Errc &error ) {
00378 _ret = error._ret;
00379 memcpy(&_val, &error._val, sizeof(_val));
00380 }
00381
00386 Errc& operator =( const Errc &error ) {
00387 _ret = error._ret;
00388 memcpy(&_val, &error._val, sizeof(_val));
00389 return *this;
00390 }
00391
00392
00393
00394
00395
00396 operator bool() {
00397 switch(_ret) {
00398 case FS_RET: return _val.fs == SUCCESS;
00399 case Char_RET: return 1;
00400 case Uchar_RET: return 1;
00401 case Short_RET: return 1;
00402 case Ushort_RET: return 1;
00403 case Long_RET: return 1;
00404 case Ulong_RET: return 1;
00405 case Llong_RET: return 1;
00406 case Ullong_RET: return 1;
00407 case Float_RET: return 1;
00408 case Double_RET: return 1;
00409 default: return false;
00410 }
00411 }
00412
00413
00414
00415
00416
00417
00418 operator FS_t() { return _val.fs; }
00419
00420
00421
00422
00423
00424 operator Char() {
00425 switch(_ret) {
00426 case FS_RET: return (Char)(_val.fs == SUCCESS);
00427 case Char_RET: return (Char)_val.v_Char;
00428 case Uchar_RET: return (Char)_val.v_Uchar;
00429 case Short_RET: return (Char)_val.v_Short;
00430 case Ushort_RET: return (Char)_val.v_Ushort;
00431 case Long_RET: return (Char)_val.v_Long;
00432 case Ulong_RET: return (Char)_val.v_Ulong;
00433 case Float_RET: return (Char)_val.v_Float;
00434 case Double_RET : return (Char)_val.v_Double;
00435 case Llong_RET : return (Char)_val.v_Double;
00436 case Ullong_RET : return (Char)_val.v_Double;
00437 default: return 0;
00438 }
00439 }
00440
00441
00442
00443
00444 operator Uchar() {
00445 switch(_ret) {
00446 case FS_RET: return (Uchar)(_val.fs == SUCCESS);
00447 case Char_RET: return (Uchar)_val.v_Char;
00448 case Uchar_RET: return (Uchar)_val.v_Uchar;
00449 case Short_RET: return (Uchar)_val.v_Short;
00450 case Ushort_RET: return (Uchar)_val.v_Ushort;
00451 case Long_RET: return (Uchar)_val.v_Long;
00452 case Ulong_RET: return (Uchar)_val.v_Ulong;
00453 case Float_RET: return (Uchar)_val.v_Float;
00454 case Double_RET : return (Uchar)_val.v_Double;
00455 case Llong_RET : return (Uchar)_val.v_Double;
00456 case Ullong_RET : return (Uchar)_val.v_Double;
00457 default: return 0;
00458 }
00459 }
00460
00461
00462
00463
00464 operator Short() {
00465 switch(_ret) {
00466 case FS_RET: return (Short)(_val.fs == SUCCESS);
00467 case Char_RET: return (Short)_val.v_Char;
00468 case Uchar_RET: return (Short)_val.v_Uchar;
00469 case Short_RET: return (Short)_val.v_Short;
00470 case Ushort_RET: return (Short)_val.v_Ushort;
00471 case Long_RET: return (Short)_val.v_Long;
00472 case Ulong_RET: return (Short)_val.v_Ulong;
00473 case Float_RET: return (Short)_val.v_Float;
00474 case Double_RET : return (Short)_val.v_Double;
00475 case Llong_RET : return (Short)_val.v_Double;
00476 case Ullong_RET : return (Short)_val.v_Double;
00477 default: return 0;
00478 }
00479 }
00480
00481
00482
00483
00484 operator Ushort() {
00485 switch(_ret) {
00486 case FS_RET: return (Ushort)(_val.fs == SUCCESS);
00487 case Char_RET: return (Ushort)_val.v_Char;
00488 case Uchar_RET: return (Ushort)_val.v_Uchar;
00489 case Short_RET: return (Ushort)_val.v_Short;
00490 case Ushort_RET: return (Ushort)_val.v_Ushort;
00491 case Long_RET: return (Ushort)_val.v_Long;
00492 case Ulong_RET: return (Ushort)_val.v_Ulong;
00493 case Float_RET: return (Ushort)_val.v_Float;
00494 case Double_RET : return (Ushort)_val.v_Double;
00495 case Llong_RET : return (Ushort)_val.v_Double;
00496 case Ullong_RET : return (Ushort)_val.v_Double;
00497 default: return 0;
00498 }
00499 }
00500
00501
00502
00503
00504 operator Long() {
00505 switch(_ret) {
00506 case FS_RET: return (Long)(_val.fs == SUCCESS);
00507 case Char_RET: return (Long)_val.v_Char;
00508 case Uchar_RET: return (Long)_val.v_Uchar;
00509 case Short_RET: return (Long)_val.v_Short;
00510 case Ushort_RET: return (Long)_val.v_Ushort;
00511 case Long_RET: return (Long)_val.v_Long;
00512 case Ulong_RET: return (Long)_val.v_Ulong;
00513 case Float_RET: return (Long)_val.v_Float;
00514 case Double_RET : return (Long)_val.v_Double;
00515 case Llong_RET : return (Long)_val.v_Double;
00516 case Ullong_RET : return (Long)_val.v_Double;
00517 default: return 0;
00518 }
00519 }
00520
00521
00522
00523
00524 operator Ulong() {
00525 switch(_ret) {
00526 case FS_RET: return (Ulong)(_val.fs == SUCCESS);
00527 case Char_RET: return (Ulong)_val.v_Char;
00528 case Uchar_RET: return (Ulong)_val.v_Uchar;
00529 case Short_RET: return (Ulong)_val.v_Short;
00530 case Ushort_RET: return (Ulong)_val.v_Ushort;
00531 case Long_RET: return (Ulong)_val.v_Long;
00532 case Ulong_RET: return (Ulong)_val.v_Ulong;
00533 case Float_RET: return (Ulong)_val.v_Float;
00534 case Double_RET : return (Ulong)_val.v_Double;
00535 case Llong_RET : return (Ulong)_val.v_Double;
00536 case Ullong_RET : return (Ulong)_val.v_Double;
00537 default: return 0;
00538 }
00539 }
00540
00541
00542
00543
00544 operator Llong() {
00545 switch(_ret) {
00546 case FS_RET: return (Llong)(_val.fs == SUCCESS);
00547 case Char_RET: return (Llong)_val.v_Char;
00548 case Uchar_RET: return (Llong)_val.v_Uchar;
00549 case Short_RET: return (Llong)_val.v_Short;
00550 case Ushort_RET: return (Llong)_val.v_Ushort;
00551 case Long_RET: return (Llong)_val.v_Long;
00552 case Ulong_RET: return (Llong)_val.v_Ulong;
00553 case Float_RET: return (Llong)_val.v_Float;
00554 case Double_RET : return (Llong)_val.v_Double;
00555 case Llong_RET : return (Llong)_val.v_Double;
00556 case Ullong_RET : return (Llong)_val.v_Double;
00557 default: return 0;
00558 }
00559 }
00560
00561
00562
00563
00564 operator Ullong() {
00565 switch(_ret) {
00566 case FS_RET: return (Ullong)(_val.fs == SUCCESS);
00567 case Char_RET: return (Ullong)_val.v_Char;
00568 case Uchar_RET: return (Ullong)_val.v_Uchar;
00569 case Short_RET: return (Ullong)_val.v_Short;
00570 case Ushort_RET: return (Ullong)_val.v_Ushort;
00571 case Long_RET: return (Ullong)_val.v_Long;
00572 case Ulong_RET: return (Ullong)_val.v_Ulong;
00573 case Float_RET: return (Ullong)_val.v_Float;
00574 case Double_RET : return (Ullong)_val.v_Double;
00575 case Llong_RET : return (Ullong)_val.v_Double;
00576 case Ullong_RET : return (Ullong)_val.v_Double;
00577 default: return 0;
00578 }
00579 }
00580
00581
00582
00583
00584 operator Float() {
00585 switch(_ret) {
00586 case FS_RET: return (Float)(_val.fs == SUCCESS);
00587 case Char_RET: return (Float)_val.v_Char;
00588 case Uchar_RET: return (Float)_val.v_Uchar;
00589 case Short_RET: return (Float)_val.v_Short;
00590 case Ushort_RET: return (Float)_val.v_Ushort;
00591 case Long_RET: return (Float)_val.v_Long;
00592 case Ulong_RET: return (Float)_val.v_Ulong;
00593 case Float_RET: return (Float)_val.v_Float;
00594 case Double_RET : return (Float)_val.v_Double;
00595 case Llong_RET : return (Float)_val.v_Double;
00596 case Ullong_RET : return (Float)_val.v_Double;
00597 default: return 0;
00598 }
00599 }
00600
00601
00602
00603
00604 operator Double() {
00605 switch(_ret) {
00606 case FS_RET: return (Double)(_val.fs == SUCCESS);
00607 case Char_RET: return (Double)_val.v_Char;
00608 case Uchar_RET: return (Double)_val.v_Uchar;
00609 case Short_RET: return (Double)_val.v_Short;
00610 case Ushort_RET: return (Double)_val.v_Ushort;
00611 case Long_RET: return (Double)_val.v_Long;
00612 case Ulong_RET: return (Double)_val.v_Ulong;
00613 case Float_RET: return (Double)_val.v_Float;
00614 case Double_RET : return (Double)_val.v_Double;
00615 case Llong_RET : return (Double)_val.v_Double;
00616 case Ullong_RET : return (Double)_val.v_Double;
00617 default: return 0;
00618 }
00619 }
00620
00624 bool operator !() {
00625 bool b = *this;
00626 return !b;
00627 }
00628
00636 void Exit() const;
00637
00638 friend bool operator !=( Errc &e1, FS_t value ) ;
00639 friend bool operator !=( FS_t value, Errc &e1 ) ;
00640 friend bool operator ==( Errc &e1, FS_t value ) ;
00641 friend bool operator ==( FS_t value, Errc &e1 ) ;
00642 friend bool operator &&( Errc &e1, Errc &e2 ) ;
00643 friend bool operator &&( Errc &e, bool b ) ;
00644 friend bool operator &&( bool b, Errc &e );
00645
00646 friend bool operator ||( Errc &e1, Errc &e2 ) ;
00647 friend bool operator ||( Errc &e, bool b ) ;
00648 friend bool operator ||( bool b, Errc &e );
00649
00650 private:
00652 union {
00653 FS_t fs;
00654 Char v_Char;
00655 Uchar v_Uchar;
00656 Short v_Short;
00657 Ushort v_Ushort;
00658 Long v_Long;
00659 Ulong v_Ulong;
00660 Llong v_Llong;
00661 Ullong v_Ullong;
00662 Float v_Float;
00663 Double v_Double;
00664 } _val;
00665 };
00666
00667 inline bool operator ==( Errc &e, FS_t value ) {
00668 if (e._ret == Errc::FS_RET) {
00669 return e._val.fs == value;
00670 } else {
00671 return false;
00672 }
00673 }
00674
00675 inline bool operator ==( FS_t value, Errc &e ) {
00676 if (e._ret == Errc::FS_RET) {
00677 return e._val.fs == value;
00678 } else {
00679 return false;
00680 }
00681 }
00682
00683 inline bool operator !=( Errc &e, FS_t value ) {
00684 if (e._ret == Errc::FS_RET) {
00685 return e._val.fs != value;
00686 } else {
00687 return true;
00688 }
00689 }
00690
00691 inline bool operator !=( FS_t value, Errc &e ) {
00692 if (e._ret == Errc::FS_RET) {
00693 return e._val.fs != value;
00694 } else {
00695 return true;
00696 }
00697 }
00698
00704 inline bool operator &&( Errc &e1, Errc &e2 ) {
00705 bool b1 = e1;
00706 bool b2 = e2;
00707 return b1 && b2;
00708 }
00709
00715 inline bool operator &&( Errc &e, bool b ) {
00716 bool b1 = e;
00717 return b1 && b;
00718 }
00719
00725 inline bool operator &&( bool b, Errc &e ) {
00726 bool b1 = e;
00727 return b && b1;
00728 }
00729
00735 inline bool operator ||( Errc &e1, Errc &e2 ) {
00736 bool b1 = e1;
00737 bool b2 = e2;
00738 return b1 || b2;
00739 }
00740
00746 inline bool operator ||( Errc &e, bool b ) {
00747 bool b1 = e;
00748 return b1 || b;
00749 }
00750
00756 inline bool operator ||( bool b, Errc &e ) {
00757 bool b1 = e;
00758 return b || b1;
00759 }
00760
00761 }
00762
00763 #endif // __PERRCH__