source: CMT/v1r20p20070208/source/cmt_error.cxx

Last change on this file was 363, checked in by garonne, 17 years ago

see C.L 322

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