Program Listing for File linear-set.h

Return to documentation for file (include\playback\resource-info\detail\linear-set.h)

/******************************************************************************

© Intel Corporation.

This software and the related documents are Intel copyrighted materials,
and your use of them is governed by the express license under which they
were provided to you ("License"). Unless the License provides otherwise,
you may not use, modify, copy, publish, distribute, disclose or transmit
this software or the related documents without Intel's prior written
permission.

 This software and the related documents are provided as is, with no express
or implied warranties, other than those that are expressly stated in the
License.

******************************************************************************/

#pragma once

#include <algorithm>
#include <utility>
#include <vector>

namespace gpa {
namespace playback {
namespace detail {

template<typename T>
class LinearSet final
{
public:
    LinearSet() = default;

    inline typename std::vector<T>::const_iterator begin() const
    {
        return mElements.begin();
    }

    inline typename std::vector<T>::const_iterator end() const
    {
        return mElements.end();
    }

    inline bool empty() const
    {
        return mElements.empty();
    }

    inline size_t size() const
    {
        return mElements.size();
    }

    inline void clear()
    {
        mElements.clear();
    }

    inline std::pair<typename std::vector<T>::const_iterator, bool> insert(T const& element)
    {
        auto itr = std::lower_bound(mElements.begin(), mElements.end(), element);
        if (itr == mElements.end() || *itr != element) {
            itr = mElements.insert(itr, element);
            return {itr, true};
        }
        return {itr, false};
    }

    inline typename std::vector<T>::const_iterator find(T const& element) const
    {
        auto itr = std::lower_bound(mElements.begin(), mElements.end(), element);
        if (itr != mElements.end() && *itr == element) {
            return itr;
        }
        return mElements.end();
    }

    inline T const* data() const
    {
        return mElements.data();
    }

private:
    std::vector<T> mElements;

    LinearSet(LinearSet<T> const&) = delete;
    LinearSet<T>& operator=(LinearSet<T> const&) = delete;
};

}  // namespace detail
}  // namespace playback
}  // namespace gpa