Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
GenVector_exception.h
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Authors: W. Brown, M. Fischler, L. Moneta 2005
3 
4 #ifndef ROOT_Math_GenVector_GenVector_exception
5 #define ROOT_Math_GenVector_GenVector_exception 1
6 
7 // ======================================================================
8 // $Id $
9 //
10 // Define the exception type used throughout this package.
11 // ======================================================================
12 
13 // ----------------------------------------------------------------------
14 // Prolog
15 
16 #include <stdexcept>
17 #include <string>
18 
19 namespace ROOT {
20 namespace Math {
21 
22 class GenVector_exception;
23 inline void Throw(GenVector_exception &e);
24 namespace GenVector {
25 inline void Throw(const char *);
26 }
27 
28 // ----------------------------------------------------------------------
29 // GenVector_exception class definition
30 //
31 // This class needs to be entirely contained in this header, otherwise
32 // the interactive usage of entities such as ROOT::Math::PtEtaPhiMVector
33 // is not possible because of missing symbols.
34 // This is due to the fact that the Throw function is used in the inline
35 // code bu this function is implemented in the Genvector library.
36 class GenVector_exception : public std::runtime_error {
37 public:
38  GenVector_exception(const std::string &s) : runtime_error(s) {}
39 
40  // Compiler-generated copy ctor, copy assignment, dtor are fine
41  // Inherited what() from runtime_error is fine
42 
43  static bool EnableThrow()
44  {
45  bool tmp = GenVector_exception::IsOn();
46  IsOn() = true;
47  return tmp;
48  }
49  static bool DisableThrow()
50  {
51  bool tmp = GenVector_exception::IsOn();
52  IsOn() = false;
53  return tmp;
54  }
55 
56 private:
57  friend void Throw(GenVector_exception &);
58  friend void GenVector::Throw(const char *);
59 
60  static bool &IsOn()
61  {
62  static bool isOn = false;
63  return isOn;
64  };
65 
66 }; // GenVector_exception
67 
68 // ----------------------------------------------------------------------
69 // Epilog
70 
71 /// throw explicity GenVector exceptions
72 inline void Throw(GenVector_exception &e)
73 {
74  if (GenVector_exception::IsOn())
75  throw e;
76 }
77 
78 namespace GenVector {
79 /// function throwing exception, by creating internally a GenVector_exception only when needed
80 inline void Throw(const char *s)
81 {
82  if (!GenVector_exception::IsOn())
83  return;
84  GenVector_exception e(s);
85  throw e;
86 }
87 } // namespace GenVector
88 
89 } // namespace Math
90 } // namespace ROOT
91 
92 #endif // GENVECTOR_EXCEPTION_H