diff --git a/.gitignore b/.gitignore index 49b9f26..dbeb312 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +build/ +Package.resolved .swiftpm rethinkdb_data .DS_Store diff --git a/Package.resolved b/Package.resolved deleted file mode 100644 index 7fc777e..0000000 --- a/Package.resolved +++ /dev/null @@ -1,25 +0,0 @@ -{ - "object": { - "pins": [ - { - "package": "Datable", - "repositoryURL": "https://github.com/OperatorFoundation/Datable", - "state": { - "branch": null, - "revision": "808ab1b2c021be3d2950ec2c2894cd48d532d592", - "version": "3.0.3" - } - }, - { - "package": "swift-ast", - "repositoryURL": "https://github.com/yanagiba/swift-ast", - "state": { - "branch": null, - "revision": "e8507d78b32dbd33ea5ea975bbbc82b7613870a1", - "version": "0.19.9" - } - } - ] - }, - "version": 1 -} diff --git a/Sources/Symphony/Dictionary.swift b/Sources/Symphony/Dictionary.swift index b195ff9..362eae3 100644 --- a/Sources/Symphony/Dictionary.swift +++ b/Sources/Symphony/Dictionary.swift @@ -48,7 +48,7 @@ extension Symphony try FileManager.default.createDirectory(at: seqPath, withIntermediateDirectories: true, attributes: nil) } - let result = ValueDictionary(path: seqPath, relativePath: seqRelPath) + let result = ValueDictionary(symphony: self, path: seqPath, relativePath: seqRelPath) return result } } @@ -117,7 +117,7 @@ extension Symphony let song = SongDecoder() let oldType = try song.decode(ValueType.self, from: data) guard oldType.type == newType else {return nil} - return ValueDictionary(path: seqPath, relativePath: seqRelPath) + return ValueDictionary(symphony: self, path: seqPath, relativePath: seqRelPath) } else { diff --git a/Sources/Symphony/ValueDictionary.swift b/Sources/Symphony/ValueDictionary.swift index ba3d4dc..83ab9ab 100644 --- a/Sources/Symphony/ValueDictionary.swift +++ b/Sources/Symphony/ValueDictionary.swift @@ -7,10 +7,18 @@ import Foundation -public struct ValueDictionary where K: Codable, V: Codable +public struct ValueDictionary where K: Codable, V: Codable, K: CustomStringConvertible { let path: URL let relativePath: URL + let symphony: Symphony + + public init(symphony: Symphony, path: URL, relativePath: URL) + { + self.path = path + self.relativePath = relativePath + self.symphony = symphony + } } extension ValueDictionary @@ -64,43 +72,25 @@ extension ValueDictionary // } //} // -//extension ValueDictionary: Collection, MutableCollection -//{ -// public typealias Index = K -// -// public var startIndex: Index -// { -// return 0 -// } -// -// public var endIndex: Index -// { -// return self.count -// } -// -// public subscript(position: Index) -> V -// { -// get -// { -// let filename = position.string -// let valuePath = self.relativePath.appendingPathComponent(filename) -// let result = Symphony.instance.readValue(type: T.self, at: valuePath) -// return result! -// } -// -// set(newValue) -// { -// let filename = position.string -// let valuePath = self.relativePath.appendingPathComponent(filename) -// let _ = Symphony.instance.writeValue(value: newValue, at: valuePath) -// } -// } -// -// public func index(after i: Index) -> Index -// { -// return i + 1 -// } -//} + +extension ValueDictionary +{ + public func get(_ key: K) -> V? + { + let filename = key.description + let valuePath = self.relativePath.appendingPathComponent(filename) + let result = self.symphony.readValue(type: V.self, at: valuePath) + return result + } + + public func set(_ key: K, _ value: V) -> Bool + { + let filename = key.description + let valuePath = self.relativePath.appendingPathComponent(filename) + return self.symphony.writeValue(value: value, at: valuePath) + } +} + // //extension ValueDictionary: BidirectionalCollection //{