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

Last change on this file since 656 was 656, checked in by rybkin, 11 years ago

See C.L. 515

  • 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";
[656]20    error_names.add() = "warning";
[2]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";
[598]32    error_names.add() = "system error";
[530]33    error_names.add() = "configuration error";
34    error_names.add() = "execution error";
35    error_names.add() = "cannot lock";
[2]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";
[530]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";
[363]46    m_execution_error = 0;
[2]47  }
48
[459]49  ~TheError ()
[2]50  {
51  }
52
53  void clear ()
54  {
55    m_code = CmtError::ok;
56    m_text = "";
[363]57    m_execution_error = 0 ;
[2]58  }
59
[363]60  void set (CmtError::code code, const cmt_string& text, const int execution_error)
[2]61  {
62    m_code = code;
63    m_text = text;
[363]64    m_execution_error = execution_error;
[2]65  }
66
67  CmtError::code get_code () const
68  {
69    return (m_code);
70  }
71
[363]72  int get_last_execution_error ()
73  {
74      return m_execution_error;
75  }
76
[2]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;
[363]93  int m_execution_error;
[2]94};
95
96//---------------------------------------------------------------
[459]97TheError& TheError::instance ()
[2]98{
[459]99  static TheError e;
[2]100 
101  return (e);
102}
103
104//---------------------------------------------------------------
105void CmtError::clear ()
106{
[459]107  TheError& e = TheError::instance ();
[2]108
109  e.clear ();
110}
111
112//---------------------------------------------------------------
113bool CmtError::has_pending_error ()
114{
[459]115  TheError& e = TheError::instance ();
[2]116
117  if (e.get_code () == ok) return (false);
118  else return (true);
119}
120
121//---------------------------------------------------------------
122CmtError::code CmtError::get_last_error_code ()
123{
[459]124  TheError& e = TheError::instance ();
[2]125
126  return (e.get_code ());
127}
128
129//---------------------------------------------------------------
[363]130int CmtError::get_last_execution_error ()
131{
[459]132  TheError& e = TheError::instance ();
[363]133
134  return (e.get_last_execution_error ());
135}
136
137//---------------------------------------------------------------
[2]138const cmt_string& CmtError::get_error_name (code error)
139{
[459]140  TheError& e = TheError::instance ();
[2]141
142  return (e.get_name (error));
143}
144
145//---------------------------------------------------------------
[363]146void CmtError::set (code error, const cmt_string& text, const int execution_error)
[2]147{
[459]148  TheError& e = TheError::instance ();
[2]149
[363]150  e.set (error, text, execution_error);
[2]151}
152
153//---------------------------------------------------------------
154cmt_string CmtError::get_last_error ()
155{
[459]156  TheError& e = TheError::instance ();
[2]157
158  cmt_string result;
159
160  result = get_error_name (e.get_code ());
[656]161  result += ": ";
[2]162  result += e.get_text ();
163
164  return (result);
165}
166
167//---------------------------------------------------------------
168void CmtError::print ()
169{
[459]170  /*
171  TheError& e = TheError::instance ();
[2]172
173  cerr << "CMT> Error: " << get_error_name (e.get_code ()) << " : " << e.get_text () << endl;
[459]174  */
175  CmtMessage::error (get_last_error ());
[2]176}
177
Note: See TracBrowser for help on using the repository browser.