From a41e9d6e68281ff33aa34a5ae8d12881f2644f97 Mon Sep 17 00:00:00 2001 From: varshneydevansh Date: Sat, 12 Aug 2023 08:00:51 +0530 Subject: [PATCH] feat: made method virtual and get rid of errors --- include/benchmark/benchmark.h | 19 +++++++++---------- src/benchmark.cc | 8 ++++---- src/console_reporter.cc | 2 +- src/csv_reporter.cc | 2 +- src/json_reporter.cc | 2 +- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/include/benchmark/benchmark.h b/include/benchmark/benchmark.h index 88bb963416..73d165b216 100644 --- a/include/benchmark/benchmark.h +++ b/include/benchmark/benchmark.h @@ -639,7 +639,7 @@ class Counter { Counter(double v = 0., Flags f = kDefaults, OneK k = kIs1000) : value(v), flags(f), oneK(k) {} - BENCHMARK_ALWAYS_INLINE operator double const&() const { return value; } + BENCHMARK_ALWAYS_INLINE operator double const &() const { return value; } BENCHMARK_ALWAYS_INLINE operator double&() { return value; } }; @@ -712,11 +712,9 @@ enum Skipped #if defined(BENCHMARK_HAS_CXX11) : unsigned #endif -{ - NotSkipped = 0, +{ NotSkipped = 0, SkippedWithMessage, - SkippedWithError -}; + SkippedWithError }; } // namespace internal @@ -1881,7 +1879,7 @@ class BENCHMARK_EXPORT BenchmarkReporter { /** * @brief Lists and describes the provided benchmarks. * - * This static method is intended to be overridden by derived classes + * This virtual method is intended to be overridden by derived classes * to provide specific implementations for listing benchmarks. * It can be used for outputting, logging, or any other operation * needed to handle or display the benchmarks' names and metadata. @@ -1889,7 +1887,8 @@ class BENCHMARK_EXPORT BenchmarkReporter { * @param benchmarks A vector containing names and details of benchmarks * that need to be listed or processed. */ - static void List(const std::vector& benchmarks); + virtual void List( + const std::vector& benchmarks) = 0; private: std::ostream* output_stream_; @@ -1912,7 +1911,7 @@ class BENCHMARK_EXPORT ConsoleReporter : public BenchmarkReporter { bool ReportContext(const Context& context) BENCHMARK_OVERRIDE; void ReportRuns(const std::vector& reports) BENCHMARK_OVERRIDE; - static void List(const std::vector& benchmarks); + void List(const std::vector& benchmarks); protected: virtual void PrintRunData(const Run& report); @@ -1930,7 +1929,7 @@ class BENCHMARK_EXPORT JSONReporter : public BenchmarkReporter { bool ReportContext(const Context& context) BENCHMARK_OVERRIDE; void ReportRuns(const std::vector& reports) BENCHMARK_OVERRIDE; void Finalize() BENCHMARK_OVERRIDE; - static void List(const std::vector& benchmarks); + void List(const std::vector& benchmarks); private: void PrintRunData(const Run& report); @@ -1945,7 +1944,7 @@ class BENCHMARK_EXPORT BENCHMARK_DEPRECATED_MSG( CSVReporter() : printed_header_(false) {} bool ReportContext(const Context& context) BENCHMARK_OVERRIDE; void ReportRuns(const std::vector& reports) BENCHMARK_OVERRIDE; - static void List(const std::vector& benchmarks); + void List(const std::vector& benchmarks); private: void PrintRunData(const Run& report); diff --git a/src/benchmark.cc b/src/benchmark.cc index 4104511f51..a0e5ca1e7f 100644 --- a/src/benchmark.cc +++ b/src/benchmark.cc @@ -594,10 +594,10 @@ size_t RunSpecifiedBenchmarks(BenchmarkReporter* display_reporter, if (FLAGS_benchmark_list_tests) { if (FLAGS_benchmark_format == "json") { - dynamic_cast(display_reporter)->List(benchmarks); - } else { - //ConsoleReporter::List(benchmarks); - dynamic_cast(display_reporter)->List(benchmarks); + display_reporter->List(benchmarks); + } else { + // ConsoleReporter::List(benchmarks); + display_reporter->List(benchmarks); } } else { internal::RunBenchmarks(benchmarks, display_reporter, file_reporter); diff --git a/src/console_reporter.cc b/src/console_reporter.cc index 562b106035..6664da21cf 100644 --- a/src/console_reporter.cc +++ b/src/console_reporter.cc @@ -21,7 +21,7 @@ #include #include -#include "benchmark/benchmark.h" +#include "benchmark_api_internal.h" #include "check.h" #include "colorprint.h" #include "commandlineflags.h" diff --git a/src/csv_reporter.cc b/src/csv_reporter.cc index 521e5e5a70..6ca1343081 100644 --- a/src/csv_reporter.cc +++ b/src/csv_reporter.cc @@ -19,7 +19,7 @@ #include #include -#include "benchmark/benchmark.h" +#include "benchmark_api_internal.h" #include "check.h" #include "complexity.h" #include "string_util.h" diff --git a/src/json_reporter.cc b/src/json_reporter.cc index 9db491d3c8..0b6fcb3d17 100644 --- a/src/json_reporter.cc +++ b/src/json_reporter.cc @@ -22,7 +22,7 @@ #include #include -#include "benchmark/benchmark.h" +#include "benchmark_api_internal.h" #include "complexity.h" #include "string_util.h" #include "timers.h"