Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

cmt_error.cxx

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

Generated on Mon May 2 10:25:04 2005 for CMT by doxygen 1.3.5