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

termreason.h

Go to the documentation of this file.
00001 // Termination Reason Class -*- C++ -*-
00002 
00003 // Copyright (C) 2001-2003 Hermann Schichl
00004 //
00005 // This file is part of the COCONUT API.  This library
00006 // is free software; you can redistribute it and/or modify it under the
00007 // terms of the Library GNU General Public License as published by the
00008 // Free Software Foundation; either version 2, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // Library GNU General Public License for more details.
00015 
00016 // As a special exception, you may use this file as part of a free software
00017 // library without restriction.  Specifically, if other files instantiate
00018 // templates or use macros or inline functions from this file, or you compile
00019 // this file and link it with other files to produce an executable, this
00020 // file does not by itself cause the resulting executable to be covered by
00021 // the Library GNU General Public License.  This exception does not however
00022 // invalidate any other reasons why the executable file might be covered by
00023 // the Library GNU General Public License.
00024 
00027 #ifndef _TERMREASON_H_
00028 #define _TERMREASON_H_
00029 
00030 #include <string>
00031 #include <map>
00032 
00033 // this map can be used during the registration phase for
00034 // producing highly descriptive termr messages or translations
00035 extern std::map<std::string,std::string> __termr_message__;
00036 
00037 class termination_reason
00038 {
00039 private:
00040   std::string termr_string;
00041   int termr_code;
00042   std::map<std::string,std::string>& termr_message;
00043   
00044 public:
00045   termination_reason() : termr_string(std::string("SUCCESS")), termr_code(0),
00046         termr_message(__termr_message__) {}
00047   
00048   termination_reason(int termr_r, const std::string& termr_ref)
00049         : termr_string(termr_ref), termr_code(termr_r),
00050           termr_message(__termr_message__) {}
00051   
00052   termination_reason(const termination_reason& __t)
00053         : termr_string(__t.termr_string), termr_code(__t.termr_code),
00054           termr_message(__t.termr_message) {}
00055 
00056   termination_reason& operator=(const termination_reason& __t)
00057   {
00058     termr_string = __t.termr_string;
00059     termr_code = __t.termr_code;
00060     termr_message = __t.termr_message;
00061     return *this;
00062   }
00063   
00064   const std::string& get_message() const
00065   {
00066     std::map<std::string,std::string>::const_iterator __i;
00067     __i = termr_message.find(termr_string);
00068     if(__i == termr_message.end())
00069       return termr_string;
00070     else
00071       return (*__i).second;
00072   }
00073 
00074   int get_code() const { return termr_code; }
00075 
00076   friend std::ostream& operator<< (std::ostream& o, const termination_reason& __x);
00077 };
00078 
00079 inline std::ostream& operator<< (std::ostream& o, const termination_reason& __x)
00080 {
00081   return o << __x.get_message();
00082 }
00083 
00084 #endif /* _TERMREASON_H_*/

Generated on Tue Nov 4 01:57:59 2003 for COCONUT API by doxygen1.2.18