source: CMT/v1r10p20011126/src/cmt_error.cxx @ 1

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

Import all tags

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