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

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

See C.L. 415

  • Property svn:eol-style set to native
File size: 4.1 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() = "configuration_error";
33    error_names.add() = "execution_error";
34    error_names.add() = "cannot_lock";
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";
41    error_names.add() = "unknown_command";
42    error_names.add() = "project_release_conflict";
43    error_names.add() = "execution_failed";
44    m_execution_error = 0;
45  }
46
47  ~TheError ()
48  {
49  }
50
51  void clear ()
52  {
53    m_code = CmtError::ok;
54    m_text = "";
55    m_execution_error = 0 ;
56  }
57
58  void set (CmtError::code code, const cmt_string& text, const int execution_error)
59  {
60    m_code = code;
61    m_text = text;
62    m_execution_error = execution_error;
63  }
64
65  CmtError::code get_code () const
66  {
67    return (m_code);
68  }
69
70  int get_last_execution_error ()
71  {
72      return m_execution_error;
73  }
74
75  const cmt_string& get_text () const
76  {
77    return (m_text);
78  }
79
80  const cmt_string& get_name (CmtError::code error) const
81  {
82    const cmt_string& s = error_names[error];
83
84    return (s);
85  }
86
87private:
88  CmtError::code m_code;
89  cmt_string m_text;
90  cmt_vector<cmt_string> error_names;
91  int m_execution_error;
92};
93
94//---------------------------------------------------------------
95TheError& TheError::instance ()
96{
97  static TheError e;
98 
99  return (e);
100}
101
102//---------------------------------------------------------------
103void CmtError::clear ()
104{
105  TheError& e = TheError::instance ();
106
107  e.clear ();
108}
109
110//---------------------------------------------------------------
111bool CmtError::has_pending_error ()
112{
113  TheError& e = TheError::instance ();
114
115  if (e.get_code () == ok) return (false);
116  else return (true);
117}
118
119//---------------------------------------------------------------
120CmtError::code CmtError::get_last_error_code ()
121{
122  TheError& e = TheError::instance ();
123
124  return (e.get_code ());
125}
126
127//---------------------------------------------------------------
128int CmtError::get_last_execution_error ()
129{
130  TheError& e = TheError::instance ();
131
132  return (e.get_last_execution_error ());
133}
134
135//---------------------------------------------------------------
136const cmt_string& CmtError::get_error_name (code error)
137{
138  TheError& e = TheError::instance ();
139
140  return (e.get_name (error));
141}
142
143//---------------------------------------------------------------
144void CmtError::set (code error, const cmt_string& text, const int execution_error)
145{
146  TheError& e = TheError::instance ();
147
148  e.set (error, text, execution_error);
149}
150
151//---------------------------------------------------------------
152cmt_string CmtError::get_last_error ()
153{
154  TheError& e = TheError::instance ();
155
156  cmt_string result;
157
158  result = get_error_name (e.get_code ());
159  result += " : ";
160  result += e.get_text ();
161
162  return (result);
163}
164
165//---------------------------------------------------------------
166void CmtError::print ()
167{
168  /*
169  TheError& e = TheError::instance ();
170
171  cerr << "CMT> Error: " << get_error_name (e.get_code ()) << " : " << e.get_text () << endl;
172  */
173  CmtMessage::error (get_last_error ());
174}
175
Note: See TracBrowser for help on using the repository browser.