Skip to content

Commit 6df4e75

Browse files
committed
formatting for readability
1 parent 545a9c2 commit 6df4e75

File tree

2 files changed

+120
-114
lines changed

2 files changed

+120
-114
lines changed

Sources/FoundationEssentials/ProgressManager/ProgressManager+Properties+Accessors.swift

Lines changed: 116 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -15,118 +15,7 @@ internal import Synchronization
1515
@available(FoundationPreview 6.2, *)
1616
extension ProgressManager {
1717

18-
/// Returns a summary for the specified integer property across the progress subtree.
19-
///
20-
/// This method aggregates the values of a custom integer property from this progress manager
21-
/// and all its children, returning a consolidated summary value.
22-
///
23-
/// - Parameter property: The type of the integer property to summarize. Must be a property
24-
/// where both the value and summary types are `Int`.
25-
/// - Returns: The aggregated summary value for the specified property across the entire subtree.
26-
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == Int, P.Summary == Int {
27-
return getUpdatedIntSummary(property: MetatypeWrapper(property))
28-
}
29-
30-
/// Returns a summary for the specified double property across the progress subtree.
31-
///
32-
/// This method aggregates the values of a custom double property from this progress manager
33-
/// and all its children, returning a consolidated summary value.
34-
///
35-
/// - Parameter property: The type of the double property to summarize. Must be a property
36-
/// where both the value and summary types are `Double`.
37-
/// - Returns: The aggregated summary value for the specified property across the entire subtree.
38-
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == Double, P.Summary == Double {
39-
return getUpdatedDoubleSummary(property: MetatypeWrapper(property))
40-
}
41-
42-
/// Returns a summary for the specified string property across the progress subtree.
43-
///
44-
/// This method aggregates the values of a custom string property from this progress manager
45-
/// and all its children, returning a consolidated summary value.
46-
///
47-
/// - Parameter property: The type of the string property to summarize. Must be a property
48-
/// where both the value and summary types are `String`.
49-
/// - Returns: The aggregated summary value for the specified property across the entire subtree.
50-
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == String?, P.Summary == [String?] {
51-
return getUpdatedStringSummary(property: MetatypeWrapper(property))
52-
}
53-
54-
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == URL?, P.Summary == [URL?] {
55-
return getUpdatedURLSummary(property: MetatypeWrapper(property))
56-
}
57-
58-
/// Returns the total file count across the progress subtree.
59-
///
60-
/// - Parameter property: The `TotalFileCount` property type.
61-
/// - Returns: The sum of all total file counts across the entire progress subtree.
62-
public func summary(of property: ProgressManager.Properties.TotalFileCount.Type) -> Int {
63-
return getUpdatedFileCount(type: .total)
64-
}
65-
66-
/// Returns the completed file count across the progress subtree.
67-
///
68-
/// - Parameter property: The `CompletedFileCount` property type.
69-
/// - Returns: The sum of all completed file counts across the entire progress subtree.
70-
public func summary(of property: ProgressManager.Properties.CompletedFileCount.Type) -> Int {
71-
return getUpdatedFileCount(type: .completed)
72-
}
73-
74-
/// Returns the total byte count across the progress subtree.
75-
///
76-
/// - Parameter property: The `TotalByteCount` property type.
77-
/// - Returns: The sum of all total byte counts across the entire progress subtree, in bytes.
78-
public func summary(of property: ProgressManager.Properties.TotalByteCount.Type) -> UInt64 {
79-
return getUpdatedByteCount(type: .total)
80-
}
81-
82-
/// Returns the completed byte count across the progress subtree.
83-
///
84-
/// - Parameter property: The `CompletedByteCount` property type.
85-
/// - Returns: The sum of all completed byte counts across the entire progress subtree, in bytes.
86-
public func summary(of property: ProgressManager.Properties.CompletedByteCount.Type) -> UInt64 {
87-
return getUpdatedByteCount(type: .completed)
88-
}
89-
90-
/// Returns the average throughput across the progress subtree.
91-
///
92-
/// - Parameter property: The `Throughput` property type.
93-
/// - Returns: The average throughput across the entire progress subtree, in bytes per second.
94-
///
95-
/// - Note: The throughput is calculated as the sum of all throughput values divided by the count
96-
/// of progress managers that have throughput data.
97-
public func summary(of property: ProgressManager.Properties.Throughput.Type) -> [UInt64] {
98-
return getUpdatedThroughput()
99-
}
100-
101-
/// Returns the maximum estimated time remaining for completion across the progress subtree.
102-
///
103-
/// - Parameter property: The `EstimatedTimeRemaining` property type.
104-
/// - Returns: The estimated duration until completion for the entire progress subtree.
105-
///
106-
/// - Note: The estimation is based on current throughput and remaining work. The accuracy
107-
/// depends on the consistency of the processing rate.
108-
public func summary(of property: ProgressManager.Properties.EstimatedTimeRemaining.Type) -> Duration {
109-
return getUpdatedEstimatedTimeRemaining()
110-
}
111-
112-
/// Returns all file URLs being processed across the progress subtree.
113-
///
114-
/// - Parameter property: The `FileURL` property type.
115-
/// - Returns: An array containing all file URLs across the entire progress subtree.
116-
public func summary(of property: ProgressManager.Properties.FileURL.Type) -> [URL?] {
117-
return getUpdatedFileURL()
118-
}
119-
120-
// MARK: Additional Properties Methods
121-
internal func getProperties<T, E: Error>(
122-
_ closure: (sending Values) throws(E) -> sending T
123-
) throws(E) -> sending T {
124-
try state.withLock { state throws(E) -> T in
125-
let values = Values(state: state)
126-
let result = try closure(values)
127-
return result
128-
}
129-
}
18+
// MARK: Methods to Read & Write Additional Properties of single ProgressManager node
13019

13120
/// Mutates any settable properties that convey information about progress.
13221
public func withProperties<T, E: Error>(
@@ -520,6 +409,7 @@ extension ProgressManager {
520409
dirtyPropertiesURL.append(MetatypeWrapper(P.self))
521410
}
522411
}
412+
523413
#if FOUNDATION_FRAMEWORK
524414
private mutating func interopNotifications() {
525415
switch state.interopType {
@@ -534,4 +424,118 @@ extension ProgressManager {
534424
}
535425
#endif
536426
}
427+
428+
internal func getProperties<T, E: Error>(
429+
_ closure: (sending Values) throws(E) -> sending T
430+
) throws(E) -> sending T {
431+
try state.withLock { state throws(E) -> T in
432+
let values = Values(state: state)
433+
let result = try closure(values)
434+
return result
435+
}
436+
}
437+
438+
// MARK: Methods to Read Additional Properties of Subtree with ProgressManager as root
439+
440+
/// Returns a summary for the specified integer property across the progress subtree.
441+
///
442+
/// This method aggregates the values of a custom integer property from this progress manager
443+
/// and all its children, returning a consolidated summary value.
444+
///
445+
/// - Parameter property: The type of the integer property to summarize. Must be a property
446+
/// where both the value and summary types are `Int`.
447+
/// - Returns: The aggregated summary value for the specified property across the entire subtree.
448+
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == Int, P.Summary == Int {
449+
return getUpdatedIntSummary(property: MetatypeWrapper(property))
450+
}
451+
452+
/// Returns a summary for the specified double property across the progress subtree.
453+
///
454+
/// This method aggregates the values of a custom double property from this progress manager
455+
/// and all its children, returning a consolidated summary value.
456+
///
457+
/// - Parameter property: The type of the double property to summarize. Must be a property
458+
/// where both the value and summary types are `Double`.
459+
/// - Returns: The aggregated summary value for the specified property across the entire subtree.
460+
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == Double, P.Summary == Double {
461+
return getUpdatedDoubleSummary(property: MetatypeWrapper(property))
462+
}
463+
464+
/// Returns a summary for the specified string property across the progress subtree.
465+
///
466+
/// This method aggregates the values of a custom string property from this progress manager
467+
/// and all its children, returning a consolidated summary value.
468+
///
469+
/// - Parameter property: The type of the string property to summarize. Must be a property
470+
/// where both the value and summary types are `String`.
471+
/// - Returns: The aggregated summary value for the specified property across the entire subtree.
472+
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == String?, P.Summary == [String?] {
473+
return getUpdatedStringSummary(property: MetatypeWrapper(property))
474+
}
475+
476+
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == URL?, P.Summary == [URL?] {
477+
return getUpdatedURLSummary(property: MetatypeWrapper(property))
478+
}
479+
480+
/// Returns the total file count across the progress subtree.
481+
///
482+
/// - Parameter property: The `TotalFileCount` property type.
483+
/// - Returns: The sum of all total file counts across the entire progress subtree.
484+
public func summary(of property: ProgressManager.Properties.TotalFileCount.Type) -> Int {
485+
return getUpdatedFileCount(type: .total)
486+
}
487+
488+
/// Returns the completed file count across the progress subtree.
489+
///
490+
/// - Parameter property: The `CompletedFileCount` property type.
491+
/// - Returns: The sum of all completed file counts across the entire progress subtree.
492+
public func summary(of property: ProgressManager.Properties.CompletedFileCount.Type) -> Int {
493+
return getUpdatedFileCount(type: .completed)
494+
}
495+
496+
/// Returns the total byte count across the progress subtree.
497+
///
498+
/// - Parameter property: The `TotalByteCount` property type.
499+
/// - Returns: The sum of all total byte counts across the entire progress subtree, in bytes.
500+
public func summary(of property: ProgressManager.Properties.TotalByteCount.Type) -> UInt64 {
501+
return getUpdatedByteCount(type: .total)
502+
}
503+
504+
/// Returns the completed byte count across the progress subtree.
505+
///
506+
/// - Parameter property: The `CompletedByteCount` property type.
507+
/// - Returns: The sum of all completed byte counts across the entire progress subtree, in bytes.
508+
public func summary(of property: ProgressManager.Properties.CompletedByteCount.Type) -> UInt64 {
509+
return getUpdatedByteCount(type: .completed)
510+
}
511+
512+
/// Returns the average throughput across the progress subtree.
513+
///
514+
/// - Parameter property: The `Throughput` property type.
515+
/// - Returns: The average throughput across the entire progress subtree, in bytes per second.
516+
///
517+
/// - Note: The throughput is calculated as the sum of all throughput values divided by the count
518+
/// of progress managers that have throughput data.
519+
public func summary(of property: ProgressManager.Properties.Throughput.Type) -> [UInt64] {
520+
return getUpdatedThroughput()
521+
}
522+
523+
/// Returns the maximum estimated time remaining for completion across the progress subtree.
524+
///
525+
/// - Parameter property: The `EstimatedTimeRemaining` property type.
526+
/// - Returns: The estimated duration until completion for the entire progress subtree.
527+
///
528+
/// - Note: The estimation is based on current throughput and remaining work. The accuracy
529+
/// depends on the consistency of the processing rate.
530+
public func summary(of property: ProgressManager.Properties.EstimatedTimeRemaining.Type) -> Duration {
531+
return getUpdatedEstimatedTimeRemaining()
532+
}
533+
534+
/// Returns all file URLs being processed across the progress subtree.
535+
///
536+
/// - Parameter property: The `FileURL` property type.
537+
/// - Returns: An array containing all file URLs across the entire progress subtree.
538+
public func summary(of property: ProgressManager.Properties.FileURL.Type) -> [URL?] {
539+
return getUpdatedFileURL()
540+
}
537541
}

Sources/FoundationEssentials/ProgressManager/ProgressManager+Properties+Helpers.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ extension ProgressManager {
1919
case completed
2020
}
2121

22-
//MARK: Methods to get updated summary of properties
22+
//MARK: Helper Methods for Updating Dirty Path
23+
2324
internal func getUpdatedIntSummary(property: MetatypeWrapper<Int, Int>) -> Int {
2425
return state.withLock { state in
2526

@@ -416,7 +417,8 @@ extension ProgressManager {
416417
}
417418
}
418419

419-
//MARK: Methods to set dirty bit recursively
420+
//MARK: Helper Methods for Setting Dirty Paths
421+
420422
internal func markSelfDirty(property: MetatypeWrapper<Int, Int>, parents: [ParentState]) {
421423
for parentState in parents {
422424
parentState.parent.markChildDirty(property: property, at: parentState.positionInParent)

0 commit comments

Comments
 (0)