XMLIOSERVER 0.4
Serveur d'Entrées/Sorties parallèles
|
00001 /* ************************************************************************** * 00002 * Copyright © IPSL/LSCE, XMLIOServer, Avril 2010 - Octobre 2011 * 00003 * ************************************************************************** */ 00004 00013 #ifndef __XIOS_NO_EXTERN 00014 00015 // Boost headers 00016 #include <boost/cast.hpp> 00017 00018 #endif // __XIOS_NO_EXTERN 00019 00020 // XMLIOServer headers 00021 #include "xmlioserver_spl.hpp" 00022 #include "exception.hpp" 00023 00024 // /////////////////////////////// Définitions ////////////////////////////// // 00025 00026 namespace xmlioserver { 00027 00028 // ------------------------------ Constructeurs ----------------------------- 00029 00030 // Constructeur simple d'une exception anonyme. 00031 CException::CException(void) 00032 : CObject(), desc_rethrow(true) 00033 { /* Ne rien faire de plus */ } 00034 00035 // Constructeur simple d'une exception identifiée. 00036 CException::CException(const std::string & _id) 00037 : CObject(_id), desc_rethrow(true) 00038 { /* Ne rien faire de plus */ } 00039 00040 // Constructeur par copie. 00041 CException::CException(const CException & _exception) 00042 : std::basic_ios<char>() 00043 , CObject(_exception.getId()) 00044 , std::ostringstream() 00045 , desc_rethrow(false) 00046 { 00047 (*this) << _exception.str(); 00048 } 00049 00050 // ------------------------------- Destructeur ----------------------------- 00051 00052 // Destructeur de l'instance. 00053 CException::~CException(void) 00054 { 00055 if (desc_rethrow) throw (*this); 00056 } 00057 00058 // ------------------------------- Accesseurs ------------------------------ 00059 00060 // Retourne un message d'erreur. 00061 const std::string CException::getMessage(void) const 00062 { 00063 std::ostringstream oss; 00064 oss << "> Error [" << this->getId() << "] : " << this->str(); 00065 return (oss.str()); 00066 } 00067 00068 // Retourne un flux d'écriture du message d'erreur. 00069 std::ostringstream & CException::getStream(void) 00070 { 00071 return (*boost::polymorphic_cast<std::ostringstream*>(this)); 00072 } 00073 00074 // --------------------------- Diverses méthodes --------------------------- 00075 00076 // Retourne une représentation ascii de l'objet. 00077 std::string CException::toString(void) const 00078 { 00079 return (std::string(this->getMessage())); 00080 } 00081 00082 // Modifie l'objet en fonction d'une chaîne de caractère. 00083 void CException::fromString(const std::string & str) 00084 { 00085 this->str(str); 00086 } 00087 00088 } // namespace xmlioserver