source: CMT/v1r25/source/cmt_error.cxx

Last change on this file was 598, checked in by rybkin, 12 years ago

See C.L. 475

  • Property svn:eol-style set to native
File size: 4.2 KB
Line 
1//-----------------------------------------------------------
2// Copyright Christian Arnault LAL-Orsay CNRS
3// arnault@lal.in2p3.fr
4// Modified by garonne@lal.in2p3.fr
5// See the complete license in cmt_license.txt "http://www.cecill.info".
6//-----------------------------------------------------------
7
8#include "cmt_error.h"
9#include "cmt_vector.h"
10#include "cmt_log.h"
11
12class TheError
13{
14public:
15  static TheError& instance ();
16
17  TheError ()
18  {
19    error_names.add() = "ok";
20    error_names.add() = "Warning";
21    error_names.add() = "symbol not found";
22    error_names.add() = "pattern not found";
23    error_names.add() = "constituent not found";
24    error_names.add() = "fragment not found";
25    error_names.add() = "language not found";
26    error_names.add() = "syntax error";
27    error_names.add() = "command not implemented";
28    error_names.add() = "package not found";
29    error_names.add() = "path not found";
30    error_names.add() = "version conflict";
31    error_names.add() = "file access error";
32    error_names.add() = "system error";
33    error_names.add() = "configuration error";
34    error_names.add() = "execution error";
35    error_names.add() = "cannot lock";
36    error_names.add() = "cannot_write_lock";
37    error_names.add() = "cannot_run_lock_command";
38    error_names.add() = "cannot_unlock";
39    error_names.add() = "cannot_run_unlock_command";
40    error_names.add() = "cannot_remove_lock";
41    error_names.add() = "conflicting_lock";
42    error_names.add() = "unknown command";
43    error_names.add() = "wrong symbol type";
44    error_names.add() = "project release conflict";
45    error_names.add() = "execution failed";
46    m_execution_error = 0;
47  }
48
49  ~TheError ()
50  {
51  }
52
53  void clear ()
54  {
55    m_code = CmtError::ok;
56    m_text = "";
57    m_execution_error = 0 ;
58  }
59
60  void set (CmtError::code code, const cmt_string& text, const int execution_error)
61  {
62    m_code = code;
63    m_text = text;
64    m_execution_error = execution_error;
65  }
66
67  CmtError::code get_code () const
68  {
69    return (m_code);
70  }
71
72  int get_last_execution_error ()
73  {
74      return m_execution_error;
75  }
76
77  const cmt_string& get_text () const
78  {
79    return (m_text);
80  }
81
82  const cmt_string& get_name (CmtError::code error) const
83  {
84    const cmt_string& s = error_names[error];
85
86    return (s);
87  }
88
89private:
90  CmtError::code m_code;
91  cmt_string m_text;
92  cmt_vector<cmt_string> error_names;
93  int m_execution_error;
94};
95
96//---------------------------------------------------------------
97TheError& TheError::instance ()
98{
99  static TheError e;
100 
101  return (e);
102}
103
104//---------------------------------------------------------------
105void CmtError::clear ()
106{
107  TheError& e = TheError::instance ();
108
109  e.clear ();
110}
111
112//---------------------------------------------------------------
113bool CmtError::has_pending_error ()
114{
115  TheError& e = TheError::instance ();
116
117  if (e.get_code () == ok) return (false);
118  else return (true);
119}
120
121//---------------------------------------------------------------
122CmtError::code CmtError::get_last_error_code ()
123{
124  TheError& e = TheError::instance ();
125
126  return (e.get_code ());
127}
128
129//---------------------------------------------------------------
130int CmtError::get_last_execution_error ()
131{
132  TheError& e = TheError::instance ();
133
134  return (e.get_last_execution_error ());
135}
136
137//---------------------------------------------------------------
138const cmt_string& CmtError::get_error_name (code error)
139{
140  TheError& e = TheError::instance ();
141
142  return (e.get_name (error));
143}
144
145//---------------------------------------------------------------
146void CmtError::set (code error, const cmt_string& text, const int execution_error)
147{
148  TheError& e = TheError::instance ();
149
150  e.set (error, text, execution_error);
151}
152
153//---------------------------------------------------------------
154cmt_string CmtError::get_last_error ()
155{
156  TheError& e = TheError::instance ();
157
158  cmt_string result;
159
160  result = get_error_name (e.get_code ());
161  result += " : ";
162  result += e.get_text ();
163
164  return (result);
165}
166
167//---------------------------------------------------------------
168void CmtError::print ()
169{
170  /*
171  TheError& e = TheError::instance ();
172
173  cerr << "CMT> Error: " << get_error_name (e.get_code ()) << " : " << e.get_text () << endl;
174  */
175  CmtMessage::error (get_last_error ());
176}
177
Note: See TracBrowser for help on using the repository browser.