00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <iostream>
00012 #include <sstream>
00013 #include <sysexits.h>
00014
00015 #include "ers/Assertion.h"
00016 #include "ers/Issue.h"
00017
00018
00019 namespace {
00020 ers::Issue *create_issue() { return new ers::Assertion(); }
00021 bool registered = ers::IssueFactory::instance()->register_issue(ers::Assertion::CLASS_NAME,create_issue) ;
00022 }
00023
00027 const char * const ers::Assertion::ASSERT_CONDITION_KEY = "ASSERTION_CONDITION" ;
00028 const char * const ers::Assertion::CLASS_NAME = "ers::Assertion" ;
00029 const char * const ers::Assertion::MESSAGE_ELEMENTS[] = { "Assertion '", "' failed: ", " (this condition is constant)" } ;
00030
00034 ers::Assertion::Assertion() : Issue() {}
00035
00039 ers::Assertion::Assertion(const Context &context, severity_t s) : Issue(context,s) {}
00040
00049 ers::Assertion::Assertion(const Context &context, severity_t s, const char* condition_text, const std::string &msg, bool constant_expression) : Issue(context,s) {
00050 setup(condition_text,msg,constant_expression);
00051 }
00052
00056 void ers::Assertion::setup(const char *condition_text, const std::string &msg, bool constant_expression) {
00057 m_value_table[ASSERT_CONDITION_KEY] = *condition_text ;
00058 responsibility(resp_server);
00059 set_value(EXIT_VALUE_KEY,EX_SOFTWARE);
00060 transience( ! constant_expression);
00061 finish_setup(build_message(condition_text,msg,constant_expression));
00062 }
00063
00064 const char* ers::Assertion::get_class_name() const throw (){
00065 return CLASS_NAME ;
00066 }
00067
00076 std::string ers::Assertion::build_message(const char* condition_text, const std::string &msg, bool constant_expression) throw() {
00077 std::ostringstream m ;
00078 m << MESSAGE_ELEMENTS[0] << condition_text << MESSAGE_ELEMENTS[1] << msg ;
00079 if (constant_expression) {
00080 m << MESSAGE_ELEMENTS[2] ;
00081 }
00082 return m.str();
00083 }
00084