X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fstructure%2Fexception.cxx;h=cac9cc950e515e68ab57e1563084d1c9727743ec;hb=5c9f5361bda56dddad8068d8e45dc08584440d70;hp=c46a1c9636c25aac25b40dfca32469cf27385fd7;hpb=76948416a9624ba269d2baeac294c6db0853f104;p=simgear.git diff --git a/simgear/structure/exception.cxx b/simgear/structure/exception.cxx index c46a1c96..cac9cc95 100644 --- a/simgear/structure/exception.cxx +++ b/simgear/structure/exception.cxx @@ -6,12 +6,13 @@ #include "exception.hxx" + #include #include #include -using std::string; - +#include + //////////////////////////////////////////////////////////////////////// // Implementation of sg_location class. //////////////////////////////////////////////////////////////////////// @@ -24,7 +25,7 @@ sg_location::sg_location () _path[0] = '\0'; } -sg_location::sg_location (const string& path, int line, int column) +sg_location::sg_location (const std::string& path, int line, int column) : _line(line), _column(column), _byte(-1) @@ -54,8 +55,8 @@ void sg_location::setPath (const char* path) { if (path) { - strncpy(_path, path, MAX_PATH); - _path[MAX_PATH -1] = '\0'; + strncpy(_path, path, max_path); + _path[max_path -1] = '\0'; } else { _path[0] = '\0'; } @@ -97,7 +98,7 @@ sg_location::setByte (int byte) _byte = byte; } -string +std::string sg_location::asString () const { std::ostringstream out; @@ -145,10 +146,10 @@ sg_throwable::getMessage () const return _message; } -const string +const std::string sg_throwable::getFormattedMessage () const { - return string(getMessage()); + return std::string(getMessage()); } void @@ -201,7 +202,7 @@ sg_error::sg_error (const char* message, const char *origin) { } -sg_error::sg_error (const string& message, const string& origin) +sg_error::sg_error(const std::string& message, const std::string& origin) : sg_throwable(message.c_str(), origin.c_str()) { } @@ -209,7 +210,7 @@ sg_error::sg_error (const string& message, const string& origin) sg_error::~sg_error () throw () { } - + //////////////////////////////////////////////////////////////////////// // Implementation of sg_exception class. //////////////////////////////////////////////////////////////////////// @@ -224,7 +225,8 @@ sg_exception::sg_exception (const char* message, const char* origin) { } -sg_exception::sg_exception (const string& message, const string& origin) +sg_exception::sg_exception( const std::string& message, + const std::string& origin ) : sg_throwable(message.c_str(), origin.c_str()) { } @@ -232,7 +234,7 @@ sg_exception::sg_exception (const string& message, const string& origin) sg_exception::~sg_exception () throw () { } - + //////////////////////////////////////////////////////////////////////// // Implementation of sg_io_exception. //////////////////////////////////////////////////////////////////////// @@ -255,20 +257,36 @@ sg_io_exception::sg_io_exception (const char* message, { } -sg_io_exception::sg_io_exception (const string& message, const string& origin) +sg_io_exception::sg_io_exception( const std::string& message, + const std::string& origin ) : sg_exception(message, origin) { } +sg_io_exception::sg_io_exception( const std::string& message, + const sg_location &location, + const std::string& origin ) + : sg_exception(message, origin), + _location(location) +{ +} + +sg_io_exception::sg_io_exception( const std::string &message, + const SGPath& origin ) + : sg_exception(message, origin.str()) +{ + +} + sg_io_exception::~sg_io_exception () throw () { } -const string +const std::string sg_io_exception::getFormattedMessage () const { - string ret = getMessage(); - string loc = getLocation().asString(); + std::string ret = getMessage(); + std::string loc = getLocation().asString(); if (loc.length()) { ret += "\n at "; ret += loc; @@ -308,9 +326,9 @@ sg_format_exception::sg_format_exception (const char* message, setText(text); } -sg_format_exception::sg_format_exception (const string& message, - const string& text, - const string& origin) +sg_format_exception::sg_format_exception( const std::string& message, + const std::string& text, + const std::string& origin ) : sg_exception(message, origin) { setText(text.c_str()); @@ -331,7 +349,7 @@ sg_format_exception::setText (const char* text) { if (text) { strncpy(_text, text, MAX_TEXT_LEN); - _text[MAX_TEXT_LEN] = '\0'; + _text[MAX_TEXT_LEN-1] = '\0'; } else { _text[0] = '\0'; } @@ -354,8 +372,8 @@ sg_range_exception::sg_range_exception (const char* message, { } -sg_range_exception::sg_range_exception(const string& message, - const string& origin) +sg_range_exception::sg_range_exception(const std::string& message, + const std::string& origin) : sg_exception(message, origin) { }