source: CMT/v1r20p20081118/source/cmt_error.cxx @ 598

Last change on this file since 598 was 459, checked in by rybkin, 16 years ago

See C.L. 360

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