source: CMT/v1r19/source/cmt_error.cxx @ 11

Last change on this file since 11 was 11, checked in by arnault, 19 years ago

Changing eol-style property

  • Property svn:eol-style set to native
File size: 3.3 KB
Line 
1//-----------------------------------------------------------
2// Copyright Christian Arnault LAL-Orsay CNRS
3// arnault@lal.in2p3.fr
4// See the complete license in cmt_license.txt "http://www.cecill.info".
5//-----------------------------------------------------------
6
7#include "cmt_error.h"
8#include "cmt_vector.h"
9
10class Error
11{
12public:
13  static Error& instance ();
14
15  Error ()
16  {
17    error_names.add() = "ok";
18    error_names.add() = "Warning";
19    error_names.add() = "symbol not found";
20    error_names.add() = "pattern not found";
21    error_names.add() = "syntax error";
22    error_names.add() = "command_not_implemented";
23    error_names.add() = "package_not_found";
24    error_names.add() = "path_not_found";
25    error_names.add() = "version_conflict";
26    error_names.add() = "file_access_error";
27    error_names.add() = "execution_error";
28    error_names.add() = "cannot_lock";
29    error_names.add() = "cannot_write_lock";
30    error_names.add() = "cannot_run_lock_command";
31    error_names.add() = "cannot_unlock";
32    error_names.add() = "cannot_run_unlock_command";
33    error_names.add() = "cannot_remove_lock";
34    error_names.add() = "conflicting_lock";
35    error_names.add() = "unknown_command";
36    error_names.add() = "project_release_conflict";
37  }
38
39  ~Error ()
40  {
41  }
42
43  void clear ()
44  {
45    m_code = CmtError::ok;
46    m_text = "";
47  }
48
49  void set (CmtError::code code, const cmt_string& text)
50  {
51    m_code = code;
52    m_text = text;
53  }
54
55  CmtError::code get_code () const
56  {
57    return (m_code);
58  }
59
60  const cmt_string& get_text () const
61  {
62    return (m_text);
63  }
64
65  const cmt_string& get_name (CmtError::code error) const
66  {
67    const cmt_string& s = error_names[error];
68
69    return (s);
70  }
71
72private:
73  CmtError::code m_code;
74  cmt_string m_text;
75  cmt_vector<cmt_string> error_names;
76};
77
78//---------------------------------------------------------------
79Error& Error::instance ()
80{
81  static Error e;
82 
83  return (e);
84}
85
86//---------------------------------------------------------------
87void CmtError::clear ()
88{
89  Error& e = Error::instance ();
90
91  e.clear ();
92}
93
94//---------------------------------------------------------------
95bool CmtError::has_pending_error ()
96{
97  Error& e = Error::instance ();
98
99  if (e.get_code () == ok) return (false);
100  else return (true);
101}
102
103//---------------------------------------------------------------
104CmtError::code CmtError::get_last_error_code ()
105{
106  Error& e = Error::instance ();
107
108  return (e.get_code ());
109}
110
111//---------------------------------------------------------------
112const cmt_string& CmtError::get_error_name (code error)
113{
114  Error& e = Error::instance ();
115
116  return (e.get_name (error));
117}
118
119//---------------------------------------------------------------
120void CmtError::set (code error, const cmt_string& text)
121{
122  Error& e = Error::instance ();
123
124  e.set (error, text);
125}
126
127//---------------------------------------------------------------
128cmt_string CmtError::get_last_error ()
129{
130  Error& e = Error::instance ();
131
132  cmt_string result;
133
134  result = get_error_name (e.get_code ());
135  result += " : ";
136  result += e.get_text ();
137
138  return (result);
139}
140
141//---------------------------------------------------------------
142void CmtError::print ()
143{
144  Error& e = Error::instance ();
145
146  cerr << "CMT> Error: " << get_error_name (e.get_code ()) << " : " << e.get_text () << endl;
147}
148
Note: See TracBrowser for help on using the repository browser.