<commit_before>// Copyright (c) 2014 Steinwurf ApS
// All Rights Reserved
//
// Distributed under the "BSD License". See the accompanying LICENSE.rst file.

namespace stub
{
    /// @brief The return_handler is a helper object that is used
    /// e.g. in the call object to control which return values should
    /// be generated when called.
    ///
    /// The return_handler provides the call operator() and when
    /// invoked it will return the specified return value. The type R
    /// will be the return value.
    ///
    /// Example:
    ///
    ///    return_handler<uint32_t> v;
    ///    v.set_return(4U);
    ///    v.set_return(3U);
    ///
    ///    uint32_t a = v();
    ///    assert(a == 4U);
    ///
    ///    uint32_t b = v();
    ///    assert(b == 3U);
    ///
    /// Or alternatively using the set_returns() function:
    ///
    ///    return_handler<uint32_t> v;
    ///    v.set_returns({4U,3U});
    ///
    ///    uint32_t a = v();
    ///    assert(a == 4U);
    ///
    ///    uint32_t b = v();
    ///    assert(b == 3U);
    ///
    template<class R>
    class return_handler
    {
    public:

        /// Constructor
        return_handler()
            : m_position(0)
        {}

        /// Add
        void set_return(const R& value)
        {
            m_returns.push_back(value);
        }

        void set_returns(const std::initializer_list<R>& values)
        {
            m_returns.insert(m_returns.end(),
                             values.begin(), values.end());
        }

        R operator()() const
        {
            assert(m_position < m_returns.size());

            R value = m_returns[m_position];
            ++m_position;

            return value;
        }

        mutable uint32_t m_position;
        std::vector<R> m_returns;
    };
<commit_msg>Working on the return_handler<commit_after>// Copyright (c) 2014 Steinwurf ApS
// All Rights Reserved
//
// Distributed under the "BSD License". See the accompanying LICENSE.rst file.

namespace stub
{
    /// @brief The return_handler is a helper object that is used
    /// e.g. in the call object to control which return values should
    /// be generated when called.
    ///
    /// The return_handler provides the call operator() and when
    /// invoked it will return the specified return value. The type R
    /// will be the return value.
    ///
    /// Example:
    ///
    ///    return_handler<uint32_t> v;
    ///    v.set_return(4U);
    ///    v.set_return(3U);
    ///
    ///    uint32_t a = v();
    ///    assert(a == 4U);
    ///
    ///    uint32_t b = v();
    ///    assert(b == 3U);
    ///
    /// Or alternatively using the set_returns() function:
    ///
    ///    return_handler<uint32_t> v;
    ///    v.set_returns({4U,3U});
    ///
    ///    uint32_t a = v();
    ///    assert(a == 4U);
    ///
    ///    uint32_t b = v();
    ///    assert(b == 3U);
    ///
    template<class R>
    class return_handler
    {
    public:

        /// Constructor
        return_handler()
            : m_position(0)
        {}

        /// Specify the return value to use
        return_handler& set_return(const R& value)
        {
            m_position = 0;
            m_returns.clear();

            m_returns.push_back(value);
        }

        return_handler& set_returns(const std::initializer_list<R>& values)
        {
            m_position = 0;
            m_returns.clear();

            m_returns.insert(m_returns.end(),
                             values.begin(), values.end());
        }

        return_handler& repeat_on()
        {
            return *this;
        }

        return_handler& repeat_off()
        {
            return *this;
        }

        R operator()() const
        {
            assert(m_position < m_returns.size());

            R value = m_returns[m_position];
            ++m_position;

            return value;
        }

        mutable uint32_t m_position;
        std::vector<R> m_returns;
    };

{'fraction_non_alphanumeric': 0.13710282712034025, 'fraction_numerical': 0.014010507880910683, 'mean_word_length': 1.4274438372799028, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6511106', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1189, 'n_words': 304}