CMS 3D CMS Logo

Exception.h
Go to the documentation of this file.
1 #ifndef CommonTools_Utils_Exception_h
2 #define CommonTools_Utils_Exception_h
3 // -*- C++ -*-
4 //
5 // Package: CommonTools/Utils
6 // Class : Exception
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Thu Aug 14 17:09:42 EDT 2008
19 // $Id: Exception.h,v 1.2 2009/02/24 14:40:26 llista Exp $
20 //
21 
22 // system include files
23 #include <sstream>
24 #include "boost/spirit/include/classic_exceptions.hpp"
25 
26 // user include files
27 
28 // forward declarations
29 namespace reco {
30  namespace parser {
31  enum SyntaxErrors {
35  };
36 
37  typedef boost::spirit::classic::parser_error<reco::parser::SyntaxErrors> BaseException;
38 
40  inline const char * baseExceptionWhat(const BaseException& e) {
41  switch(e.descriptor) {
43  return "Missing close parenthesis.";
44  case kSyntaxError:
45  return "Syntax error.";
46  case kSpecialError:
47  default:
48  break;
49  }
50  return e.what();
51  }
52  class Exception : public BaseException {
53 
54  public:
55  Exception(const char* iIterator) : BaseException(iIterator,kSpecialError) {}
56  Exception(const Exception& iOther) : BaseException(iOther) {
57  ost_ << iOther.ost_.str();
58  }
59  ~Exception() throw() override {}
60 
61  // ---------- const member functions ---------------------
62  const char* what() const throw() override { what_ = ost_.str(); return what_.c_str();}
63 
64  // ---------- static member functions --------------------
65 
66  // ---------- member functions ---------------------------
67 
68  template<class T>
69  friend Exception& operator<<(Exception&, const T&);
70  template<class T>
71  friend Exception& operator<<(const Exception&, const T&);
72  friend Exception& operator<<(Exception&, std::ostream&(*f)(std::ostream&));
73  friend Exception& operator<<(const Exception&, std::ostream&(*f)(std::ostream&));
74  friend Exception& operator<<(Exception&, std::ios_base&(*f)(std::ios_base&));
75  friend Exception& operator<<(const Exception&, std::ios_base&(*f)(std::ios_base&));
76  private:
77 
78  //const Exception& operator=(const Exception&); // stop default
79 
80  // ---------- member data --------------------------------
81  std::ostringstream ost_;
82  mutable std::string what_; //needed since ost_.str() returns a temporary string
83  };
84 
85  template<class T>
86  inline Exception& operator<<(Exception& e, const T& iT) {
87  e.ost_ << iT;
88  return e;
89  }
90  template<class T>
91  inline Exception& operator<<(const Exception& e, const T& iT) {
92  return operator<<(const_cast<Exception&>(e), iT);
93  }
94  inline Exception& operator<<(Exception& e, std::ostream&(*f)(std::ostream&))
95  {
96  f(e.ost_);
97  return e;
98  }
99  inline Exception& operator<<(const Exception& e, std::ostream&(*f)(std::ostream&))
100  {
101  f(const_cast<Exception&>(e).ost_);
102  return const_cast<Exception&>(e);
103  }
104  inline Exception& operator<<(Exception& e, std::ios_base&(*f)(std::ios_base&)) {
105  f(e.ost_);
106  return e;
107  }
108  inline Exception& operator<<(const Exception& e, std::ios_base&(*f)(std::ios_base&)) {
109  f(const_cast<Exception&>(e).ost_);
110  return const_cast<Exception&>(e);
111  }
112  }
113 }
114 
115 #endif
const char * what() const override
Definition: Exception.h:62
boost::spirit::classic::parser_error< reco::parser::SyntaxErrors > BaseException
Definition: Exception.h:37
friend Exception & operator<<(Exception &, const T &)
Definition: Exception.h:86
double f[11][100]
const char * baseExceptionWhat(const BaseException &e)
returns the appropriate &#39;what&#39; message for the exception
Definition: Exception.h:40
Exception(const char *iIterator)
Definition: Exception.h:55
std::ostringstream ost_
Definition: Exception.h:81
Exception(const Exception &iOther)
Definition: Exception.h:56
fixed size matrix
long double T
~Exception() override
Definition: Exception.h:59