Path: blob/master/thirdparty/metal-cpp/Foundation/NSRange.hpp
21066 views
//-------------------------------------------------------------------------------------------------------------------------------------------------------------1//2// Foundation/NSRange.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 "NSDefines.hpp"25#include "NSTypes.hpp"2627//-------------------------------------------------------------------------------------------------------------------------------------------------------------2829namespace NS30{31struct Range32{33static Range Make(UInteger loc, UInteger len);3435Range(UInteger loc, UInteger len);3637bool Equal(const Range& range) const;38bool LocationInRange(UInteger loc) const;39UInteger Max() const;4041UInteger location;42UInteger length;43} _NS_PACKED;44}4546//-------------------------------------------------------------------------------------------------------------------------------------------------------------4748_NS_INLINE NS::Range::Range(UInteger loc, UInteger len)49: location(loc)50, length(len)51{52}5354//-------------------------------------------------------------------------------------------------------------------------------------------------------------5556_NS_INLINE NS::Range NS::Range::Make(UInteger loc, UInteger len)57{58return Range(loc, len);59}6061//-------------------------------------------------------------------------------------------------------------------------------------------------------------6263_NS_INLINE bool NS::Range::Equal(const Range& range) const64{65return (location == range.location) && (length == range.length);66}6768//-------------------------------------------------------------------------------------------------------------------------------------------------------------6970_NS_INLINE bool NS::Range::LocationInRange(UInteger loc) const71{72return (!(loc < location)) && ((loc - location) < length);73}7475//-------------------------------------------------------------------------------------------------------------------------------------------------------------7677_NS_INLINE NS::UInteger NS::Range::Max() const78{79return location + length;80}8182//-------------------------------------------------------------------------------------------------------------------------------------------------------------838485