diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-27 15:37:47 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-27 15:37:47 +0100 |
commit | 3334e1ba2417fb726f52963270f1367fac45265c (patch) | |
tree | 5f85f35610e140d984f4cd5df780a5e7b4469c31 /src | |
parent | 13393c5e1e3261176d9b750cc10b9c62b740f08c (diff) |
Adapted LoggableException to use the same code for obtaining the location of an object reference or pointer as the Logger class
Diffstat (limited to 'src')
-rw-r--r-- | src/core/common/Exceptions.hpp | 31 | ||||
-rw-r--r-- | src/core/common/Location.hpp | 26 | ||||
-rw-r--r-- | src/core/common/Logger.hpp | 34 |
3 files changed, 33 insertions, 58 deletions
diff --git a/src/core/common/Exceptions.hpp b/src/core/common/Exceptions.hpp index 0be33b3..b63c32a 100644 --- a/src/core/common/Exceptions.hpp +++ b/src/core/common/Exceptions.hpp @@ -103,40 +103,14 @@ public: } /** - * Constructor of the LoggableException class. - * - * @param msg contains the error message. - * @param line is the line in the above file the message refers to. - * @param column is the column in the above file the message refers to. - * @param offs is the byte offset. - */ - LoggableException(std::string msg, int line, - int column, size_t offs) - : LoggableException(msg, SourceLocation(line, column, offs)) - { - } - - /** * Constructor of LoggableException for arbitrary position objects. * * @param msg is the actual log message. * @param loc is a reference to a variable with location data. */ template <class LocationType> - LoggableException(std::string msg, const LocationType &loc) - : LoggableException(std::move(msg), loc.getLocation()) - { - } - - /** - * Constructor of LoggableException for arbitrary position objects. - * - * @param msg is the actual log message. - * @param loc is a pointe to a variable with location data. - */ - template <class LocationType> - LoggableException(std::string msg, const LocationType *loc) - : LoggableException(std::move(msg), loc->getLocation()) + LoggableException(std::string msg, LocationType loc) + : LoggableException(std::move(msg), SourceLocation::location(loc)) { } @@ -147,6 +121,7 @@ public: */ const SourceLocation& getLocation() const { return loc; } }; + } #endif /* _OUSIA_EXCEPTIONS_HPP_ */ diff --git a/src/core/common/Location.hpp b/src/core/common/Location.hpp index 4b70619..93e5d8e 100644 --- a/src/core/common/Location.hpp +++ b/src/core/common/Location.hpp @@ -345,6 +345,32 @@ public: { return SourceRange::isValid() && sourceId != InvalidSourceId; } + + /** + * Calls the getLocation function on the given reference. + * + * @param obj is the object on which the getLocation function should be + * called. + * @return the SourceLocation returned by the getLocation function. + */ + template <typename T> + static SourceLocation location(const T &obj) + { + return obj.getLocation(); + } + + /** + * Calls the getLocation function on the given pointer. + * + * @param obj is the object on which the getLocation function should be + * called. + * @return the SourceLocation returned by the getLocation function. + */ + template <typename T> + static SourceLocation location(const T *obj) + { + return obj->getLocation(); + } }; /** diff --git a/src/core/common/Logger.hpp b/src/core/common/Logger.hpp index 433aa31..ae06d08 100644 --- a/src/core/common/Logger.hpp +++ b/src/core/common/Logger.hpp @@ -181,32 +181,6 @@ public: } }; - /** - * Calls the getLocation function on the given reference. - * - * @param obj is the object on which the getLocation function should be - * called. - * @return the SourceLocation returned by the getLocation function. - */ - template <typename T> - static SourceLocation location(const T &obj) - { - return obj.getLocation(); - } - - /** - * Calls the getLocation function on the given pointer. - * - * @param obj is the object on which the getLocation function should be - * called. - * @return the SourceLocation returned by the getLocation function. - */ - template <typename T> - static SourceLocation location(const T *obj) - { - return obj->getLocation(); - } - protected: /** * Function to be overriden by child classes to actually display or store @@ -311,7 +285,7 @@ public: void log(Severity severity, const std::string &msg, LocationType loc, MessageMode mode = MessageMode::DEFAULT) { - log(severity, msg, location(loc), mode); + log(severity, msg, SourceLocation::location(loc), mode); } /** @@ -398,7 +372,7 @@ public: void warning(const std::string &msg, LocationType loc, MessageMode mode = MessageMode::DEFAULT) { - log(Severity::WARNING, msg, location(loc), mode); + log(Severity::WARNING, msg, SourceLocation::location(loc), mode); } /** @@ -425,7 +399,7 @@ public: void error(const std::string &msg, LocationType loc, MessageMode mode = MessageMode::DEFAULT) { - log(Severity::ERROR, msg, location(loc), mode); + log(Severity::ERROR, msg, SourceLocation::location(loc), mode); } /** @@ -452,7 +426,7 @@ public: void fatalError(const std::string &msg, LocationType loc, MessageMode mode = MessageMode::DEFAULT) { - log(Severity::FATAL_ERROR, msg, location(loc), mode); + log(Severity::FATAL_ERROR, msg, SourceLocation::location(loc), mode); } /** |