From: Martin Quinson Date: Sat, 25 Aug 2018 09:07:11 +0000 (+0200) Subject: Merge the content of xbt/exception.hpp into simgrid/Exception.hpp X-Git-Tag: v3_21~178 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/29379a85ce9802fd3174f4237b57d240a704cb45 Merge the content of xbt/exception.hpp into simgrid/Exception.hpp --- diff --git a/include/simgrid/Exception.hpp b/include/simgrid/Exception.hpp index 66c12def16..37acd8ff53 100644 --- a/include/simgrid/Exception.hpp +++ b/include/simgrid/Exception.hpp @@ -13,11 +13,79 @@ #include #include -#include +#include +#include +#include +#include +#include +#include #include +#include +#include // xbt_procname +#include // xbt_getpid namespace simgrid { +namespace xbt { + +/** The location of where an exception has been thrown + * + * This is a tuple (__FILE__, __LINE__, __func__), created with @ref XBT_THROW_POINT. + * + * @ingroup XBT_ex + */ +class ThrowPoint { +public: + ThrowPoint() = default; + explicit ThrowPoint(const char* file, int line, const char* function) : file_(file), line_(line), function_(function) + { + } + const char* file_ = nullptr; + int line_ = 0; + const char* function_ = nullptr; +}; + +/** Create a ThrowPoint with (__FILE__, __LINE__, __func__) */ +#define XBT_THROW_POINT ::simgrid::xbt::ThrowPoint(__FILE__, __LINE__, __func__) + +/** A base class for exceptions with context + * + * This is a base class for exceptions which store additional contextual + * information: backtrace, throw point, simulated process name, PID, etc. + */ +class XBT_PUBLIC ContextedException { +public: + ContextedException() : backtrace_(simgrid::xbt::backtrace()), procname_(xbt_procname()), pid_(xbt_getpid()) {} + explicit ContextedException(Backtrace bt) : backtrace_(std::move(bt)), procname_(xbt_procname()), pid_(xbt_getpid()) + { + } + explicit ContextedException(ThrowPoint throwpoint, Backtrace bt) + : backtrace_(std::move(bt)), procname_(xbt_procname()), pid_(xbt_getpid()), throwpoint_(throwpoint) + { + } + virtual ~ContextedException(); + Backtrace const& backtrace() const { return backtrace_; } + int pid() const { return pid_; } + std::string const& process_name() const { return procname_; } + ThrowPoint& throw_point() { return throwpoint_; } + + // deprecated + XBT_ATTRIB_DEPRECATED_v323("Please use WithContextException::process_name()") std::string const& processName() const + { + return process_name(); + } + XBT_ATTRIB_DEPRECATED_v323("Please use WithContextException::throw_point()") ThrowPoint& throwPoint() + { + return throw_point(); + } + +private: + Backtrace backtrace_; + std::string procname_; /**< Name of the process who thrown this */ + int pid_; /**< PID of the process who thrown this */ + ThrowPoint throwpoint_; +}; +} // namespace xbt /** Ancestor class of all SimGrid exception */ class Exception : public std::runtime_error { diff --git a/include/xbt/exception.hpp b/include/xbt/exception.hpp deleted file mode 100644 index 4036734664..0000000000 --- a/include/xbt/exception.hpp +++ /dev/null @@ -1,93 +0,0 @@ -/* Copyright (c) 2005-2018. The SimGrid Team.All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#ifndef SIMGRID_XBT_EXCEPTION_HPP -#define SIMGRID_XBT_EXCEPTION_HPP - -#include -#include -#include - -#include -#include -#include -#include -#include // xbt_procname -#include // xbt_getpid - -/** @addtogroup XBT_ex - * @brief Exceptions support - */ - -namespace simgrid { -namespace xbt { - -/** The location of where an exception has been thrown - * - * This is a tuple (__FILE__, __LINE__, __func__) and can be created with - * @ref XBT_THROW_POINT. - * - * @ingroup XBT_ex - */ -class ThrowPoint { - public: - ThrowPoint() = default; - explicit ThrowPoint(const char* file, int line, const char* function) : file_(file), line_(line), function_(function) - { - } - const char* file_ = nullptr; - int line_ = 0; - const char* function_ = nullptr; -}; - -/** Create a ThrowPoint with (__FILE__, __LINE__, __func__) */ -#define XBT_THROW_POINT ::simgrid::xbt::ThrowPoint(__FILE__, __LINE__, __func__) - -/** A base class for exceptions with context - * - * This is a base class for exceptions which store additional contextual - * information: backtrace, throw point, simulated process name, PID, etc. - */ -class XBT_PUBLIC ContextedException { -public: - ContextedException() : - backtrace_(simgrid::xbt::backtrace()), - procname_(xbt_procname()), - pid_(xbt_getpid()) - {} - explicit ContextedException(Backtrace bt) : backtrace_(std::move(bt)), procname_(xbt_procname()), pid_(xbt_getpid()) - {} - explicit ContextedException(ThrowPoint throwpoint, Backtrace bt) - : backtrace_(std::move(bt)), procname_(xbt_procname()), pid_(xbt_getpid()), throwpoint_(throwpoint) - {} - virtual ~ContextedException(); - Backtrace const& backtrace() const - { - return backtrace_; - } - int pid() const { return pid_; } - std::string const& process_name() const { return procname_; } - ThrowPoint& throw_point() { return throwpoint_; } - - // deprecated - XBT_ATTRIB_DEPRECATED_v323("Please use WithContextException::process_name()") std::string const& processName() const - { - return process_name(); - } - XBT_ATTRIB_DEPRECATED_v323("Please use WithContextException::throw_point()") ThrowPoint& throwPoint() - { - return throw_point(); - } - -private: - Backtrace backtrace_; - std::string procname_; /**< Name of the process who thrown this */ - int pid_; /**< PID of the process who thrown this */ - ThrowPoint throwpoint_; -}; -} -} - -#endif diff --git a/include/xbt/log.hpp b/include/xbt/log.hpp index 083ce2dd7a..4aaff8a26a 100644 --- a/include/xbt/log.hpp +++ b/include/xbt/log.hpp @@ -3,8 +3,8 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#include #include -#include namespace simgrid { namespace xbt { diff --git a/src/s4u/s4u_Barrier.cpp b/src/s4u/s4u_Barrier.cpp index b0c21215af..d19fb26337 100644 --- a/src/s4u/s4u_Barrier.cpp +++ b/src/s4u/s4u_Barrier.cpp @@ -6,12 +6,11 @@ #include #include -#include -#include - +#include "simgrid/Exception.hpp" #include "simgrid/barrier.h" #include "simgrid/s4u/Barrier.hpp" #include "simgrid/simix.h" +#include "xbt/log.hpp" XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_barrier, "S4U barrier"); diff --git a/src/s4u/s4u_ConditionVariable.cpp b/src/s4u/s4u_ConditionVariable.cpp index 7707e66011..4d053aed3f 100644 --- a/src/s4u/s4u_ConditionVariable.cpp +++ b/src/s4u/s4u_ConditionVariable.cpp @@ -3,15 +3,13 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include -#include - -#include -#include - #include "simgrid/s4u/ConditionVariable.hpp" #include "simgrid/simix.h" #include "src/kernel/activity/ConditionVariableImpl.hpp" +#include "xbt/log.hpp" + +#include +#include namespace simgrid { namespace s4u {