wml_exception.cpp

Go to the documentation of this file.
00001 /* $Id: wml_exception.cpp 26690 2008-05-18 13:47:04Z mordante $ */
00002 /*
00003    Copyright (C) 2007 - 2008 by Mark de Wever <koraq@xs4all.nl>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License version 2
00008    or at your option any later version.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 
00015 /**
00016  *  @file wml_exception.cpp
00017  *  Implementation for wml_exception.hpp.
00018  */
00019 
00020 #include "global.hpp"
00021 #include "wml_exception.hpp"
00022 
00023 #include "display.hpp"
00024 #include "gettext.hpp"
00025 #include "show_dialog.hpp"
00026 
00027 #include <cassert>
00028 #include <sstream>
00029 
00030 void wml_exception(const char* cond, const char* file, 
00031     const int line, const char* function, const t_string& message)
00032 {
00033     std::stringstream sstr;
00034     sstr << "Condition '" << cond << "' failed at " 
00035         << file << ":" << line << " in function '" << function << "'.";
00036     
00037     throw twml_exception(message, sstr.str());
00038 }
00039 
00040 twml_exception::twml_exception(const t_string& user_msg, const std::string& dev_msg) :
00041     user_message(user_msg),
00042     dev_message(dev_msg)
00043 {
00044 }
00045 
00046 void twml_exception::show(display &disp)
00047 {
00048     std::stringstream sstr;
00049 
00050     // The extra spaces between the \n are needed, otherwise the dialog doesn't show
00051     // an empty line.
00052     sstr << _("An error due to possible invalid WML occured\nThe error message is :")
00053         << "\n" << user_message << "\n \n" 
00054         << _("When reporting the bug please include the following error message :")
00055         << "\n" << dev_message;
00056 
00057     gui::show_error_message(disp, sstr.str());
00058 }
00059 
00060 t_string missing_mandatory_wml_key(const std::string& section, const std::string& key,
00061         const std::string& primary_key, const std::string& primary_value)
00062 {
00063     utils::string_map symbols;
00064     symbols["section"] = section;
00065     symbols["key"] = key;
00066     if(!primary_key.empty()) {
00067         assert(!primary_value.empty());
00068 
00069         symbols["primary_key"] = primary_key;
00070         symbols["primary_value"] = primary_value;
00071 
00072         return t_string(vgettext("In section '[$section|]' where '$primary_key| = "
00073             "$primary_value' the mandatory key '$key|' isn't set.", symbols));
00074     } else {
00075         return t_string(vgettext("In section '[$section|]' the "
00076             "mandatory key '$key|' isn't set.", symbols));
00077     }
00078 }

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs