SPB Git

spb/forge Public MIT

Forge — LLM training from scratch in pure C++20 + Metal on Apple Silicon.

C++ 61.2% C 23% Python 7.6% TeX 7.2% CMake 1.1%
5.1 KB · 125 lines cpp
Raw Blame History
1//-------------------------------------------------------------------------------------------------------------------------------------------------------------2//3// Foundation/NSArray.hpp4//5// Copyright 2020-2024 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 at10//11//     http://www.apache.org/licenses/LICENSE-2.012//13// Unless required by applicable law or agreed to in writing, software14// 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 and17// limitations under the License.18//19//-------------------------------------------------------------------------------------------------------------------------------------------------------------2021#pragma once2223//-------------------------------------------------------------------------------------------------------------------------------------------------------------2425#include "NSObject.hpp"26#include "NSTypes.hpp"27#include "NSEnumerator.hpp"2829//-------------------------------------------------------------------------------------------------------------------------------------------------------------3031namespace NS32{33class Array : public Copying<Array>34{35public:36    static Array* array();37    static Array* array(const Object* pObject);38    static Array* array(const Object* const* pObjects, UInteger count);3940    static Array* alloc();4142    Array*        init();43    Array*        init(const Object* const* pObjects, UInteger count);44    Array*        init(const class Coder* pCoder);4546    template <class _Object = Object>47    _Object*            object(UInteger index) const;48    UInteger            count() const;49    Enumerator<Object>* objectEnumerator() const;50};51}5253//-------------------------------------------------------------------------------------------------------------------------------------------------------------5455_NS_INLINE NS::Array* NS::Array::array()56{57    return Object::sendMessage<Array*>(_NS_PRIVATE_CLS(NSArray), _NS_PRIVATE_SEL(array));58}5960//-------------------------------------------------------------------------------------------------------------------------------------------------------------6162_NS_INLINE NS::Array* NS::Array::array(const Object* pObject)63{64    return Object::sendMessage<Array*>(_NS_PRIVATE_CLS(NSArray), _NS_PRIVATE_SEL(arrayWithObject_), pObject);65}6667//-------------------------------------------------------------------------------------------------------------------------------------------------------------6869_NS_INLINE NS::Array* NS::Array::array(const Object* const* pObjects, UInteger count)70{71    return Object::sendMessage<Array*>(_NS_PRIVATE_CLS(NSArray), _NS_PRIVATE_SEL(arrayWithObjects_count_), pObjects, count);72}7374//-------------------------------------------------------------------------------------------------------------------------------------------------------------7576_NS_INLINE NS::Array* NS::Array::alloc()77{78    return NS::Object::alloc<Array>(_NS_PRIVATE_CLS(NSArray));79}8081//-------------------------------------------------------------------------------------------------------------------------------------------------------------8283_NS_INLINE NS::Array* NS::Array::init()84{85    return NS::Object::init<Array>();86}8788//-------------------------------------------------------------------------------------------------------------------------------------------------------------8990_NS_INLINE NS::Array* NS::Array::init(const Object* const* pObjects, UInteger count)91{92    return Object::sendMessage<Array*>(this, _NS_PRIVATE_SEL(initWithObjects_count_), pObjects, count);93}9495//-------------------------------------------------------------------------------------------------------------------------------------------------------------9697_NS_INLINE NS::Array* NS::Array::init(const class Coder* pCoder)98{99    return Object::sendMessage<Array*>(this, _NS_PRIVATE_SEL(initWithCoder_), pCoder);100}101102//-------------------------------------------------------------------------------------------------------------------------------------------------------------103104_NS_INLINE NS::UInteger NS::Array::count() const105{106    return Object::sendMessage<UInteger>(this, _NS_PRIVATE_SEL(count));107}108109//-------------------------------------------------------------------------------------------------------------------------------------------------------------110111template <class _Object>112_NS_INLINE _Object* NS::Array::object(UInteger index) const113{114    return Object::sendMessage<_Object*>(this, _NS_PRIVATE_SEL(objectAtIndex_), index);115}116117//-------------------------------------------------------------------------------------------------------------------------------------------------------------118119_NS_INLINE NS::Enumerator<NS::Object>* NS::Array::objectEnumerator() const120{121    return NS::Object::sendMessage<Enumerator<NS::Object>*>(this, _NS_PRIVATE_SEL(objectEnumerator));122}123124//-------------------------------------------------------------------------------------------------------------------------------------------------------------125