source: CMT/v1r25-branch/source/cmt_error.cxx @ 666

Last change on this file since 666 was 666, checked in by rybkin, 10 years ago

merge -r 664:665 HEAD

  • Property svn:eol-style set to native
File size: 4.3 KB
RevLine 
[2]1//-----------------------------------------------------------
2// Copyright Christian Arnault LAL-Orsay CNRS
3// arnault@lal.in2p3.fr
[363]4// Modified by garonne@lal.in2p3.fr
[664]5// Modified by Grigory Rybkin
[2]6// See the complete license in cmt_license.txt "http://www.cecill.info".
7//-----------------------------------------------------------
8
9#include "cmt_error.h"
10#include "cmt_vector.h"
[459]11#include "cmt_log.h"
[2]12
[459]13class TheError
[2]14{
15public:
[459]16  static TheError& instance ();
[2]17
[459]18  TheError ()
[2]19  {
20    error_names.add() = "ok";
[664]21    error_names.add() = "warning";
[2]22    error_names.add() = "symbol not found";
23    error_names.add() = "pattern not found";
[528]24    error_names.add() = "constituent not found";
25    error_names.add() = "fragment not found";
26    error_names.add() = "language not found";
[2]27    error_names.add() = "syntax error";
[530]28    error_names.add() = "command not implemented";
29    error_names.add() = "package not found";
30    error_names.add() = "path not found";
31    error_names.add() = "version conflict";
32    error_names.add() = "file access error";
[598]33    error_names.add() = "system error";
[530]34    error_names.add() = "configuration error";
35    error_names.add() = "execution error";
36    error_names.add() = "cannot lock";
[2]37    error_names.add() = "cannot_write_lock";
38    error_names.add() = "cannot_run_lock_command";
39    error_names.add() = "cannot_unlock";
40    error_names.add() = "cannot_run_unlock_command";
41    error_names.add() = "cannot_remove_lock";
42    error_names.add() = "conflicting_lock";
[530]43    error_names.add() = "unknown command";
44    error_names.add() = "wrong symbol type";
45    error_names.add() = "project release conflict";
46    error_names.add() = "execution failed";
[363]47    m_execution_error = 0;
[2]48  }
49
[459]50  ~TheError ()
[2]51  {
52  }
53
54  void clear ()
55  {
56    m_code = CmtError::ok;
57    m_text = "";
[363]58    m_execution_error = 0 ;
[2]59  }
60
[363]61  void set (CmtError::code code, const cmt_string& text, const int execution_error)
[2]62  {
63    m_code = code;
64    m_text = text;
[363]65    m_execution_error = execution_error;
[2]66  }
67
68  CmtError::code get_code () const
69  {
70    return (m_code);
71  }
72
[363]73  int get_last_execution_error ()
74  {
75      return m_execution_error;
76  }
77
[2]78  const cmt_string& get_text () const
79  {
80    return (m_text);
81  }
82
83  const cmt_string& get_name (CmtError::code error) const
84  {
85    const cmt_string& s = error_names[error];
86
87    return (s);
88  }
89
90private:
91  CmtError::code m_code;
92  cmt_string m_text;
93  cmt_vector<cmt_string> error_names;
[363]94  int m_execution_error;
[2]95};
96
97//---------------------------------------------------------------
[459]98TheError& TheError::instance ()
[2]99{
[459]100  static TheError e;
[2]101 
102  return (e);
103}
104
105//---------------------------------------------------------------
106void CmtError::clear ()
107{
[459]108  TheError& e = TheError::instance ();
[2]109
110  e.clear ();
111}
112
113//---------------------------------------------------------------
114bool CmtError::has_pending_error ()
115{
[459]116  TheError& e = TheError::instance ();
[2]117
118  if (e.get_code () == ok) return (false);
119  else return (true);
120}
121
122//---------------------------------------------------------------
123CmtError::code CmtError::get_last_error_code ()
124{
[459]125  TheError& e = TheError::instance ();
[2]126
127  return (e.get_code ());
128}
129
130//---------------------------------------------------------------
[363]131int CmtError::get_last_execution_error ()
132{
[459]133  TheError& e = TheError::instance ();
[363]134
135  return (e.get_last_execution_error ());
136}
137
138//---------------------------------------------------------------
[2]139const cmt_string& CmtError::get_error_name (code error)
140{
[459]141  TheError& e = TheError::instance ();
[2]142
143  return (e.get_name (error));
144}
145
146//---------------------------------------------------------------
[363]147void CmtError::set (code error, const cmt_string& text, const int execution_error)
[2]148{
[459]149  TheError& e = TheError::instance ();
[2]150
[363]151  e.set (error, text, execution_error);
[2]152}
153
154//---------------------------------------------------------------
155cmt_string CmtError::get_last_error ()
156{
[459]157  TheError& e = TheError::instance ();
[2]158
159  cmt_string result;
160
161  result = get_error_name (e.get_code ());
[664]162  result += ": ";
[2]163  result += e.get_text ();
164
165  return (result);
166}
167
168//---------------------------------------------------------------
169void CmtError::print ()
170{
[459]171  /*
172  TheError& e = TheError::instance ();
[2]173
174  cerr << "CMT> Error: " << get_error_name (e.get_code ()) << " : " << e.get_text () << endl;
[459]175  */
[666]176  if (CmtError::get_last_error_code () != CmtError::warning)
177    CmtMessage::error (get_last_error ());
178  else
179    CmtMessage::warning (get_last_error ());
[2]180}
181
Note: See TracBrowser for help on using the repository browser.