exception-abstract.h 3.69 KB
Newer Older
1
2
3
4
5
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 * Copyright Projet JRL-Japan, 2007
 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *
 * File:      exception-abstract.h
6
 * Project:   DYNAMIC-GRAPH
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
 * 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


// Uncomment this macros to have lines parameter on the throw display
36
// #define DYNAMIC-GRAPH_EXCEPTION_PASSING_PARAM 
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

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

namespace dynamicgraph {

/* \class ExceptionAbstract
 */
class DYNAMICGRAPH_EXPORT ExceptionAbstract
{

 public:

  enum ExceptionEnum
    {
      ABSTRACT = 0
      ,SIGNAL = 100
      ,FACTORY = 200
56
      ,TRACES = 300
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
    };

  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);

95
#ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM 
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
 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;    }
124
#endif //#ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM 
125
126
127
128
129
130
131
132
};

} // namespace dynamicgraph

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



133
#ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM
134
#  define DG_THROW throw ExceptionAbstract::Param(__LINE__,__FUNCTION__,__FILE__) +
135
#else //#ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM 
136
#  define DG_THROW throw
137
#endif //#ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM 
138
139
140
141
142
143
144
145
146


#endif /* #ifndef __ABSTRACT_EXCEPTION_H */

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