|
||||
File indexing completed on 2025-01-18 09:54:04
0001 0002 // Copyright Catch2 Authors 0003 // Distributed under the Boost Software License, Version 1.0. 0004 // (See accompanying file LICENSE.txt or copy at 0005 // https://www.boost.org/LICENSE_1_0.txt) 0006 0007 // SPDX-License-Identifier: BSL-1.0 0008 #ifndef CATCH_INTERFACES_GENERATORTRACKER_HPP_INCLUDED 0009 #define CATCH_INTERFACES_GENERATORTRACKER_HPP_INCLUDED 0010 0011 #include <catch2/internal/catch_unique_ptr.hpp> 0012 #include <catch2/internal/catch_stringref.hpp> 0013 0014 #include <string> 0015 0016 namespace Catch { 0017 0018 namespace Generators { 0019 class GeneratorUntypedBase { 0020 // Caches result from `toStringImpl`, assume that when it is an 0021 // empty string, the cache is invalidated. 0022 mutable std::string m_stringReprCache; 0023 0024 // Counts based on `next` returning true 0025 std::size_t m_currentElementIndex = 0; 0026 0027 /** 0028 * Attempts to move the generator to the next element 0029 * 0030 * Returns true iff the move succeeded (and a valid element 0031 * can be retrieved). 0032 */ 0033 virtual bool next() = 0; 0034 0035 //! Customization point for `currentElementAsString` 0036 virtual std::string stringifyImpl() const = 0; 0037 0038 public: 0039 GeneratorUntypedBase() = default; 0040 // Generation of copy ops is deprecated (and Clang will complain) 0041 // if there is a user destructor defined 0042 GeneratorUntypedBase(GeneratorUntypedBase const&) = default; 0043 GeneratorUntypedBase& operator=(GeneratorUntypedBase const&) = default; 0044 0045 virtual ~GeneratorUntypedBase(); // = default; 0046 0047 /** 0048 * Attempts to move the generator to the next element 0049 * 0050 * Serves as a non-virtual interface to `next`, so that the 0051 * top level interface can provide sanity checking and shared 0052 * features. 0053 * 0054 * As with `next`, returns true iff the move succeeded and 0055 * the generator has new valid element to provide. 0056 */ 0057 bool countedNext(); 0058 0059 std::size_t currentElementIndex() const { return m_currentElementIndex; } 0060 0061 /** 0062 * Returns generator's current element as user-friendly string. 0063 * 0064 * By default returns string equivalent to calling 0065 * `Catch::Detail::stringify` on the current element, but generators 0066 * can customize their implementation as needed. 0067 * 0068 * Not thread-safe due to internal caching. 0069 * 0070 * The returned ref is valid only until the generator instance 0071 * is destructed, or it moves onto the next element, whichever 0072 * comes first. 0073 */ 0074 StringRef currentElementAsString() const; 0075 }; 0076 using GeneratorBasePtr = Catch::Detail::unique_ptr<GeneratorUntypedBase>; 0077 0078 } // namespace Generators 0079 0080 class IGeneratorTracker { 0081 public: 0082 virtual ~IGeneratorTracker(); // = default; 0083 virtual auto hasGenerator() const -> bool = 0; 0084 virtual auto getGenerator() const -> Generators::GeneratorBasePtr const& = 0; 0085 virtual void setGenerator( Generators::GeneratorBasePtr&& generator ) = 0; 0086 }; 0087 0088 } // namespace Catch 0089 0090 #endif // CATCH_INTERFACES_GENERATORTRACKER_HPP_INCLUDED
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |