Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extension Progress {
/// - Parameter count: Number of units delegated to a child instance of `ProgressManager`
/// which may be instantiated by `Subprogress` later when `reporter(totalCount:)` is called.
/// - Returns: A `Subprogress` instance.
public func makeChild(withPendingUnitCount count: Int) -> Subprogress {
public func subprogress(assigningCount count: Int) -> Subprogress {

// Make a ProgressManager
let manager = ProgressManager(totalCount: 1)
Expand Down Expand Up @@ -102,7 +102,7 @@ extension ProgressManager {
/// - Parameters:
/// - count: Number of units delegated from `self`'s `totalCount`.
/// - progress: `Progress` which receives the delegated `count`.
public func subprogress(assigningCount count: Int, to progress: Foundation.Progress) {
public func assign(count: Int, to progress: Foundation.Progress) {
precondition(progress._parent() == nil, "Cannot assign a progress to more than one parent.")

// Create a ProgressManager - NSProgress bridge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,22 +388,25 @@ extension ProgressManager {
/// - Parameter property: The type of the integer property to summarize. Must be a property
/// where both the value and summary types are `Int`.
/// - Returns: An `Int` summary value for the specified property.
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == Int, P.Summary == Int {
if property.self == ProgressManager.Properties.TotalFileCount.self {
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> P.Summary where P.Value == Int, P.Summary == Int {
if P.self == ProgressManager.Properties.TotalFileCount.self {
self.access(keyPath: \.totalFileCount)
self.access(keyPath: \.totalFileCountSummary)
let updatedFileCount = updatedFileCount(type: .total)
self.didSet(keyPath: \.totalFileCountSummary)
return updatedFileCount(type: .total)
} else if property.self == ProgressManager.Properties.CompletedFileCount.self {
return updatedFileCount
} else if P.self == ProgressManager.Properties.CompletedFileCount.self {
self.access(keyPath: \.completedFileCount)
self.access(keyPath: \.completedFileCountSummary)
let updatedFileCount = updatedFileCount(type: .completed)
self.didSet(keyPath: \.completedFileCountSummary)
return updatedFileCount(type: .completed)
return updatedFileCount
} else {
self.access(keyPath: \.customPropertiesInt)
self.access(keyPath: \.customPropertiesIntSummary)
let updatedResult = updatedIntSummary(property: MetatypeWrapper(P.self))
self.didSet(keyPath: \.customPropertiesIntSummary)
return updatedIntSummary(property: MetatypeWrapper(property))
return updatedResult
}
}

Expand All @@ -415,22 +418,25 @@ extension ProgressManager {
/// - Parameter property: The type of the unsigned integer property to summarize. Must be a property
/// where both the value and summary types are `UInt64`.
/// - Returns: An `UInt64` summary value for the specified property.
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == UInt64, P.Summary == UInt64 {
if property.self == ProgressManager.Properties.TotalByteCount.self {
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> P.Summary where P.Value == UInt64, P.Summary == UInt64 {
if P.self == ProgressManager.Properties.TotalByteCount.self {
self.access(keyPath: \.totalByteCount)
self.access(keyPath: \.totalByteCountSummary)
let updatedByteCount = updatedByteCount(type: .total)
self.didSet(keyPath: \.totalByteCountSummary)
return updatedByteCount(type: .total)
} else if property.self == ProgressManager.Properties.CompletedByteCount.self {
return updatedByteCount
} else if P.self == ProgressManager.Properties.CompletedByteCount.self {
self.access(keyPath: \.completedByteCount)
self.access(keyPath: \.completedByteCountSummary)
let updatedByteCount = updatedByteCount(type: .completed)
self.didSet(keyPath: \.completedByteCountSummary)
return updatedByteCount(type: .completed)
return updatedByteCount
} else {
self.access(keyPath: \.customPropertiesUInt64)
self.access(keyPath: \.customPropertiesUInt64Summary)
let updatedResult = updatedUInt64Summary(property: MetatypeWrapper(P.self))
self.didSet(keyPath: \.customPropertiesUInt64Summary)
return updatedUInt64Summary(property: MetatypeWrapper(property))
return updatedResult
}
}

Expand All @@ -442,11 +448,12 @@ extension ProgressManager {
/// - Parameter property: The type of the double property to summarize. Must be a property
/// where both the value and summary types are `Double`.
/// - Returns: A `Double` summary value for the specified property.
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == Double, P.Summary == Double {
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> P.Summary where P.Value == Double, P.Summary == Double {
self.access(keyPath: \.customPropertiesDouble)
self.access(keyPath: \.customPropertiesDoubleSummary)
let updatedResult = updatedDoubleSummary(property: MetatypeWrapper(P.self))
self.didSet(keyPath: \.customPropertiesDoubleSummary)
return updatedDoubleSummary(property: MetatypeWrapper(property))
return updatedResult
}

/// Returns a summary for a custom string property across the progress subtree.
Expand All @@ -457,11 +464,12 @@ extension ProgressManager {
/// - Parameter property: The type of the string property to summarize. Must be a property
/// where both the value type is `String?` and the summary type is `[String?]`.
/// - Returns: A `[String?]` summary value for the specified property.
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == String?, P.Summary == [String?] {
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> P.Summary where P.Value == String?, P.Summary == [String?] {
self.access(keyPath: \.customPropertiesString)
self.access(keyPath: \.customPropertiesStringSummary)
let updatedResult = updatedStringSummary(property: MetatypeWrapper(P.self))
self.didSet(keyPath: \.customPropertiesStringSummary)
return updatedStringSummary(property: MetatypeWrapper(property))
return updatedResult
}

/// Returns a summary for a custom URL property across the progress subtree.
Expand All @@ -472,11 +480,12 @@ extension ProgressManager {
/// - Parameter property: The type of the URL property to summarize. Must be a property
/// where the value type is `URL?` and the summary type is `[URL?]`.
/// - Returns: A `[URL?]` summary value for the specified property.
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == URL?, P.Summary == [URL?] {
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> P.Summary where P.Value == URL?, P.Summary == [URL?] {
self.access(keyPath: \.customPropertiesURL)
self.access(keyPath: \.customPropertiesURLSummary)
let updatedResult = updatedURLSummary(property: MetatypeWrapper(P.self))
self.didSet(keyPath: \.customPropertiesURLSummary)
return updatedURLSummary(property: MetatypeWrapper(property))
return updatedResult
}

/// Returns a summary for a custom unsigned integer property across the progress subtree.
Expand All @@ -487,17 +496,19 @@ extension ProgressManager {
/// - Parameter property: The type of the unsigned integer property to summarize. Must be a property
/// where the value type is `UInt64` and the summary type is `[UInt64]`.
/// - Returns: A `[UInt64]` summary value for the specified property.
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == UInt64, P.Summary == [UInt64] {
if property.self == ProgressManager.Properties.Throughput.self {
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> P.Summary where P.Value == UInt64, P.Summary == [UInt64] {
if P.self == ProgressManager.Properties.Throughput.self {
self.access(keyPath: \.throughput)
self.access(keyPath: \.throughputSummary)
let updatedThroughput = updatedThroughput()
self.didSet(keyPath: \.throughputSummary)
return updatedThroughput()
return updatedThroughput
} else {
self.access(keyPath: \.customPropertiesUInt64Array)
self.access(keyPath: \.customPropertiesUInt64ArraySummary)
let updatedResult = updatedUInt64ArraySummary(property: MetatypeWrapper(P.self))
self.didSet(keyPath: \.customPropertiesUInt64ArraySummary)
return updatedUInt64ArraySummary(property: MetatypeWrapper(property))
return updatedResult
}
}

Expand All @@ -509,17 +520,19 @@ extension ProgressManager {
/// - Parameter property: The type of the duration property to summarize. Must be a property
/// where the value type is `Duration` and the summary type is `Duration`.
/// - Returns: A `Duration` summary value for the specified property.
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == Duration, P.Summary == Duration {
if property.self == ProgressManager.Properties.EstimatedTimeRemaining.self {
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> P.Summary where P.Value == Duration, P.Summary == Duration {
if P.self == ProgressManager.Properties.EstimatedTimeRemaining.self {
self.access(keyPath: \.estimatedTimeRemaining)
self.access(keyPath: \.estimatedTimeRemainingSummary)
let updatedTimeRemaining = updatedEstimatedTimeRemaining()
self.didSet(keyPath: \.estimatedTimeRemainingSummary)
return updatedEstimatedTimeRemaining()
return updatedTimeRemaining
} else {
self.access(keyPath: \.customPropertiesDuration)
self.access(keyPath: \.customPropertiesDurationSummary)
let updatedResult = updatedDurationSummary(property: MetatypeWrapper(P.self))
self.didSet(keyPath: \.customPropertiesDurationSummary)
return updatedDurationSummary(property: MetatypeWrapper(property))
return updatedResult
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -551,12 +551,12 @@ extension ProgressManager: CustomStringConvertible, CustomDebugStringConvertible
fractionCompleted: \(fractionCompleted)
isIndeterminate: \(isIndeterminate)
isFinished: \(isFinished)
totalFileCount: \(summary(of: ProgressManager.Properties.TotalFileCount.self))
completedFileCount: \(summary(of: ProgressManager.Properties.CompletedFileCount.self))
totalByteCount: \(summary(of: ProgressManager.Properties.TotalByteCount.self))
completedByteCount: \(summary(of: ProgressManager.Properties.CompletedByteCount.self))
throughput: \(summary(of: ProgressManager.Properties.Throughput.self))
estimatedTimeRemaining: \(summary(of: ProgressManager.Properties.EstimatedTimeRemaining.self))
totalFileCount: \(summary(of: \.totalFileCount))
completedFileCount: \(summary(of: \.completedFileCount))
totalByteCount: \(summary(of: \.totalByteCount))
completedByteCount: \(summary(of: \.completedByteCount))
throughput: \(summary(of: \.throughput))
estimatedTimeRemaining: \(summary(of: \.estimatedTimeRemaining))
"""
}

Expand Down
26 changes: 13 additions & 13 deletions Sources/FoundationEssentials/ProgressManager/ProgressReporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ import Observation
fractionCompleted: \(fractionCompleted)
isIndeterminate: \(isIndeterminate)
isFinished: \(isFinished)
totalFileCount: \(summary(of: ProgressManager.Properties.TotalFileCount.self))
completedFileCount: \(summary(of: ProgressManager.Properties.CompletedFileCount.self))
totalByteCount: \(summary(of: ProgressManager.Properties.TotalByteCount.self))
completedByteCount: \(summary(of: ProgressManager.Properties.CompletedByteCount.self))
throughput: \(summary(of: ProgressManager.Properties.Throughput.self))
estimatedTimeRemaining: \(summary(of: ProgressManager.Properties.EstimatedTimeRemaining.self))
totalFileCount: \(summary(of: \.totalFileCount))
completedFileCount: \(summary(of: \.completedFileCount))
totalByteCount: \(summary(of: \.totalByteCount))
completedByteCount: \(summary(of: \.completedByteCount))
throughput: \(summary(of: \.throughput))
estimatedTimeRemaining: \(summary(of: \.estimatedTimeRemaining))
"""
}

Expand All @@ -90,7 +90,7 @@ import Observation
/// - Parameter property: The type of the integer property to summarize. Must be a property
/// where both the value and summary types are `Int`.
/// - Returns: The aggregated summary value for the specified property across the entire subtree.
public func summary<P: Property>(of property: P.Type) -> Int where P.Value == Int, P.Summary == Int {
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> Int where P.Value == Int, P.Summary == Int {
manager.summary(of: property)
}

Expand All @@ -102,7 +102,7 @@ import Observation
/// - Parameter property: The type of the unsigned property to summarize. Must be a property
/// where both the value and summary types are `UInt64`.
/// - Returns: The aggregated summary value for the specified property across the entire subtree.
public func summary<P: Property>(of property: P.Type) -> UInt64 where P.Value == UInt64, P.Summary == UInt64 {
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> UInt64 where P.Value == UInt64, P.Summary == UInt64 {
manager.summary(of: property)
}

Expand All @@ -114,7 +114,7 @@ import Observation
/// - Parameter property: The type of the double property to summarize. Must be a property
/// where both the value and summary types are `Double`.
/// - Returns: The aggregated summary value for the specified property across the entire subtree.
public func summary<P: Property>(of property: P.Type) -> Double where P.Value == Double, P.Summary == Double {
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> Double where P.Value == Double, P.Summary == Double {
manager.summary(of: property)
}

Expand All @@ -126,7 +126,7 @@ import Observation
/// - Parameter property: The type of the string property to summarize. Must be a property
/// where both the value and summary types are `String`.
/// - Returns: The aggregated summary value for the specified property across the entire subtree.
public func summary<P: Property>(of property: P.Type) -> [String?] where P.Value == String?, P.Summary == [String?] {
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> [String?] where P.Value == String?, P.Summary == [String?] {
return manager.summary(of: property)
}

Expand All @@ -138,7 +138,7 @@ import Observation
/// - Parameter property: The type of the URL property to summarize. Must be a property
/// where both the value and summary types are `URL?` and `[URL?]` respectively.
/// - Returns: The aggregated summary value for the specified property across the entire subtree.
public func summary<P: Property>(of property: P.Type) -> [URL?] where P.Value == URL?, P.Summary == [URL?] {
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> [URL?] where P.Value == URL?, P.Summary == [URL?] {
return manager.summary(of: property)
}

Expand All @@ -150,7 +150,7 @@ import Observation
/// - Parameter property: The type of the unsigned integer property to summarize. Must be a property
/// where the value type is `UInt64` and the summary type is `[UInt64]`.
/// - Returns: The aggregated summary value for the specified property across the entire subtree.
public func summary<P: Property>(of property: P.Type) -> [UInt64] where P.Value == UInt64, P.Summary == [UInt64] {
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> [UInt64] where P.Value == UInt64, P.Summary == [UInt64] {
return manager.summary(of: property)
}

Expand All @@ -162,7 +162,7 @@ import Observation
/// - Parameter property: The type of the duration property to summarize. Must be a property
/// where both the value and summary types are `Duration`.
/// - Returns: The aggregated summary value for the specified property across the entire subtree.
public func summary<P: Property>(of property: P.Type) -> Duration where P.Value == Duration, P.Summary == Duration {
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> Duration where P.Value == Duration, P.Summary == Duration {
return manager.summary(of: property)
}

Expand Down
Loading