#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2023 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_SUPPORT_COLLECTIONS_COLLECTION_H #define NUCLEX_SUPPORT_COLLECTIONS_COLLECTION_H #include "Nuclex/Support/Config.h" #include // for std::size_t namespace Nuclex { namespace Support { namespace Collections { // ------------------------------------------------------------------------------------------- // /// Set of items that can be accessed sequentially /// /// /// The collection interface is not meant for local or private use within your /// code since the Standard C++ Library contains a host of very well designed and /// powerful container classes that are the envy of other languages far and wide. /// /// /// Use this interface where you might want to expose a collection to users of /// a library without binding yourself to a specific container type. This allows /// you to expose a list of things in a natural and consistent way without /// duplicating Add() and Remove() methods, while keeping complete freedom over /// the actual data structure used to store the items. /// /// template class Collection { #pragma region class Enumerator /// Iterates over the items in the collection public: class Enumerator { /// Frees any memory used by the enumerator public: virtual ~Enumerator() = default; /// Advances to the next item in the collection, if available /// True if there was a next item, false if the end was reached public: virtual bool Advance() = 0; /// Retrieves the item at the current enumerator position /// /// The enumerator starts out on an empty position, so you have to call /// as the very first method of a new enumerator /// (and if the collection is empty, that first call will return false). /// public: virtual const TValue &Get() const = 0; private: Enumerator(const Enumerator &) = delete; private: Enumerator &operator =(const Enumerator &) = delete; }; #pragma endregion // class Enumerator /// Initializes a new collection protected: Collection() = default; /// Frees all memory used by the collection public: virtual ~Collection() = default; /// Adds the specified item to the collection /// Item that will be added to the collection public: virtual void Add(const TValue &item) = 0; /// Removes the specified item from the collection /// Item that will be removed from the collection /// True if the item existed in the collection and was removed public: virtual bool Remove(const TValue &item) = 0; /// Removes all items from the collection public: virtual void Clear() = 0; /// Checks if the collection contains the specified item /// Item the collection will be checked for /// True if the collection contain the specified item, false otherwise public: virtual bool Contains(const TValue &item) const = 0; /// Counts the number of items in the collection /// The number of items the collection contains public: virtual std::size_t Count() const = 0; /// Checks if the collection is empty /// True if the collection is empty public: virtual bool IsEmpty() const = 0; //private: Collection(const Collection &) = delete; //private: Collection &operator =(const Collection &) = delete; }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Support::Collections #endif // NUCLEX_SUPPORT_COLLECTIONS_COLLECTION_H