Path: blob/master/thirdparty/metal-cpp/Foundation/NSEnumerator.hpp
21066 views
//-------------------------------------------------------------------------------------------------------------------------------------------------------------1//2// Foundation/NSEnumerator.hpp3//4// Copyright 2020-2024 Apple Inc.5//6// Licensed under the Apache License, Version 2.0 (the "License");7// you may not use this file except in compliance with the License.8// You may obtain a copy of the License at9//10// http://www.apache.org/licenses/LICENSE-2.011//12// Unless required by applicable law or agreed to in writing, software13// distributed under the License is distributed on an "AS IS" BASIS,14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15// See the License for the specific language governing permissions and16// limitations under the License.17//18//-------------------------------------------------------------------------------------------------------------------------------------------------------------1920#pragma once2122//-------------------------------------------------------------------------------------------------------------------------------------------------------------2324#include "NSObject.hpp"25#include "NSTypes.hpp"2627//-------------------------------------------------------------------------------------------------------------------------------------------------------------2829namespace NS30{31struct FastEnumerationState32{33unsigned long state;34Object** itemsPtr;35unsigned long* mutationsPtr;36unsigned long extra[5];37} _NS_PACKED;3839class FastEnumeration : public Referencing<FastEnumeration>40{41public:42NS::UInteger countByEnumerating(FastEnumerationState* pState, Object** pBuffer, NS::UInteger len);43};4445template <class _ObjectType>46class Enumerator : public Referencing<Enumerator<_ObjectType>, FastEnumeration>47{48public:49_ObjectType* nextObject();50class Array* allObjects();51};52}5354//-------------------------------------------------------------------------------------------------------------------------------------------------------------5556_NS_INLINE NS::UInteger NS::FastEnumeration::countByEnumerating(FastEnumerationState* pState, Object** pBuffer, NS::UInteger len)57{58return Object::sendMessage<UInteger>(this, _NS_PRIVATE_SEL(countByEnumeratingWithState_objects_count_), pState, pBuffer, len);59}6061//-------------------------------------------------------------------------------------------------------------------------------------------------------------6263template <class _ObjectType>64_NS_INLINE _ObjectType* NS::Enumerator<_ObjectType>::nextObject()65{66return Object::sendMessage<_ObjectType*>(this, _NS_PRIVATE_SEL(nextObject));67}6869//-------------------------------------------------------------------------------------------------------------------------------------------------------------7071template <class _ObjectType>72_NS_INLINE NS::Array* NS::Enumerator<_ObjectType>::allObjects()73{74return Object::sendMessage<Array*>(this, _NS_PRIVATE_SEL(allObjects));75}7677//-------------------------------------------------------------------------------------------------------------------------------------------------------------787980