The vbs tools - vbs_ls, vbs_rm, vbs_fs - for listing, removing and mounting vbs and Mark6 format scattered VLBI recordings on FlexBuff and Mark6 systems
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

152 lines
4.3 KiB

  1. // use this to define/declare exceptions of your own type
  2. // Copyright (C) 2007-2008 Harro Verkouter
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful, but WITHOUT ANY
  10. // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  11. // PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. //
  16. // Author: Harro Verkouter - verkouter@jive.nl
  17. // Joint Institute for VLBI in Europe
  18. // P.O. Box 2
  19. // 7990 AA Dwingeloo
  20. //
  21. // All exceptions take "const std::string&" as c'tor arg and are
  22. // derived off of std::exception.
  23. //
  24. // Usagage:
  25. // in .h file:
  26. // #include <ezexcept.h>
  27. // DECLARE_EZEXCEPT(Whatchamacallem);
  28. //
  29. // in .cc
  30. // DEFINE_EZEXCEPT(Whatchamacallem);
  31. // ...
  32. /// if( usr_fscked_up )
  33. // throw Whatchamacallem("Usr fscked up!");
  34. #ifndef JIVE5A_EZEXCEPT_H
  35. #define JIVE5A_EZEXCEPT_H
  36. #include <exception>
  37. #include <string>
  38. #include <sstream>
  39. // Declare the prototype of the exception
  40. #define DECLARE_EZEXCEPT(xept) \
  41. struct xept:\
  42. public std::exception\
  43. {\
  44. xept( const std::string& m = std::string() );\
  45. virtual const char* what( void ) const throw();\
  46. virtual ~xept() throw();\
  47. const std::string __m;\
  48. };
  49. // For the xtra-lzy ppl: throws + prefixed with
  50. // FILE:LINE
  51. #define THROW_EZEXCEPT(xept, msg) \
  52. do { int eZ_Lijn_gH = __LINE__; \
  53. const std::string eZ_Fijl_9q( __FILE__ );\
  54. std::ostringstream eZ_Stroom_yw;\
  55. eZ_Stroom_yw << eZ_Fijl_9q << "@" << eZ_Lijn_gH << " - " << msg;\
  56. throw xept(eZ_Stroom_yw.str());\
  57. } while( 0 );
  58. // And this is to go in your .cc file
  59. #define DEFINE_EZEXCEPT(xept) \
  60. xept::xept( const std::string& m ):\
  61. __m( m )\
  62. {} \
  63. const char* xept::what( void ) const throw() {\
  64. return __m.c_str();\
  65. }\
  66. xept::~xept() throw() \
  67. {}
  68. // Set up the defines to make it all readable (ahem) and usable
  69. #define EZCALLLOCATION \
  70. std::string ez_fn_( __FILE__); int ez_ln_(__LINE__);
  71. #define EZCALLSTUFF(fubarvar) \
  72. std::ostringstream ezlclSvar_0a;\
  73. ezlclSvar_0a << ez_fn_ << "@" << ez_ln_ << " assertion [" << fubarvar << "] fails ";
  74. // EZINFO
  75. // can be used to add extra info to the errormessage. Use as (one of) the
  76. // entries in the EZASSERT2_*() macros: eg:
  77. // EZASSERT2(idx<length,
  78. // EZINFO("idx " << idx << ">= length " << length));
  79. #define EZINFO(a) \
  80. ezlclSvar_0a << a;
  81. // The actual assertions:
  82. // The throw 'e' if 'a' is not met, executing 'b' before throwing
  83. // generic assertion "a"
  84. // [w/o cleanup is just "with cleanup" where the cleanup is a nop]
  85. #define EZASSERT2(a, e, b) \
  86. do {\
  87. if( !(a) ) { \
  88. EZCALLLOCATION;\
  89. EZCALLSTUFF(#a);\
  90. b;\
  91. throw e( ezlclSvar_0a.str() ); \
  92. } \
  93. } while( 0 );
  94. #define EZASSERT(a, e) \
  95. EZASSERT2(a, e, ;)
  96. // assert "a==0"
  97. // [w/o cleanup is just "with cleanup" where the cleanup is a nop]
  98. #define EZASSERT2_ZERO(a, e, b) \
  99. do {\
  100. if( !((a)==0) ) { \
  101. EZCALLLOCATION;\
  102. EZCALLSTUFF(#a);\
  103. b;\
  104. throw e( ezlclSvar_0a.str() ); \
  105. } \
  106. } while( 0 );
  107. #define EZASSERT_ZERO(a, e) \
  108. EZASSERT2_ZERO(a, e, ;)
  109. // assert "a!=0"
  110. // [w/o cleanup is just "with cleanup" where the cleanup is a nop]
  111. #define EZASSERT2_NZERO(a, e, b) \
  112. do {\
  113. if( !((a)!=0) ) { \
  114. EZCALLLOCATION;\
  115. EZCALLSTUFF(#a);\
  116. b;\
  117. throw e( ezlclSvar_0a.str() ); \
  118. } \
  119. } while( 0 );
  120. #define EZASSERT_NZERO(a, e) \
  121. EZASSERT2_NZERO(a, e, ;)
  122. // assert "a>=0" [a is non-negative]
  123. // [w/o cleanup is just "with cleanup" where the cleanup is a nop]
  124. #define EZASSERT2_POS(a, e, b) \
  125. do {\
  126. if( !((a)>=0) ) { \
  127. EZCALLLOCATION;\
  128. EZCALLSTUFF(#a);\
  129. b;\
  130. throw e( ezlclSvar_0a.str() ); \
  131. } \
  132. } while( 0 );
  133. #define EZASSERT_POS(a, e) \
  134. EZASSERT2_POS(a, e, ;)
  135. #endif