GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 85.7% 6 / 0 / 7
Functions: 100.0% 2 / 0 / 2
Branches: 52.6% 10 / 0 / 19

src/utilities/core/DeprecatedHelpers.hpp
Line Branch Exec Source
1 /***********************************************************************************************************************
2 * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC.
3 * See also https://openstudio.net/license
4 ***********************************************************************************************************************/
5
6 #ifndef UTILITIES_CORE_DEPRECATEDHELPERS_HPP
7 #define UTILITIES_CORE_DEPRECATEDHELPERS_HPP
8
9 #include "Compare.hpp"
10 #include "Exception.hpp"
11 #include "Logger.hpp"
12
13 #include <OpenStudio.hxx>
14
15 #include <boost/current_function.hpp>
16 #include <fmt/core.h>
17 #include <fmt/compile.h>
18
19 #include <string>
20
21 namespace openstudio {
22
23 struct cx_VersionString
24 {
25 constexpr cx_VersionString(int t_major, int t_minor, int t_patch) : major(t_major), minor(t_minor), patch(t_patch) {}
26
27 constexpr cx_VersionString() = default;
28
29 constexpr bool isGreaterThan(const cx_VersionString& other, int numMinors = 3) const {
30 return (major > other.major) || (minor >= other.minor + numMinors);
31 }
32
33 270 std::string str() const {
34 540 return fmt::format("{}.{}.{}", major, minor, patch);
35 }
36
37 int major = openstudio::detail::cx_openStudioVersionMajor();
38 int minor = openstudio::detail::cx_openStudioVersionMinor();
39 int patch = openstudio::detail::cx_openStudioVersionPatch();
40 };
41
42 // static inline constexpr cx_VersionString cx_currentVersion{};
43
44 namespace detail {
45 270 inline void log_deprecation_and_throw_if_time_to_remove(const std::string& deprecatedAt, const std::string& logChannel,
46 const std::string& methodName, const std::string& extraMessage = "") {
47
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 270 times.
270 if (extraMessage.empty()) {
48 ✗ LOG_FREE(Warn, logChannel, "As of " << deprecatedAt << ", " << methodName << " is deprecated.");
49 } else {
50
9/9
✓ Branch 1 taken 270 times.
✓ Branch 4 taken 270 times.
✓ Branch 7 taken 270 times.
✓ Branch 10 taken 270 times.
✓ Branch 13 taken 270 times.
✓ Branch 16 taken 270 times.
✓ Branch 19 taken 270 times.
✓ Branch 22 taken 270 times.
✓ Branch 25 taken 270 times.
270 LOG_FREE(Warn, logChannel, "As of " << deprecatedAt << ", " << methodName << " is deprecated. " << extraMessage);
51 }
52 270 }
53 } // namespace detail
54 } // namespace openstudio
55
56 #define DEPRECATED_AT(__deprecatedAtVersionMajor__, __deprecatedAtVersionMinor__, __deprecatedAtVersionPatch__) \
57 DEPRECATED_AT_MSG(__deprecatedAtVersionMajor__, __deprecatedAtVersionMinor__, __deprecatedAtVersionPatch__, "")
58
59 #define DEPRECATED_AT_MSG(__deprecatedAtVersionMajor__, __deprecatedAtVersionMinor__, __deprecatedAtVersionPatch__, __message__) \
60 constexpr openstudio::cx_VersionString deprecatedAt(__deprecatedAtVersionMajor__, __deprecatedAtVersionMinor__, __deprecatedAtVersionPatch__); \
61 static_assert(true || !openstudio::cx_VersionString{}.isGreaterThan(deprecatedAt), \
62 "Time to remove, deprecated at " #__deprecatedAtVersionMajor__ "." #__deprecatedAtVersionMinor__ "." #__deprecatedAtVersionPatch__); \
63 openstudio::detail::log_deprecation_and_throw_if_time_to_remove(deprecatedAt.str(), logChannel(), BOOST_CURRENT_FUNCTION, __message__)
64
65 #endif // UTILITIES_CORE_DEPRECATEDHELPERS_HPP
66