Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

cmt_error.cxx

Go to the documentation of this file.
00001 
00002 #include "cmt_error.h"
00003 #include "cmt_vector.h"
00004 
00005 class Error
00006 {
00007 public:
00008   static Error& instance ();
00009 
00010   Error ()
00011       {
00012         error_names.add() = "ok";
00013         error_names.add() = "symbol not found";
00014         error_names.add() = "pattern not found";
00015         error_names.add() = "syntax error";
00016         error_names.add() = "command_not_implemented";
00017         error_names.add() = "package_not_found";
00018         error_names.add() = "path_not_found";
00019         error_names.add() = "version_conflict";
00020         error_names.add() = "file_access_error";
00021         error_names.add() = "execution_error";
00022         error_names.add() = "cannot_lock";
00023         error_names.add() = "cannot_write_lock";
00024         error_names.add() = "cannot_run_lock_command";
00025         error_names.add() = "cannot_unlock";
00026         error_names.add() = "cannot_run_unlock_command";
00027         error_names.add() = "cannot_remove_lock";
00028         error_names.add() = "conflicting_lock";
00029       }
00030 
00031   ~Error ()
00032       {
00033       }
00034 
00035   void clear ()
00036       {
00037         m_code = CmtError::ok;
00038         m_text = "";
00039       }
00040 
00041   void set (CmtError::code code, const cmt_string& text)
00042       {
00043         m_code = code;
00044         m_text = text;
00045       }
00046 
00047   CmtError::code get_code () const
00048       {
00049         return (m_code);
00050       }
00051 
00052   const cmt_string& get_text () const
00053       {
00054         return (m_text);
00055       }
00056 
00057   const cmt_string& get_name (CmtError::code error) const
00058       {
00059         const cmt_string& s = error_names[error];
00060 
00061         return (s);
00062       }
00063 
00064 private:
00065   CmtError::code m_code;
00066   cmt_string m_text;
00067   cmt_vector<cmt_string> error_names;
00068 };
00069 
00070 //---------------------------------------------------------------
00071 Error& Error::instance ()
00072 //---------------------------------------------------------------
00073 {
00074   static Error e;
00075   
00076   return (e);
00077 }
00078 
00079 //---------------------------------------------------------------
00080 void CmtError::clear ()
00081 //---------------------------------------------------------------
00082 {
00083   Error& e = Error::instance ();
00084 
00085   e.clear ();
00086 }
00087 
00088 //---------------------------------------------------------------
00089 bool CmtError::has_pending_error ()
00090 //---------------------------------------------------------------
00091 {
00092   Error& e = Error::instance ();
00093 
00094   if (e.get_code () == ok) return (false);
00095   else return (true);
00096 }
00097 
00098 //---------------------------------------------------------------
00099 CmtError::code CmtError::get_last_error_code ()
00100 //---------------------------------------------------------------
00101 {
00102   Error& e = Error::instance ();
00103 
00104   return (e.get_code ());
00105 }
00106 
00107 //---------------------------------------------------------------
00108 const cmt_string& CmtError::get_error_name (code error)
00109 //---------------------------------------------------------------
00110 {
00111   Error& e = Error::instance ();
00112 
00113   return (e.get_name (error));
00114 }
00115 
00116 //---------------------------------------------------------------
00117 void CmtError::set (code error, const cmt_string& text)
00118 //---------------------------------------------------------------
00119 {
00120   Error& e = Error::instance ();
00121 
00122   e.set (error, text);
00123 }
00124 
00125 //---------------------------------------------------------------
00126 cmt_string CmtError::get_last_error ()
00127 {
00128   Error& e = Error::instance ();
00129 
00130   cmt_string result;
00131 
00132   result = get_error_name (e.get_code ());
00133   result += " - ";
00134   result += e.get_text ();
00135 
00136   return (result);
00137 }
00138 
00139 //---------------------------------------------------------------
00140 void CmtError::print ()
00141 //---------------------------------------------------------------
00142 {
00143   Error& e = Error::instance ();
00144 
00145   cout << endl;
00146   cout << "# CMT> " << get_error_name (e.get_code ()) << " - " << e.get_text () << endl;
00147 }
00148 

Generated at Thu May 16 16:27:05 2002 for CMT by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000