Commit 4b57215e authored by thomas.forbriger's avatar thomas.forbriger
Browse files

libdatrwxx [WP]: use string containers in exceptions

parent e5825362
......@@ -27,15 +27,17 @@
* Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 30/03/2004 V1.0 Thomas Forbriger
* - 30/03/2004 V1.0 Thomas Forbriger (thof)
* - 07/07/2006 V1.1 added report function
* - 06/09/2011 V1.2 introduced report_deprecated
* - 10/06/2015 V1.3 update repository URL in report_deprecated
* - 05/07/2016 V1.4 thof: operate with string containers rather than
* with pointer to character arrays
*
* ============================================================================
*/
#define DATRW_ERROR_CC_VERSION \
"DATRW_ERROR_CC V1.3"
"DATRW_ERROR_CC V1.4"
#include <iostream>
#include <datrwxx/error.h>
......@@ -54,28 +56,28 @@ namespace datrw {
{ if (Mreport_on_construct) { report(); } }
//! construct with message
Exception::Exception(const char* message):
Exception::Exception(const std::string& message):
Mmessage(message), Mfile(0), Mline(0), Mcondition(0)
{ if (Mreport_on_construct) { report(); } }
//! construct with message and file info
Exception::Exception(const char* message,
const char* condition):
Exception::Exception(const std::string& message,
const std::string& condition):
Mmessage(message), Mfile(0), Mline(0), Mcondition(condition)
{ if (Mreport_on_construct) { report(); } }
//! construct with message and file info
Exception::Exception(const char* message,
const char* file,
Exception::Exception(const std::string& message,
const std::string& file,
const int& line):
Mmessage(message), Mfile(file), Mline(line), Mcondition(0)
{ if (Mreport_on_construct) { report(); } }
//! construct with message and file info and condition
Exception::Exception(const char* message,
const char* file,
Exception::Exception(const std::string& message,
const std::string& file,
const int& line,
const char* condition):
const std::string& condition):
Mmessage(message), Mfile(file), Mline(line), Mcondition(condition)
{ if (Mreport_on_construct) { report(); } }
......@@ -101,7 +103,7 @@ namespace datrw {
void Exception::base_report() const
{
cerr << "Exception report:" << endl;
if (Mmessage==0)
if (Mmessage.empty())
{
cerr << " No message" << endl;
}
......@@ -109,11 +111,11 @@ namespace datrw {
{
cerr << " message: " << Mmessage << endl;
}
if (Mfile!=0)
if (!Mfile.empty())
{
cerr << " triggered in \"" << Mfile << "\" at line #" << Mline << endl;
}
if (Mcondition!=0)
if (!Mcondition.empty())
{
cerr << " by violation of condition:" << endl
<< " \"" << Mcondition << "\"" << endl;
......@@ -123,10 +125,10 @@ namespace datrw {
/*----------------------------------------------------------------------*/
//! report violation of assertion
void report_violation(const char* message,
const char* file,
void report_violation(const std::string& message,
const std::string& file,
const int& line,
const char* condition)
const std::string& condition)
{
std::cerr << std::endl;
std::cerr << "VIOLATION of condition: " << condition << std::endl;
......@@ -137,14 +139,14 @@ namespace datrw {
/*----------------------------------------------------------------------*/
//! report deprecated function
void report_deprecated(const char* function,
const char* reason)
void report_deprecated(const std::string& function,
const std::string& reason)
{
std::cerr << "WARNING: program uses deprecated function in libdatrwxx\n"
<< "* " << function << std::endl;
std::cerr << "* This function should no longer be used because\n"
<< "* " << reason << std::endl;
std::cerr << "* Please place a ticket at "
std::cerr << "* Please open an issue at "
"http://git.scc.kit.edu/Seitosh/Seitosh"
<< std::endl;
}
......
......@@ -33,6 +33,8 @@
* - 06/09/2011 V1.3 introduced report_deprecated
* - 22/07/2014 V1.4 thof: report comments prior to throwing exception
* provide warning macro
* - 05/07/2016 V1.5 thof: operate with string containers rather than
* with pointer to character arrays
*
* ============================================================================
*/
......@@ -41,9 +43,10 @@
#ifndef DATRW_ERROR_H_VERSION
#define DATRW_ERROR_H_VERSION \
"DATRW_ERROR_H V1.4"
"DATRW_ERROR_H V1.5"
#include <iostream>
#include <string>
namespace datrw {
......@@ -71,18 +74,18 @@ namespace datrw {
//! Creates exception with no explaning comments
Exception();
//! Creates an exception with an explanation message
Exception(const char* message);
Exception(const std::string& message);
//! Creates an exception with message and failed assertion
Exception(const char* message,
const char* condition);
Exception(const std::string& message,
const std::string& condition);
//! Create with message, failed assertion, and code position
Exception(const char* message,
const char* file,
Exception(const std::string& message,
const std::string& file,
const int& line,
const char* condition);
const std::string& condition);
//! Create with message and code position
Exception(const char* message,
const char* file,
Exception(const std::string& message,
const std::string& file,
const int& line);
//! provide explicit virtual destructor
virtual ~Exception() { }
......@@ -104,13 +107,13 @@ namespace datrw {
//! Shall we print to cerr at construction time?
static bool Mreport_on_construct;
//! pointer to message string
const char* Mmessage;
std::string Mmessage;
//! pointer to file name string
const char* Mfile;
std::string Mfile;
//! pointer to line number in source file
const int& Mline;
//! pointer to assertion condition text string
const char* Mcondition;
std::string Mcondition;
}; // class Exception
/*! \brief report violation of condition
......@@ -121,10 +124,10 @@ namespace datrw {
* \param line source code line number
* \param condition assert condition
*/
void report_violation(const char* message,
const char* file,
void report_violation(const std::string& message,
const std::string& file,
const int& line,
const char* condition);
const std::string& condition);
/*! \brief report deprecation of a function
*
......@@ -133,8 +136,8 @@ namespace datrw {
* \param reason the reason for deprecating the function
* should finish a sentence which started with "because"
*/
void report_deprecated(const char* function,
const char* reason);
void report_deprecated(const std::string& function,
const std::string& reason);
} // namespace datrw
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment