|
| 1 | +//------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 2 | +// |
| 3 | +// Foundation/NSArray.hpp |
| 4 | +// |
| 5 | +// Copyright 2020-2021 Apple Inc. |
| 6 | +// |
| 7 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +// you may not use this file except in compliance with the License. |
| 9 | +// You may obtain a copy of the License at |
| 10 | +// |
| 11 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +// |
| 13 | +// Unless required by applicable law or agreed to in writing, software |
| 14 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +// See the License for the specific language governing permissions and |
| 17 | +// limitations under the License. |
| 18 | +// |
| 19 | +//------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 20 | + |
| 21 | +#pragma once |
| 22 | + |
| 23 | +//------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 24 | + |
| 25 | +#include "NSObject.hpp" |
| 26 | +#include "NSTypes.hpp" |
| 27 | + |
| 28 | +//------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 29 | + |
| 30 | +namespace NS |
| 31 | +{ |
| 32 | +class Array : public Copying<Array> |
| 33 | +{ |
| 34 | +public: |
| 35 | + static Array* array(); |
| 36 | + static Array* array(const Object* pObject); |
| 37 | + static Array* array(const Object* const* pObjects, UInteger count); |
| 38 | + |
| 39 | + static Array* alloc(); |
| 40 | + |
| 41 | + Array* init(); |
| 42 | + Array* init(const Object* const* pObjects, UInteger count); |
| 43 | + Array* init(const class Coder* pCoder); |
| 44 | + |
| 45 | + template <class _Object = Object> |
| 46 | + _Object* object(UInteger index) const; |
| 47 | + UInteger count() const; |
| 48 | +}; |
| 49 | +} |
| 50 | + |
| 51 | +//------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 52 | + |
| 53 | +_NS_INLINE NS::Array* NS::Array::array() |
| 54 | +{ |
| 55 | + return Object::sendMessage<Array*>(_NS_PRIVATE_CLS(NSArray), _NS_PRIVATE_SEL(array)); |
| 56 | +} |
| 57 | + |
| 58 | +//------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 59 | + |
| 60 | +_NS_INLINE NS::Array* NS::Array::array(const Object* pObject) |
| 61 | +{ |
| 62 | + return Object::sendMessage<Array*>(_NS_PRIVATE_CLS(NSArray), _NS_PRIVATE_SEL(arrayWithObject_), pObject); |
| 63 | +} |
| 64 | + |
| 65 | +//------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 66 | + |
| 67 | +_NS_INLINE NS::Array* NS::Array::array(const Object* const* pObjects, UInteger count) |
| 68 | +{ |
| 69 | + return Object::sendMessage<Array*>(_NS_PRIVATE_CLS(NSArray), _NS_PRIVATE_SEL(arrayWithObjects_count_), pObjects, count); |
| 70 | +} |
| 71 | + |
| 72 | +//------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 73 | + |
| 74 | +_NS_INLINE NS::Array* NS::Array::alloc() |
| 75 | +{ |
| 76 | + return NS::Object::alloc<Array>(_NS_PRIVATE_CLS(NSArray)); |
| 77 | +} |
| 78 | + |
| 79 | +//------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 80 | + |
| 81 | +_NS_INLINE NS::Array* NS::Array::init() |
| 82 | +{ |
| 83 | + return NS::Object::init<Array>(); |
| 84 | +} |
| 85 | + |
| 86 | +//------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 87 | + |
| 88 | +_NS_INLINE NS::Array* NS::Array::init(const Object* const* pObjects, UInteger count) |
| 89 | +{ |
| 90 | + return Object::sendMessage<Array*>(this, _NS_PRIVATE_SEL(initWithObjects_count_), pObjects, count); |
| 91 | +} |
| 92 | + |
| 93 | +//------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 94 | + |
| 95 | +_NS_INLINE NS::Array* NS::Array::init(const class Coder* pCoder) |
| 96 | +{ |
| 97 | + return Object::sendMessage<Array*>(this, _NS_PRIVATE_SEL(initWithCoder_), pCoder); |
| 98 | +} |
| 99 | + |
| 100 | +//------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 101 | + |
| 102 | +_NS_INLINE NS::UInteger NS::Array::count() const |
| 103 | +{ |
| 104 | + return Object::sendMessage<UInteger>(this, _NS_PRIVATE_SEL(count)); |
| 105 | +} |
| 106 | + |
| 107 | +//------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 108 | + |
| 109 | +template <class _Object> |
| 110 | +_NS_INLINE _Object* NS::Array::object(UInteger index) const |
| 111 | +{ |
| 112 | + return Object::sendMessage<_Object*>(this, _NS_PRIVATE_SEL(objectAtIndex_), index); |
| 113 | +} |
| 114 | + |
| 115 | +//------------------------------------------------------------------------------------------------------------------------------------------------------------- |
0 commit comments