SEP Solver Library  1.0
 All Classes Namespaces Files Functions Variables Typedefs Macros
except.h
Go to the documentation of this file.
1 #ifndef EXCEPTION_H
2 #define EXCEPTION_H 1
3 #include<exception>
4 #include<string>
5 #include<ostream>
6 #define BUFLEN 1024
7 namespace SEP {
8 
9 
10 
11 
12 class SEPException: public std::exception {
13  private:
14  std::string msg;
15  public:
16  SEPException(): msg("") {}
17 
18  SEPException(const std::string& s): msg(s) {}
19 
20  SEPException(const SEPException &s): std::exception(), msg(""){
21  msg+=s.msg;
22  }
23  virtual ~SEPException() throw() {}
24 
25 
26  SEPException & operator<< ( std::string str ) {
27  msg += str;
28  return *this;
29  }
30  const char* what() const throw() { return msg.c_str(); }
31 
32  SEPException & operator<< ( const char* str ) {
33  msg += str;
34  return *this;
35  }
37  char buf[ BUFLEN ];
38  sprintf( buf, "%d", i );
39  msg += buf;
40  return *this;
41  }
42  SEPException & operator<< ( unsigned int i ) {
43  char buf[ BUFLEN ];
44  sprintf( buf, "%u", i );
45  msg += buf;
46  return *this;
47  }
48  SEPException & operator<< ( long i ) {
49  char buf[ BUFLEN ];
50  sprintf( buf, "%ld", i );
51  msg += buf;
52  return *this;
53  }
54  SEPException & operator<< ( unsigned long i ) {
55  char buf[ BUFLEN ];
56  sprintf( buf, "%lu", i );
57  msg += buf;
58  return *this;
59  }
60  SEPException & operator<< ( short i ) {
61  char buf[ BUFLEN ];
62  sprintf( buf, "%d", i );
63  msg += buf;
64  return *this;
65  }
66  SEPException & operator<< ( unsigned short i ) {
67  char buf[ BUFLEN ];
68  sprintf( buf, "%d", i );
69  msg += buf;
70  return *this;
71  }
72  /*
73  SEPException & operator<< ( off_t i ) {
74  char buf[ BUFLEN ];
75  sprintf( buf, "%zd", i );
76  msg += buf;
77  return *this;
78  }
79  */
80  SEPException & operator<< ( double d ) {
81  char buf[ BUFLEN ];
82  sprintf( buf, "%g", d );
83  msg += buf;
84  return *this;
85  }
86  SEPException & operator<< ( float d ) {
87  char buf[ BUFLEN ];
88  sprintf( buf, "%g", d );
89  msg += buf;
90  return *this;
91  }
92  template<class T>
93  /*
94  SEPException & operator<< ( complex<T> d ) {
95  char buf[ BUFLEN ];
96  sprintf( buf, "(%g,%g)", d.real(),d.imag() );
97  msg += buf;
98  return *this;
99  }
100 */
101  SEPException & operator<< ( char c ) {
102  char buf[ BUFLEN ];
103  buf[ 0 ] = c;
104  buf[ 1 ] = '\0';
105  msg += buf;
106  return *this;
107  }
108 
109  std::ostream & write(std::ostream & str) const {
110  str<<msg<<std::endl;
111  return str;
112  }
113  };
114 
115 }
116 #endif