source: CMT/HEAD/source/cmt_error.cxx @ 597

Last change on this file since 597 was 530, checked in by rybkin, 15 years ago

See C.L. 417

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