XMLIOSERVER 0.4
Serveur d'Entrées/Sorties parallèles
exception.cpp
Aller à la documentation de ce fichier.
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 
00023 // /////////////////////////////// Définitions ////////////////////////////// //
00024 
00025 namespace xmlioserver {
00026 
00027    // ------------------------------ Constructeurs -----------------------------
00028 
00029    // Constructeur simple d'une exception anonyme.
00030    CException::CException(void)
00031       : CObject(), desc_rethrow(true)
00032    { /* Ne rien faire de plus */ }
00033 
00034    // Constructeur simple d'une exception identifiée.
00035    CException::CException(const std::string & _id)
00036       : CObject(_id), desc_rethrow(true)
00037    { /* Ne rien faire de plus */ }
00038 
00039    // Constructeur par copie.
00040    CException::CException(const CException & _exception)
00041       : std::basic_ios<char>()
00042       , CObject(_exception.getId())
00043       , std::ostringstream()
00044       , desc_rethrow(false)
00045    {
00046       (*this) << _exception.str();
00047    }
00048 
00049    // ------------------------------- Destructeur -----------------------------
00050 
00051    // Destructeur de l'instance.
00052    CException::~CException(void)
00053    {
00054       if (this->desc_rethrow) throw (*this);
00055    }
00056 
00057    // ------------------------------- Accesseurs ------------------------------
00058 
00059    // Retourne un message d'erreur.
00060    const std::string CException::getMessage(void) const
00061    {
00062       std::ostringstream oss;
00063       oss << "> Error [" << this->getId() << "] : " << this->str();
00064       return (oss.str());
00065    }
00066 
00067    // Retourne un flux d'écriture du message d'erreur.
00068    std::ostringstream &  CException::getStream(void)
00069    {
00070       return (*boost::polymorphic_cast<std::ostringstream*>(this));
00071    }
00072 
00073    // --------------------------- Diverses méthodes ---------------------------
00074 
00075    // Retourne une représentation ascii de l'objet.
00076    std::string CException::toString(void) const
00077    {
00078       return (std::string(this->getMessage()));
00079    }
00080 
00081    // Modifie l'objet en fonction d'une chaîne de caractère.
00082    void CException::fromString(const std::string & str)
00083    {
00084       this->str(str);
00085    }
00086 
00087 } // namespace xmlioserver
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Définition de type Énumérations Valeurs énumérées Amis Macros