UTStatus.h
Go to the documentation of this file.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 #ifndef _UT_H_
00026 #error "DO NOT INCLUDE THIS FILE - INCLUDE UT.h INSTEAD"
00027 #endif
00028
00029
00030
00031
00032
00040 typedef int32 error_code_t;
00041
00042 #if __cplusplus
00047 #define ERROR_CODE(error_code) ( static_cast<error_code_t>(error_code) )
00048 #else
00049 #define ERROR_CODE(error_code) ( (error_code_t)(error_code) )
00050 #endif
00051
00052 #if WINDOWS
00053
00055 #define eERR_windows_error_base ERROR_CODE(0xC0000000)
00056
00057 #endif
00058
00061 #define eERR_unknown_error ERROR_CODE(0xE0000000)
00062
00064 #define eERR_user_base ERROR_CODE(0xE0010000)
00065
00067 #define eERR_posix_error_base ERROR_CODE(0xEF000000)
00068
00069
00070
00071
00072
00073
00074
00075 #if __cplusplus
00076
00077 class String_t;
00078 class RefCountedString_t;
00079
00080
00081
00082 class UT_EXPORT Status_t
00083
00096 {
00097
00098 public:
00099
00100 inline Status_t();
00103
00104 inline Status_t(error_code_t error_code);
00113
00114 inline Status_t( error_code_t error_code, const utf8* explanation );
00129
00130 inline Status_t( error_code_t error_code, stringliteral* explanation );
00148
00149 Status_t( error_code_t error_code, const String_t& explanation );
00164
00165 inline Status_t(const Status_t& copy);
00169
00170 Status_t( const Status_t& copy, const utf8* explanation );
00179
00180 Status_t( const Status_t& copy, stringliteral* explanation );
00192
00193 Status_t( const Status_t& copy, const String_t& explanation );
00202
00203 inline ~Status_t();
00209
00210 inline const Status_t& operator =(const Status_t& set);
00219
00220 inline const Status_t& operator =(error_code_t set);
00227
00228 inline error_code_t StatusCode() const;
00232
00233 inline bool Success() const;
00237
00238 inline bool SuccessAndTrue() const;
00242
00243 inline bool SuccessAndFalse() const;
00247
00248 const String_t* Explanation() const;
00250
00251 bool operator ==(const Status_t& other) const;
00256
00257 inline bool operator ==(error_code_t error_code) const;
00261
00262 inline bool operator !=(const Status_t& other);
00268
00269 inline bool operator !=(error_code_t error_code);
00273
00274 inline bool operator <(int32 value);
00277
00278 inline bool operator <=(int32 value);
00282
00283 inline bool operator >(int32 value);
00287
00288 inline bool operator >=(int32 value);
00292
00293 #if WINDOWS
00294 static Status_t GetLastWinError();
00297
00298 static Status_t GetLastWinError(const utf8* extra_explanation);
00306
00307 static Status_t GetLastWinError(const String_t& extra_explanation);
00315
00316 static Status_t GetLastWinError(stringliteral* extra_explanation);
00327
00328 inline static Status_t WinError(int32 windows_error_code);
00331
00332 inline static Status_t WinError( int32 windows_error_code,
00333 const utf8* extra_explanation );
00342
00343 inline static Status_t WinError( int32 windows_error_code,
00344 stringliteral* extra_explanation );
00356 #endif
00357
00358 inline static Status_t POSIXError(int posix_error_code);
00361
00362 inline static Status_t POSIXError( int posix_error_code,
00363 const utf8* extra_explanation );
00372
00373 inline static Status_t POSIXError( int posix_error_code,
00374 stringliteral* extra_explanation );
00386
00387
00388 private:
00389
00390 void CreateExplanation(const utf8* explanation);
00391
00392
00393
00394
00395 void CreateExplanation(stringliteral* explanation);
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406 void AddExplanation(RefCountedString_t* explanation);
00407
00408
00409
00410
00411
00412 void RemoveExplanation();
00413
00414
00415
00416
00417
00418 private:
00419
00420 error_code_t m_error_code;
00421 RefCountedString_t* m_explanation;
00422 };
00423
00424
00425 #endif // __cplusplus
00426
00427
00428
00429
00430
00431
00445 #define DEFINE_USER_ERROR( error, string )
00446 #include "UTErrorCodes.h"
00447
00448
00449 #if __cplusplus
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459 inline
00460 Status_t::Status_t()
00461 {
00462 m_error_code = 0;
00463 m_explanation = NULL;
00464 }
00465
00466
00467 inline
00468 Status_t::Status_t(error_code_t error_code)
00469 {
00470 m_error_code = error_code;
00471 m_explanation = NULL;
00472 }
00473
00474
00475 inline
00476 Status_t::Status_t( error_code_t error_code, const utf8* explanation )
00477 {
00478 m_error_code = error_code;
00479 assert(explanation);
00480 CreateExplanation(explanation);
00481 }
00482
00483
00484 inline
00485 Status_t::Status_t( error_code_t error_code, stringliteral* explanation )
00486 {
00487 m_error_code = error_code;
00488 assert(explanation);
00489 CreateExplanation(explanation);
00490 }
00491
00492
00493 inline
00494 Status_t::Status_t(const Status_t& copy)
00495 {
00496 m_error_code = copy.m_error_code;
00497 m_explanation = NULL;
00498 if(copy.m_explanation)
00499 AddExplanation(copy.m_explanation);
00500 }
00501
00502
00503 inline
00504 Status_t::~Status_t()
00505 {
00506 if(m_explanation)
00507 RemoveExplanation();
00508 }
00509
00510
00511 inline const Status_t&
00512 Status_t::operator =(const Status_t& set)
00513 {
00514 m_error_code = set.m_error_code;
00515 if(m_explanation)
00516 RemoveExplanation();
00517 if( set.Explanation() )
00518 AddExplanation(set.m_explanation);
00519 return *this;
00520 }
00521
00522
00523 inline const Status_t&
00524 Status_t::operator =(error_code_t set)
00525 {
00526 m_error_code = set;
00527 if(m_explanation)
00528 RemoveExplanation();
00529 return *this;
00530 }
00531
00532
00533 inline bool
00534 Status_t::Success() const
00535 {
00536 return (m_error_code >= 0);
00537 }
00538
00539
00540 inline bool
00541 Status_t::SuccessAndTrue() const
00542 {
00543 return (m_error_code > 0);
00544 }
00545
00546
00547 inline bool
00548 Status_t::SuccessAndFalse() const
00549 {
00550 return (m_error_code == 0);
00551 }
00552
00553
00554 inline error_code_t
00555 Status_t::StatusCode() const
00556 {
00557 return m_error_code;
00558 }
00559
00560
00561 inline bool
00562 Status_t::operator ==(error_code_t error_code) const
00563 {
00564 return (m_error_code == error_code);
00565 }
00566
00567
00568 inline bool
00569 Status_t::operator !=(const Status_t& other)
00570 {
00571 return !(*this == other);
00572 }
00573
00574
00575 inline bool
00576 Status_t::operator !=(error_code_t error_code)
00577 {
00578 return (m_error_code != error_code);
00579 }
00580
00581
00582 inline bool
00583 Status_t::operator <(int32 value)
00584 {
00585 return (m_error_code < value);
00586 }
00587
00588
00589 inline bool
00590 Status_t::operator <=(int32 value)
00591 {
00592 return (m_error_code <= value);
00593 }
00594
00595
00596 inline bool
00597 Status_t::operator >(int32 value)
00598 {
00599 return (m_error_code > value);
00600 }
00601
00602
00603 inline bool
00604 Status_t::operator >=(int32 value)
00605 {
00606 return (m_error_code >= value);
00607 }
00608
00609
00610 #if WINDOWS
00611
00612
00613 inline Status_t
00614 Status_t::WinError(int32 windows_error_code)
00615 {
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631 return (windows_error_code | eERR_windows_error_base);
00632 }
00633
00634
00635 inline Status_t
00636 Status_t::WinError( int32 win_error_code, const utf8* explanation )
00637 {
00638 return Status_t( win_error_code | eERR_windows_error_base, explanation );
00639 }
00640
00641
00642 inline Status_t
00643 Status_t::WinError( int32 win_error_code, stringliteral* explanation )
00644 {
00645 return Status_t( win_error_code | eERR_windows_error_base, explanation );
00646 }
00647
00648
00649 #endif
00650
00651
00652 inline Status_t
00653 Status_t::POSIXError(int posix_error_code)
00654 {
00655
00656 return ( (posix_error_code & 0x0000FFFF) | eERR_posix_error_base );
00657 }
00658
00659
00660 inline Status_t
00661 Status_t::POSIXError( int posix_error_code, const utf8* explanation )
00662 {
00663 return Status_t( (posix_error_code & 0x0000FFFF) | eERR_posix_error_base, explanation );
00664 }
00665
00666
00667 inline Status_t
00668 Status_t::POSIXError( int posix_error_code, stringliteral* explanation )
00669 {
00670 return Status_t( (posix_error_code & 0x0000FFFF) | eERR_posix_error_base, explanation );
00671 }
00672
00673
00674 #endif // __cplusplus