Path: blob/master/thirdparty/metal-cpp/Foundation/NSArray.hpp
21066 views
//-------------------------------------------------------------------------------------------------------------------------------------------------------------1//2// Foundation/NSArray.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"26#include "NSEnumerator.hpp"2728//-------------------------------------------------------------------------------------------------------------------------------------------------------------2930namespace NS31{32class Array : public Copying<Array>33{34public:35static Array* array();36static Array* array(const Object* pObject);37static Array* array(const Object* const* pObjects, UInteger count);3839static Array* alloc();4041Array* init();42Array* init(const Object* const* pObjects, UInteger count);43Array* init(const class Coder* pCoder);4445template <class _Object = Object>46_Object* object(UInteger index) const;47UInteger count() const;48Enumerator<Object>* objectEnumerator() const;49};50}5152//-------------------------------------------------------------------------------------------------------------------------------------------------------------5354_NS_INLINE NS::Array* NS::Array::array()55{56return Object::sendMessage<Array*>(_NS_PRIVATE_CLS(NSArray), _NS_PRIVATE_SEL(array));57}5859//-------------------------------------------------------------------------------------------------------------------------------------------------------------6061_NS_INLINE NS::Array* NS::Array::array(const Object* pObject)62{63return Object::sendMessage<Array*>(_NS_PRIVATE_CLS(NSArray), _NS_PRIVATE_SEL(arrayWithObject_), pObject);64}6566//-------------------------------------------------------------------------------------------------------------------------------------------------------------6768_NS_INLINE NS::Array* NS::Array::array(const Object* const* pObjects, UInteger count)69{70return Object::sendMessage<Array*>(_NS_PRIVATE_CLS(NSArray), _NS_PRIVATE_SEL(arrayWithObjects_count_), pObjects, count);71}7273//-------------------------------------------------------------------------------------------------------------------------------------------------------------7475_NS_INLINE NS::Array* NS::Array::alloc()76{77return NS::Object::alloc<Array>(_NS_PRIVATE_CLS(NSArray));78}7980//-------------------------------------------------------------------------------------------------------------------------------------------------------------8182_NS_INLINE NS::Array* NS::Array::init()83{84return NS::Object::init<Array>();85}8687//-------------------------------------------------------------------------------------------------------------------------------------------------------------8889_NS_INLINE NS::Array* NS::Array::init(const Object* const* pObjects, UInteger count)90{91return Object::sendMessage<Array*>(this, _NS_PRIVATE_SEL(initWithObjects_count_), pObjects, count);92}9394//-------------------------------------------------------------------------------------------------------------------------------------------------------------9596_NS_INLINE NS::Array* NS::Array::init(const class Coder* pCoder)97{98return Object::sendMessage<Array*>(this, _NS_PRIVATE_SEL(initWithCoder_), pCoder);99}100101//-------------------------------------------------------------------------------------------------------------------------------------------------------------102103_NS_INLINE NS::UInteger NS::Array::count() const104{105return Object::sendMessage<UInteger>(this, _NS_PRIVATE_SEL(count));106}107108//-------------------------------------------------------------------------------------------------------------------------------------------------------------109110template <class _Object>111_NS_INLINE _Object* NS::Array::object(UInteger index) const112{113return Object::sendMessage<_Object*>(this, _NS_PRIVATE_SEL(objectAtIndex_), index);114}115116//-------------------------------------------------------------------------------------------------------------------------------------------------------------117118_NS_INLINE NS::Enumerator<NS::Object>* NS::Array::objectEnumerator() const119{120return NS::Object::sendMessage<Enumerator<NS::Object>*>(this, _NS_PRIVATE_SEL(objectEnumerator));121}122123//-------------------------------------------------------------------------------------------------------------------------------------------------------------124125126