00001 // Termination Reason Class -*- C++ -*- 00002 00003 // $Id: termreason.h 347 2008-02-06 15:20:01Z schilly $ 00004 // Copyright (C) 2001-2003 Hermann Schichl 00005 // 00006 // This file is part of the COCONUT API. This library 00007 // is free software; you can redistribute it and/or modify it under the 00008 // terms of the Library GNU General Public License as published by the 00009 // Free Software Foundation; either version 2, or (at your option) 00010 // any later version. 00011 00012 // This library is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // Library GNU General Public License for more details. 00016 00017 // As a special exception, you may use this file as part of a free software 00018 // library without restriction. Specifically, if other files instantiate 00019 // templates or use macros or inline functions from this file, or you compile 00020 // this file and link it with other files to produce an executable, this 00021 // file does not by itself cause the resulting executable to be covered by 00022 // the Library GNU General Public License. This exception does not however 00023 // invalidate any other reasons why the executable file might be covered by 00024 // the Library GNU General Public License. 00025 00028 #ifndef _TERMREASON_H_ 00029 #define _TERMREASON_H_ 00030 00031 #include <string> 00032 #include <map> 00033 00034 namespace coco { 00035 00036 const std::string& get_translated_message(const std::string& msg); 00037 void set_translation_map(const std::map<std::string,std::string>& tr_msg_map); 00038 00040 00045 class termination_reason 00046 { 00047 private: 00049 std::string termr_string; 00053 int termr_code; 00056 public: 00058 termination_reason() : termr_string(std::string("SUCCESS")), termr_code(0) {} 00059 00062 termination_reason(int termr_r, const std::string& termr_ref) 00063 : termr_string(termr_ref), termr_code(termr_r) {} 00064 00066 termination_reason(const termination_reason& __t) 00067 : termr_string(__t.termr_string), termr_code(__t.termr_code) {} 00068 00070 termination_reason& operator=(const termination_reason& __t) 00071 { 00072 termr_string = __t.termr_string; 00073 termr_code = __t.termr_code; 00074 return *this; 00075 } 00076 00078 const std::string& get_message() const { return get_translated_message(termr_string); } 00079 00081 int get_code() const { return termr_code; } 00082 00083 friend std::ostream& operator<< (std::ostream& o, const termination_reason& __x); 00084 }; 00085 00087 00090 inline std::ostream& operator<< (std::ostream& o, const termination_reason& __x) 00091 { 00092 return o << __x.get_message(); 00093 } 00094 00095 } // namespace coco 00096 00097 #endif /* _TERMREASON_H_*/