exception-abstract.h 3.6 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 * Copyright Projet JRL-Japan, 2007
 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *
 * File:      exception-abstract.h
 * Project:   SOT
 * Author:    Nicolas Mansard
 *
 * Version control
 * ===============
 *
 *  $Id$
 *
 * Description
 * ============
 *
 *
 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/


#ifndef __ABSTRACT_EXCEPTION_H
#define __ABSTRACT_EXCEPTION_H

/* --------------------------------------------------------------------- */
/* --- INCLUDE --------------------------------------------------------- */
/* --------------------------------------------------------------------- */


/* Classes standards. */
#include <iostream>                /* Classe ostream.    */
#include <string>                  /* Classe string.     */
32
#include <dynamic-graph/dynamic-graph-API.h>
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145


// Uncomment this macros to have lines parameter on the throw display
// #define SOT_EXCEPTION_PASSING_PARAM 

/* --------------------------------------------------------------------- */
/* --- CLASS ----------------------------------------------------------- */
/* --------------------------------------------------------------------- */

namespace dynamicgraph {

/* \class ExceptionAbstract
 */
class DYNAMICGRAPH_EXPORT ExceptionAbstract
{

 public:

  enum ExceptionEnum
    {
      ABSTRACT = 0
      ,SIGNAL = 100
      ,FACTORY = 200
    };

  static const std::string EXCEPTION_NAME;
  virtual const std::string& getExceptionName( void ) const { return EXCEPTION_NAME; }

 protected:
  /** Error code.
   * \sa ErrorCodeEnum */
  int code;

  /**  Error message (can be empty). */
  std::string message;

private:

  /**  forbid the empty constructor (private). */
  ExceptionAbstract( void );
public:

  ExceptionAbstract( const int& code, const std::string & msg = "" );
  virtual ~ExceptionAbstract( void ){}

  /**  Access to the error code. */
  int getCode (void);

  /** Reference access to the error message (can be empty). */
  const std::string &getStringMessage (void);

  /** Access to the pointer on the array of  \e char related to the error string.
   * Cannot be  \e NULL.
   */
  const char *getMessage (void);

  
  /** Print the error structure. */
  DYNAMICGRAPH_EXPORT friend std::ostream & operator << (std::ostream & os,
				     const ExceptionAbstract & err);

#ifdef SOT_EXCEPTION_PASSING_PARAM 
 public:
  class Param
    {
    public:
      static const int BUFFER_SIZE = 80;

      const char * functionPTR;
      char function[ BUFFER_SIZE ];
      int line;
      const char * filePTR;
      char file[ BUFFER_SIZE ];
      bool pointersSet,set;
    public:
      Param( const int& _line, const char * _function, const char * _file );
      Param( void ) : pointersSet(false),set(false) {}
      Param& initCopy( const Param& p );
	
    };

 protected:
  mutable Param p;

  template<class Exc>
    friend const Exc& operator+ ( const ExceptionAbstract::Param& p, const Exc& e )
    { e.p.initCopy(p);   return e;    }
  template<class Exc>
    friend Exc& operator+ ( const ExceptionAbstract::Param& p, Exc& e )
    { e.p.initCopy(p);   return e;    }
#endif //#ifdef SOT_EXCEPTION_PASSING_PARAM 
};

} // namespace dynamicgraph

#define DG_RETHROW ( const ExceptionAbstract& err ) { throw err; }



#ifdef SOT_EXCEPTION_PASSING_PARAM 
#  define DG_THROW throw ExceptionAbstract::Param(__LINE__,__FUNCTION__,__FILE__) +
#else //#ifdef SOT_EXCEPTION_PASSING_PARAM 
#  define DG_THROW throw
#endif //#ifdef SOT_EXCEPTION_PASSING_PARAM 


#endif /* #ifndef __ABSTRACT_EXCEPTION_H */

/*
 * Local variables:
 * c-basic-offset: 2
 * End:
 */