diff --git a/DapCore/context/Property.swift b/DapCore/context/Property.swift index 4c74d1f..96bbe3a 100644 --- a/DapCore/context/Property.swift +++ b/DapCore/context/Property.swift @@ -20,656 +20,812 @@ public protocol Property: Var { } //SILP: PROPERTY_CLASS(Bool, Bool) -public protocol BoolValueChecker : class { //__SILP__ - func isValid(propertyPath: String, value: Bool?, newValue: Bool?) -> Bool //__SILP__ -} //__SILP__ - //__SILP__ -public protocol BoolValueWatcher : class { //__SILP__ - func onChanged(propertyPath: String, lastValue: Bool?, value: Bool?) -> Void //__SILP__ -} //__SILP__ - //__SILP__ -public class BoolProperty : BoolVar, Property { //__SILP__ - public typealias ValueChecker = BoolValueChecker //__SILP__ - public typealias ValueWatcher = BoolValueWatcher //__SILP__ - //__SILP__ - public override var type: String? { //__SILP__ - return Properties.Consts.TypeBoolProperty //__SILP__ - } //__SILP__ - //__SILP__ - public required init(entity: Entity, path: String) { //__SILP__ - super.init(entity: entity, path: path) //__SILP__ - } //__SILP__ - //__SILP__ - private var _checkers = [ValueChecker]() //__SILP__ - private var _watchers = [ValueWatcher]() //__SILP__ - //__SILP__ - private func getIndexOfValueChecker(checker: ValueChecker) -> Int? { //__SILP__ - for (i, obj) in enumerate(_checkers) { //__SILP__ - if obj === checker { //__SILP__ - return i //__SILP__ - } //__SILP__ - } //__SILP__ - return nil //__SILP__ - } //__SILP__ - //__SILP__ - public final func addValueChecker(checker: ValueChecker) -> Bool { //__SILP__ - if getIndexOfValueChecker(checker) == nil { //__SILP__ - _checkers.append(checker) //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - public final func removeValueChecker(checker: ValueChecker) -> Bool { //__SILP__ - if let index = getIndexOfValueChecker(checker) { //__SILP__ - _checkers.removeAtIndex(index) //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - private func getIndexOfValueWatcher(watcher: ValueWatcher) -> Int? { //__SILP__ - for (i, obj) in enumerate(_watchers) { //__SILP__ - if obj === watcher { //__SILP__ - return i //__SILP__ - } //__SILP__ - } //__SILP__ - return nil //__SILP__ - } //__SILP__ - //__SILP__ - public final func addValueWatcher(watcher: ValueWatcher) -> Bool { //__SILP__ - if getIndexOfValueWatcher(watcher) == nil { //__SILP__ - _watchers.append(watcher) //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - public final func removeValueWatcher(watcher: ValueWatcher) -> Bool { //__SILP__ - if let index = getIndexOfValueWatcher(watcher) { //__SILP__ - _watchers.removeAtIndex(index) //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - private var _checkingValue = false //__SILP__ - private var _updatingValue = false //__SILP__ - //__SILP__ - public override func setValue(newValue: Bool?) -> Bool { //__SILP__ - if _checkingValue { return false } //__SILP__ - if _updatingValue { return false } //__SILP__ - //__SILP__ - if (value != newValue) { //__SILP__ - _checkingValue = true //__SILP__ - for checker in _checkers { //__SILP__ - if !checker.isValid(path, value: value, newValue: newValue) { //__SILP__ - _checkingValue = false //__SILP__ - return false //__SILP__ - } //__SILP__ - } //__SILP__ - _checkingValue = false //__SILP__ - //__SILP__ - _updatingValue = true //__SILP__ - let lastValue = value //__SILP__ - //__SILP__ - if (!super.setValue(newValue)) { //__SILP__ - _updatingValue = false //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - for watcher in _watchers { //__SILP__ - watcher.onChanged(path, lastValue: lastValue, value: value) //__SILP__ - } //__SILP__ - _updatingValue = false //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ -} //__SILP__ - //__SILP__ +public protocol BoolValueChecker : class { //__SILP__ + func isValid(propertyPath: String, value: Bool?, newValue: Bool?) -> Bool //__SILP__ +} //__SILP__ + //__SILP__ +public protocol BoolValueWatcher : class { //__SILP__ + func onChanged(propertyPath: String, lastValue: Bool?, value: Bool?) -> Void //__SILP__ +} //__SILP__ + //__SILP__ +public final class BlockBoolValueChecker : BoolValueChecker { //__SILP__ + public typealias CheckerBlock = (String, Bool?, Bool?) -> Bool //__SILP__ + private let block: CheckerBlock //__SILP__ + //__SILP__ + public init(block: CheckerBlock) { //__SILP__ + self.block = block //__SILP__ + } //__SILP__ + //__SILP__ + public func isValid(propertyPath: String, value: Bool?, newValue: Bool?) -> Bool { //__SILP__ + return block(propertyPath, value, newValue) //__SILP__ + } //__SILP__ +} //__SILP__ + //__SILP__ +public final class BlockBoolValueWatcher : BoolValueWatcher { //__SILP__ + public typealias WatcherBlock = (String, Bool?, Bool?) -> Void //__SILP__ + private let block: WatcherBlock //__SILP__ + //__SILP__ + public init(block: WatcherBlock) { //__SILP__ + self.block = block //__SILP__ + } //__SILP__ + //__SILP__ + public func onChanged(propertyPath: String, lastValue: Bool?, value: Bool?) -> Void { //__SILP__ + block(propertyPath, lastValue, value) //__SILP__ + } //__SILP__ +} //__SILP__ + //__SILP__ +public class BoolProperty : BoolVar, Property { //__SILP__ + public typealias ValueChecker = BoolValueChecker //__SILP__ + public typealias ValueWatcher = BoolValueWatcher //__SILP__ + //__SILP__ + public override var type: String? { //__SILP__ + return Properties.Consts.TypeBoolProperty //__SILP__ + } //__SILP__ + //__SILP__ + public required init(entity: Entity, path: String) { //__SILP__ + super.init(entity: entity, path: path) //__SILP__ + } //__SILP__ + //__SILP__ + private var _checkers = [ValueChecker]() //__SILP__ + private var _watchers = [ValueWatcher]() //__SILP__ + //__SILP__ + private func getIndexOfValueChecker(checker: ValueChecker) -> Int? { //__SILP__ + for (i, obj) in enumerate(_checkers) { //__SILP__ + if obj === checker { //__SILP__ + return i //__SILP__ + } //__SILP__ + } //__SILP__ + return nil //__SILP__ + } //__SILP__ + //__SILP__ + public final func addValueChecker(checker: ValueChecker) -> Bool { //__SILP__ + if getIndexOfValueChecker(checker) == nil { //__SILP__ + _checkers.append(checker) //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + public final func removeValueChecker(checker: ValueChecker) -> Bool { //__SILP__ + if let index = getIndexOfValueChecker(checker) { //__SILP__ + _checkers.removeAtIndex(index) //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + private func getIndexOfValueWatcher(watcher: ValueWatcher) -> Int? { //__SILP__ + for (i, obj) in enumerate(_watchers) { //__SILP__ + if obj === watcher { //__SILP__ + return i //__SILP__ + } //__SILP__ + } //__SILP__ + return nil //__SILP__ + } //__SILP__ + //__SILP__ + public final func addValueWatcher(watcher: ValueWatcher) -> Bool { //__SILP__ + if getIndexOfValueWatcher(watcher) == nil { //__SILP__ + _watchers.append(watcher) //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + public final func removeValueWatcher(watcher: ValueWatcher) -> Bool { //__SILP__ + if let index = getIndexOfValueWatcher(watcher) { //__SILP__ + _watchers.removeAtIndex(index) //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + private var _checkingValue = false //__SILP__ + private var _updatingValue = false //__SILP__ + //__SILP__ + public override func setValue(newValue: Bool?) -> Bool { //__SILP__ + if _checkingValue { return false } //__SILP__ + if _updatingValue { return false } //__SILP__ + //__SILP__ + if (value != newValue) { //__SILP__ + _checkingValue = true //__SILP__ + for checker in _checkers { //__SILP__ + if !checker.isValid(path, value: value, newValue: newValue) { //__SILP__ + _checkingValue = false //__SILP__ + return false //__SILP__ + } //__SILP__ + } //__SILP__ + _checkingValue = false //__SILP__ + //__SILP__ + _updatingValue = true //__SILP__ + let lastValue = value //__SILP__ + //__SILP__ + if (!super.setValue(newValue)) { //__SILP__ + _updatingValue = false //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + for watcher in _watchers { //__SILP__ + watcher.onChanged(path, lastValue: lastValue, value: value) //__SILP__ + } //__SILP__ + _updatingValue = false //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ +} //__SILP__ + //__SILP__ //SILP: PROPERTY_CLASS(Int, Int32) -public protocol IntValueChecker : class { //__SILP__ - func isValid(propertyPath: String, value: Int32?, newValue: Int32?) -> Bool //__SILP__ -} //__SILP__ - //__SILP__ -public protocol IntValueWatcher : class { //__SILP__ - func onChanged(propertyPath: String, lastValue: Int32?, value: Int32?) -> Void //__SILP__ -} //__SILP__ - //__SILP__ -public class IntProperty : IntVar, Property { //__SILP__ - public typealias ValueChecker = IntValueChecker //__SILP__ - public typealias ValueWatcher = IntValueWatcher //__SILP__ - //__SILP__ - public override var type: String? { //__SILP__ - return Properties.Consts.TypeIntProperty //__SILP__ - } //__SILP__ - //__SILP__ - public required init(entity: Entity, path: String) { //__SILP__ - super.init(entity: entity, path: path) //__SILP__ - } //__SILP__ - //__SILP__ - private var _checkers = [ValueChecker]() //__SILP__ - private var _watchers = [ValueWatcher]() //__SILP__ - //__SILP__ - private func getIndexOfValueChecker(checker: ValueChecker) -> Int? { //__SILP__ - for (i, obj) in enumerate(_checkers) { //__SILP__ - if obj === checker { //__SILP__ - return i //__SILP__ - } //__SILP__ - } //__SILP__ - return nil //__SILP__ - } //__SILP__ - //__SILP__ - public final func addValueChecker(checker: ValueChecker) -> Bool { //__SILP__ - if getIndexOfValueChecker(checker) == nil { //__SILP__ - _checkers.append(checker) //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - public final func removeValueChecker(checker: ValueChecker) -> Bool { //__SILP__ - if let index = getIndexOfValueChecker(checker) { //__SILP__ - _checkers.removeAtIndex(index) //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - private func getIndexOfValueWatcher(watcher: ValueWatcher) -> Int? { //__SILP__ - for (i, obj) in enumerate(_watchers) { //__SILP__ - if obj === watcher { //__SILP__ - return i //__SILP__ - } //__SILP__ - } //__SILP__ - return nil //__SILP__ - } //__SILP__ - //__SILP__ - public final func addValueWatcher(watcher: ValueWatcher) -> Bool { //__SILP__ - if getIndexOfValueWatcher(watcher) == nil { //__SILP__ - _watchers.append(watcher) //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - public final func removeValueWatcher(watcher: ValueWatcher) -> Bool { //__SILP__ - if let index = getIndexOfValueWatcher(watcher) { //__SILP__ - _watchers.removeAtIndex(index) //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - private var _checkingValue = false //__SILP__ - private var _updatingValue = false //__SILP__ - //__SILP__ - public override func setValue(newValue: Int32?) -> Bool { //__SILP__ - if _checkingValue { return false } //__SILP__ - if _updatingValue { return false } //__SILP__ - //__SILP__ - if (value != newValue) { //__SILP__ - _checkingValue = true //__SILP__ - for checker in _checkers { //__SILP__ - if !checker.isValid(path, value: value, newValue: newValue) { //__SILP__ - _checkingValue = false //__SILP__ - return false //__SILP__ - } //__SILP__ - } //__SILP__ - _checkingValue = false //__SILP__ - //__SILP__ - _updatingValue = true //__SILP__ - let lastValue = value //__SILP__ - //__SILP__ - if (!super.setValue(newValue)) { //__SILP__ - _updatingValue = false //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - for watcher in _watchers { //__SILP__ - watcher.onChanged(path, lastValue: lastValue, value: value) //__SILP__ - } //__SILP__ - _updatingValue = false //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ -} //__SILP__ - //__SILP__ +public protocol IntValueChecker : class { //__SILP__ + func isValid(propertyPath: String, value: Int32?, newValue: Int32?) -> Bool //__SILP__ +} //__SILP__ + //__SILP__ +public protocol IntValueWatcher : class { //__SILP__ + func onChanged(propertyPath: String, lastValue: Int32?, value: Int32?) -> Void //__SILP__ +} //__SILP__ + //__SILP__ +public final class BlockIntValueChecker : IntValueChecker { //__SILP__ + public typealias CheckerBlock = (String, Int32?, Int32?) -> Bool //__SILP__ + private let block: CheckerBlock //__SILP__ + //__SILP__ + public init(block: CheckerBlock) { //__SILP__ + self.block = block //__SILP__ + } //__SILP__ + //__SILP__ + public func isValid(propertyPath: String, value: Int32?, newValue: Int32?) -> Bool { //__SILP__ + return block(propertyPath, value, newValue) //__SILP__ + } //__SILP__ +} //__SILP__ + //__SILP__ +public final class BlockIntValueWatcher : IntValueWatcher { //__SILP__ + public typealias WatcherBlock = (String, Int32?, Int32?) -> Void //__SILP__ + private let block: WatcherBlock //__SILP__ + //__SILP__ + public init(block: WatcherBlock) { //__SILP__ + self.block = block //__SILP__ + } //__SILP__ + //__SILP__ + public func onChanged(propertyPath: String, lastValue: Int32?, value: Int32?) -> Void { //__SILP__ + block(propertyPath, lastValue, value) //__SILP__ + } //__SILP__ +} //__SILP__ + //__SILP__ +public class IntProperty : IntVar, Property { //__SILP__ + public typealias ValueChecker = IntValueChecker //__SILP__ + public typealias ValueWatcher = IntValueWatcher //__SILP__ + //__SILP__ + public override var type: String? { //__SILP__ + return Properties.Consts.TypeIntProperty //__SILP__ + } //__SILP__ + //__SILP__ + public required init(entity: Entity, path: String) { //__SILP__ + super.init(entity: entity, path: path) //__SILP__ + } //__SILP__ + //__SILP__ + private var _checkers = [ValueChecker]() //__SILP__ + private var _watchers = [ValueWatcher]() //__SILP__ + //__SILP__ + private func getIndexOfValueChecker(checker: ValueChecker) -> Int? { //__SILP__ + for (i, obj) in enumerate(_checkers) { //__SILP__ + if obj === checker { //__SILP__ + return i //__SILP__ + } //__SILP__ + } //__SILP__ + return nil //__SILP__ + } //__SILP__ + //__SILP__ + public final func addValueChecker(checker: ValueChecker) -> Bool { //__SILP__ + if getIndexOfValueChecker(checker) == nil { //__SILP__ + _checkers.append(checker) //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + public final func removeValueChecker(checker: ValueChecker) -> Bool { //__SILP__ + if let index = getIndexOfValueChecker(checker) { //__SILP__ + _checkers.removeAtIndex(index) //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + private func getIndexOfValueWatcher(watcher: ValueWatcher) -> Int? { //__SILP__ + for (i, obj) in enumerate(_watchers) { //__SILP__ + if obj === watcher { //__SILP__ + return i //__SILP__ + } //__SILP__ + } //__SILP__ + return nil //__SILP__ + } //__SILP__ + //__SILP__ + public final func addValueWatcher(watcher: ValueWatcher) -> Bool { //__SILP__ + if getIndexOfValueWatcher(watcher) == nil { //__SILP__ + _watchers.append(watcher) //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + public final func removeValueWatcher(watcher: ValueWatcher) -> Bool { //__SILP__ + if let index = getIndexOfValueWatcher(watcher) { //__SILP__ + _watchers.removeAtIndex(index) //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + private var _checkingValue = false //__SILP__ + private var _updatingValue = false //__SILP__ + //__SILP__ + public override func setValue(newValue: Int32?) -> Bool { //__SILP__ + if _checkingValue { return false } //__SILP__ + if _updatingValue { return false } //__SILP__ + //__SILP__ + if (value != newValue) { //__SILP__ + _checkingValue = true //__SILP__ + for checker in _checkers { //__SILP__ + if !checker.isValid(path, value: value, newValue: newValue) { //__SILP__ + _checkingValue = false //__SILP__ + return false //__SILP__ + } //__SILP__ + } //__SILP__ + _checkingValue = false //__SILP__ + //__SILP__ + _updatingValue = true //__SILP__ + let lastValue = value //__SILP__ + //__SILP__ + if (!super.setValue(newValue)) { //__SILP__ + _updatingValue = false //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + for watcher in _watchers { //__SILP__ + watcher.onChanged(path, lastValue: lastValue, value: value) //__SILP__ + } //__SILP__ + _updatingValue = false //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ +} //__SILP__ + //__SILP__ //SILP: PROPERTY_CLASS(Long, Int64) -public protocol LongValueChecker : class { //__SILP__ - func isValid(propertyPath: String, value: Int64?, newValue: Int64?) -> Bool //__SILP__ -} //__SILP__ - //__SILP__ -public protocol LongValueWatcher : class { //__SILP__ - func onChanged(propertyPath: String, lastValue: Int64?, value: Int64?) -> Void //__SILP__ -} //__SILP__ - //__SILP__ -public class LongProperty : LongVar, Property { //__SILP__ - public typealias ValueChecker = LongValueChecker //__SILP__ - public typealias ValueWatcher = LongValueWatcher //__SILP__ - //__SILP__ - public override var type: String? { //__SILP__ - return Properties.Consts.TypeLongProperty //__SILP__ - } //__SILP__ - //__SILP__ - public required init(entity: Entity, path: String) { //__SILP__ - super.init(entity: entity, path: path) //__SILP__ - } //__SILP__ - //__SILP__ - private var _checkers = [ValueChecker]() //__SILP__ - private var _watchers = [ValueWatcher]() //__SILP__ - //__SILP__ - private func getIndexOfValueChecker(checker: ValueChecker) -> Int? { //__SILP__ - for (i, obj) in enumerate(_checkers) { //__SILP__ - if obj === checker { //__SILP__ - return i //__SILP__ - } //__SILP__ - } //__SILP__ - return nil //__SILP__ - } //__SILP__ - //__SILP__ - public final func addValueChecker(checker: ValueChecker) -> Bool { //__SILP__ - if getIndexOfValueChecker(checker) == nil { //__SILP__ - _checkers.append(checker) //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - public final func removeValueChecker(checker: ValueChecker) -> Bool { //__SILP__ - if let index = getIndexOfValueChecker(checker) { //__SILP__ - _checkers.removeAtIndex(index) //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - private func getIndexOfValueWatcher(watcher: ValueWatcher) -> Int? { //__SILP__ - for (i, obj) in enumerate(_watchers) { //__SILP__ - if obj === watcher { //__SILP__ - return i //__SILP__ - } //__SILP__ - } //__SILP__ - return nil //__SILP__ - } //__SILP__ - //__SILP__ - public final func addValueWatcher(watcher: ValueWatcher) -> Bool { //__SILP__ - if getIndexOfValueWatcher(watcher) == nil { //__SILP__ - _watchers.append(watcher) //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - public final func removeValueWatcher(watcher: ValueWatcher) -> Bool { //__SILP__ - if let index = getIndexOfValueWatcher(watcher) { //__SILP__ - _watchers.removeAtIndex(index) //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - private var _checkingValue = false //__SILP__ - private var _updatingValue = false //__SILP__ - //__SILP__ - public override func setValue(newValue: Int64?) -> Bool { //__SILP__ - if _checkingValue { return false } //__SILP__ - if _updatingValue { return false } //__SILP__ - //__SILP__ - if (value != newValue) { //__SILP__ - _checkingValue = true //__SILP__ - for checker in _checkers { //__SILP__ - if !checker.isValid(path, value: value, newValue: newValue) { //__SILP__ - _checkingValue = false //__SILP__ - return false //__SILP__ - } //__SILP__ - } //__SILP__ - _checkingValue = false //__SILP__ - //__SILP__ - _updatingValue = true //__SILP__ - let lastValue = value //__SILP__ - //__SILP__ - if (!super.setValue(newValue)) { //__SILP__ - _updatingValue = false //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - for watcher in _watchers { //__SILP__ - watcher.onChanged(path, lastValue: lastValue, value: value) //__SILP__ - } //__SILP__ - _updatingValue = false //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ -} //__SILP__ - //__SILP__ +public protocol LongValueChecker : class { //__SILP__ + func isValid(propertyPath: String, value: Int64?, newValue: Int64?) -> Bool //__SILP__ +} //__SILP__ + //__SILP__ +public protocol LongValueWatcher : class { //__SILP__ + func onChanged(propertyPath: String, lastValue: Int64?, value: Int64?) -> Void //__SILP__ +} //__SILP__ + //__SILP__ +public final class BlockLongValueChecker : LongValueChecker { //__SILP__ + public typealias CheckerBlock = (String, Int64?, Int64?) -> Bool //__SILP__ + private let block: CheckerBlock //__SILP__ + //__SILP__ + public init(block: CheckerBlock) { //__SILP__ + self.block = block //__SILP__ + } //__SILP__ + //__SILP__ + public func isValid(propertyPath: String, value: Int64?, newValue: Int64?) -> Bool { //__SILP__ + return block(propertyPath, value, newValue) //__SILP__ + } //__SILP__ +} //__SILP__ + //__SILP__ +public final class BlockLongValueWatcher : LongValueWatcher { //__SILP__ + public typealias WatcherBlock = (String, Int64?, Int64?) -> Void //__SILP__ + private let block: WatcherBlock //__SILP__ + //__SILP__ + public init(block: WatcherBlock) { //__SILP__ + self.block = block //__SILP__ + } //__SILP__ + //__SILP__ + public func onChanged(propertyPath: String, lastValue: Int64?, value: Int64?) -> Void { //__SILP__ + block(propertyPath, lastValue, value) //__SILP__ + } //__SILP__ +} //__SILP__ + //__SILP__ +public class LongProperty : LongVar, Property { //__SILP__ + public typealias ValueChecker = LongValueChecker //__SILP__ + public typealias ValueWatcher = LongValueWatcher //__SILP__ + //__SILP__ + public override var type: String? { //__SILP__ + return Properties.Consts.TypeLongProperty //__SILP__ + } //__SILP__ + //__SILP__ + public required init(entity: Entity, path: String) { //__SILP__ + super.init(entity: entity, path: path) //__SILP__ + } //__SILP__ + //__SILP__ + private var _checkers = [ValueChecker]() //__SILP__ + private var _watchers = [ValueWatcher]() //__SILP__ + //__SILP__ + private func getIndexOfValueChecker(checker: ValueChecker) -> Int? { //__SILP__ + for (i, obj) in enumerate(_checkers) { //__SILP__ + if obj === checker { //__SILP__ + return i //__SILP__ + } //__SILP__ + } //__SILP__ + return nil //__SILP__ + } //__SILP__ + //__SILP__ + public final func addValueChecker(checker: ValueChecker) -> Bool { //__SILP__ + if getIndexOfValueChecker(checker) == nil { //__SILP__ + _checkers.append(checker) //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + public final func removeValueChecker(checker: ValueChecker) -> Bool { //__SILP__ + if let index = getIndexOfValueChecker(checker) { //__SILP__ + _checkers.removeAtIndex(index) //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + private func getIndexOfValueWatcher(watcher: ValueWatcher) -> Int? { //__SILP__ + for (i, obj) in enumerate(_watchers) { //__SILP__ + if obj === watcher { //__SILP__ + return i //__SILP__ + } //__SILP__ + } //__SILP__ + return nil //__SILP__ + } //__SILP__ + //__SILP__ + public final func addValueWatcher(watcher: ValueWatcher) -> Bool { //__SILP__ + if getIndexOfValueWatcher(watcher) == nil { //__SILP__ + _watchers.append(watcher) //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + public final func removeValueWatcher(watcher: ValueWatcher) -> Bool { //__SILP__ + if let index = getIndexOfValueWatcher(watcher) { //__SILP__ + _watchers.removeAtIndex(index) //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + private var _checkingValue = false //__SILP__ + private var _updatingValue = false //__SILP__ + //__SILP__ + public override func setValue(newValue: Int64?) -> Bool { //__SILP__ + if _checkingValue { return false } //__SILP__ + if _updatingValue { return false } //__SILP__ + //__SILP__ + if (value != newValue) { //__SILP__ + _checkingValue = true //__SILP__ + for checker in _checkers { //__SILP__ + if !checker.isValid(path, value: value, newValue: newValue) { //__SILP__ + _checkingValue = false //__SILP__ + return false //__SILP__ + } //__SILP__ + } //__SILP__ + _checkingValue = false //__SILP__ + //__SILP__ + _updatingValue = true //__SILP__ + let lastValue = value //__SILP__ + //__SILP__ + if (!super.setValue(newValue)) { //__SILP__ + _updatingValue = false //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + for watcher in _watchers { //__SILP__ + watcher.onChanged(path, lastValue: lastValue, value: value) //__SILP__ + } //__SILP__ + _updatingValue = false //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ +} //__SILP__ + //__SILP__ //SILP: PROPERTY_CLASS(Float, Float) -public protocol FloatValueChecker : class { //__SILP__ - func isValid(propertyPath: String, value: Float?, newValue: Float?) -> Bool //__SILP__ -} //__SILP__ - //__SILP__ -public protocol FloatValueWatcher : class { //__SILP__ - func onChanged(propertyPath: String, lastValue: Float?, value: Float?) -> Void //__SILP__ -} //__SILP__ - //__SILP__ -public class FloatProperty : FloatVar, Property { //__SILP__ - public typealias ValueChecker = FloatValueChecker //__SILP__ - public typealias ValueWatcher = FloatValueWatcher //__SILP__ - //__SILP__ - public override var type: String? { //__SILP__ - return Properties.Consts.TypeFloatProperty //__SILP__ - } //__SILP__ - //__SILP__ - public required init(entity: Entity, path: String) { //__SILP__ - super.init(entity: entity, path: path) //__SILP__ - } //__SILP__ - //__SILP__ - private var _checkers = [ValueChecker]() //__SILP__ - private var _watchers = [ValueWatcher]() //__SILP__ - //__SILP__ - private func getIndexOfValueChecker(checker: ValueChecker) -> Int? { //__SILP__ - for (i, obj) in enumerate(_checkers) { //__SILP__ - if obj === checker { //__SILP__ - return i //__SILP__ - } //__SILP__ - } //__SILP__ - return nil //__SILP__ - } //__SILP__ - //__SILP__ - public final func addValueChecker(checker: ValueChecker) -> Bool { //__SILP__ - if getIndexOfValueChecker(checker) == nil { //__SILP__ - _checkers.append(checker) //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - public final func removeValueChecker(checker: ValueChecker) -> Bool { //__SILP__ - if let index = getIndexOfValueChecker(checker) { //__SILP__ - _checkers.removeAtIndex(index) //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - private func getIndexOfValueWatcher(watcher: ValueWatcher) -> Int? { //__SILP__ - for (i, obj) in enumerate(_watchers) { //__SILP__ - if obj === watcher { //__SILP__ - return i //__SILP__ - } //__SILP__ - } //__SILP__ - return nil //__SILP__ - } //__SILP__ - //__SILP__ - public final func addValueWatcher(watcher: ValueWatcher) -> Bool { //__SILP__ - if getIndexOfValueWatcher(watcher) == nil { //__SILP__ - _watchers.append(watcher) //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - public final func removeValueWatcher(watcher: ValueWatcher) -> Bool { //__SILP__ - if let index = getIndexOfValueWatcher(watcher) { //__SILP__ - _watchers.removeAtIndex(index) //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - private var _checkingValue = false //__SILP__ - private var _updatingValue = false //__SILP__ - //__SILP__ - public override func setValue(newValue: Float?) -> Bool { //__SILP__ - if _checkingValue { return false } //__SILP__ - if _updatingValue { return false } //__SILP__ - //__SILP__ - if (value != newValue) { //__SILP__ - _checkingValue = true //__SILP__ - for checker in _checkers { //__SILP__ - if !checker.isValid(path, value: value, newValue: newValue) { //__SILP__ - _checkingValue = false //__SILP__ - return false //__SILP__ - } //__SILP__ - } //__SILP__ - _checkingValue = false //__SILP__ - //__SILP__ - _updatingValue = true //__SILP__ - let lastValue = value //__SILP__ - //__SILP__ - if (!super.setValue(newValue)) { //__SILP__ - _updatingValue = false //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - for watcher in _watchers { //__SILP__ - watcher.onChanged(path, lastValue: lastValue, value: value) //__SILP__ - } //__SILP__ - _updatingValue = false //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ -} //__SILP__ - //__SILP__ +public protocol FloatValueChecker : class { //__SILP__ + func isValid(propertyPath: String, value: Float?, newValue: Float?) -> Bool //__SILP__ +} //__SILP__ + //__SILP__ +public protocol FloatValueWatcher : class { //__SILP__ + func onChanged(propertyPath: String, lastValue: Float?, value: Float?) -> Void //__SILP__ +} //__SILP__ + //__SILP__ +public final class BlockFloatValueChecker : FloatValueChecker { //__SILP__ + public typealias CheckerBlock = (String, Float?, Float?) -> Bool //__SILP__ + private let block: CheckerBlock //__SILP__ + //__SILP__ + public init(block: CheckerBlock) { //__SILP__ + self.block = block //__SILP__ + } //__SILP__ + //__SILP__ + public func isValid(propertyPath: String, value: Float?, newValue: Float?) -> Bool { //__SILP__ + return block(propertyPath, value, newValue) //__SILP__ + } //__SILP__ +} //__SILP__ + //__SILP__ +public final class BlockFloatValueWatcher : FloatValueWatcher { //__SILP__ + public typealias WatcherBlock = (String, Float?, Float?) -> Void //__SILP__ + private let block: WatcherBlock //__SILP__ + //__SILP__ + public init(block: WatcherBlock) { //__SILP__ + self.block = block //__SILP__ + } //__SILP__ + //__SILP__ + public func onChanged(propertyPath: String, lastValue: Float?, value: Float?) -> Void { //__SILP__ + block(propertyPath, lastValue, value) //__SILP__ + } //__SILP__ +} //__SILP__ + //__SILP__ +public class FloatProperty : FloatVar, Property { //__SILP__ + public typealias ValueChecker = FloatValueChecker //__SILP__ + public typealias ValueWatcher = FloatValueWatcher //__SILP__ + //__SILP__ + public override var type: String? { //__SILP__ + return Properties.Consts.TypeFloatProperty //__SILP__ + } //__SILP__ + //__SILP__ + public required init(entity: Entity, path: String) { //__SILP__ + super.init(entity: entity, path: path) //__SILP__ + } //__SILP__ + //__SILP__ + private var _checkers = [ValueChecker]() //__SILP__ + private var _watchers = [ValueWatcher]() //__SILP__ + //__SILP__ + private func getIndexOfValueChecker(checker: ValueChecker) -> Int? { //__SILP__ + for (i, obj) in enumerate(_checkers) { //__SILP__ + if obj === checker { //__SILP__ + return i //__SILP__ + } //__SILP__ + } //__SILP__ + return nil //__SILP__ + } //__SILP__ + //__SILP__ + public final func addValueChecker(checker: ValueChecker) -> Bool { //__SILP__ + if getIndexOfValueChecker(checker) == nil { //__SILP__ + _checkers.append(checker) //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + public final func removeValueChecker(checker: ValueChecker) -> Bool { //__SILP__ + if let index = getIndexOfValueChecker(checker) { //__SILP__ + _checkers.removeAtIndex(index) //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + private func getIndexOfValueWatcher(watcher: ValueWatcher) -> Int? { //__SILP__ + for (i, obj) in enumerate(_watchers) { //__SILP__ + if obj === watcher { //__SILP__ + return i //__SILP__ + } //__SILP__ + } //__SILP__ + return nil //__SILP__ + } //__SILP__ + //__SILP__ + public final func addValueWatcher(watcher: ValueWatcher) -> Bool { //__SILP__ + if getIndexOfValueWatcher(watcher) == nil { //__SILP__ + _watchers.append(watcher) //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + public final func removeValueWatcher(watcher: ValueWatcher) -> Bool { //__SILP__ + if let index = getIndexOfValueWatcher(watcher) { //__SILP__ + _watchers.removeAtIndex(index) //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + private var _checkingValue = false //__SILP__ + private var _updatingValue = false //__SILP__ + //__SILP__ + public override func setValue(newValue: Float?) -> Bool { //__SILP__ + if _checkingValue { return false } //__SILP__ + if _updatingValue { return false } //__SILP__ + //__SILP__ + if (value != newValue) { //__SILP__ + _checkingValue = true //__SILP__ + for checker in _checkers { //__SILP__ + if !checker.isValid(path, value: value, newValue: newValue) { //__SILP__ + _checkingValue = false //__SILP__ + return false //__SILP__ + } //__SILP__ + } //__SILP__ + _checkingValue = false //__SILP__ + //__SILP__ + _updatingValue = true //__SILP__ + let lastValue = value //__SILP__ + //__SILP__ + if (!super.setValue(newValue)) { //__SILP__ + _updatingValue = false //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + for watcher in _watchers { //__SILP__ + watcher.onChanged(path, lastValue: lastValue, value: value) //__SILP__ + } //__SILP__ + _updatingValue = false //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ +} //__SILP__ + //__SILP__ //SILP: PROPERTY_CLASS(Double, Double) -public protocol DoubleValueChecker : class { //__SILP__ - func isValid(propertyPath: String, value: Double?, newValue: Double?) -> Bool //__SILP__ -} //__SILP__ - //__SILP__ -public protocol DoubleValueWatcher : class { //__SILP__ - func onChanged(propertyPath: String, lastValue: Double?, value: Double?) -> Void //__SILP__ -} //__SILP__ - //__SILP__ -public class DoubleProperty : DoubleVar, Property { //__SILP__ - public typealias ValueChecker = DoubleValueChecker //__SILP__ - public typealias ValueWatcher = DoubleValueWatcher //__SILP__ - //__SILP__ - public override var type: String? { //__SILP__ - return Properties.Consts.TypeDoubleProperty //__SILP__ - } //__SILP__ - //__SILP__ - public required init(entity: Entity, path: String) { //__SILP__ - super.init(entity: entity, path: path) //__SILP__ - } //__SILP__ - //__SILP__ - private var _checkers = [ValueChecker]() //__SILP__ - private var _watchers = [ValueWatcher]() //__SILP__ - //__SILP__ - private func getIndexOfValueChecker(checker: ValueChecker) -> Int? { //__SILP__ - for (i, obj) in enumerate(_checkers) { //__SILP__ - if obj === checker { //__SILP__ - return i //__SILP__ - } //__SILP__ - } //__SILP__ - return nil //__SILP__ - } //__SILP__ - //__SILP__ - public final func addValueChecker(checker: ValueChecker) -> Bool { //__SILP__ - if getIndexOfValueChecker(checker) == nil { //__SILP__ - _checkers.append(checker) //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - public final func removeValueChecker(checker: ValueChecker) -> Bool { //__SILP__ - if let index = getIndexOfValueChecker(checker) { //__SILP__ - _checkers.removeAtIndex(index) //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - private func getIndexOfValueWatcher(watcher: ValueWatcher) -> Int? { //__SILP__ - for (i, obj) in enumerate(_watchers) { //__SILP__ - if obj === watcher { //__SILP__ - return i //__SILP__ - } //__SILP__ - } //__SILP__ - return nil //__SILP__ - } //__SILP__ - //__SILP__ - public final func addValueWatcher(watcher: ValueWatcher) -> Bool { //__SILP__ - if getIndexOfValueWatcher(watcher) == nil { //__SILP__ - _watchers.append(watcher) //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - public final func removeValueWatcher(watcher: ValueWatcher) -> Bool { //__SILP__ - if let index = getIndexOfValueWatcher(watcher) { //__SILP__ - _watchers.removeAtIndex(index) //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - private var _checkingValue = false //__SILP__ - private var _updatingValue = false //__SILP__ - //__SILP__ - public override func setValue(newValue: Double?) -> Bool { //__SILP__ - if _checkingValue { return false } //__SILP__ - if _updatingValue { return false } //__SILP__ - //__SILP__ - if (value != newValue) { //__SILP__ - _checkingValue = true //__SILP__ - for checker in _checkers { //__SILP__ - if !checker.isValid(path, value: value, newValue: newValue) { //__SILP__ - _checkingValue = false //__SILP__ - return false //__SILP__ - } //__SILP__ - } //__SILP__ - _checkingValue = false //__SILP__ - //__SILP__ - _updatingValue = true //__SILP__ - let lastValue = value //__SILP__ - //__SILP__ - if (!super.setValue(newValue)) { //__SILP__ - _updatingValue = false //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - for watcher in _watchers { //__SILP__ - watcher.onChanged(path, lastValue: lastValue, value: value) //__SILP__ - } //__SILP__ - _updatingValue = false //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ -} //__SILP__ - //__SILP__ +public protocol DoubleValueChecker : class { //__SILP__ + func isValid(propertyPath: String, value: Double?, newValue: Double?) -> Bool //__SILP__ +} //__SILP__ + //__SILP__ +public protocol DoubleValueWatcher : class { //__SILP__ + func onChanged(propertyPath: String, lastValue: Double?, value: Double?) -> Void //__SILP__ +} //__SILP__ + //__SILP__ +public final class BlockDoubleValueChecker : DoubleValueChecker { //__SILP__ + public typealias CheckerBlock = (String, Double?, Double?) -> Bool //__SILP__ + private let block: CheckerBlock //__SILP__ + //__SILP__ + public init(block: CheckerBlock) { //__SILP__ + self.block = block //__SILP__ + } //__SILP__ + //__SILP__ + public func isValid(propertyPath: String, value: Double?, newValue: Double?) -> Bool { //__SILP__ + return block(propertyPath, value, newValue) //__SILP__ + } //__SILP__ +} //__SILP__ + //__SILP__ +public final class BlockDoubleValueWatcher : DoubleValueWatcher { //__SILP__ + public typealias WatcherBlock = (String, Double?, Double?) -> Void //__SILP__ + private let block: WatcherBlock //__SILP__ + //__SILP__ + public init(block: WatcherBlock) { //__SILP__ + self.block = block //__SILP__ + } //__SILP__ + //__SILP__ + public func onChanged(propertyPath: String, lastValue: Double?, value: Double?) -> Void { //__SILP__ + block(propertyPath, lastValue, value) //__SILP__ + } //__SILP__ +} //__SILP__ + //__SILP__ +public class DoubleProperty : DoubleVar, Property { //__SILP__ + public typealias ValueChecker = DoubleValueChecker //__SILP__ + public typealias ValueWatcher = DoubleValueWatcher //__SILP__ + //__SILP__ + public override var type: String? { //__SILP__ + return Properties.Consts.TypeDoubleProperty //__SILP__ + } //__SILP__ + //__SILP__ + public required init(entity: Entity, path: String) { //__SILP__ + super.init(entity: entity, path: path) //__SILP__ + } //__SILP__ + //__SILP__ + private var _checkers = [ValueChecker]() //__SILP__ + private var _watchers = [ValueWatcher]() //__SILP__ + //__SILP__ + private func getIndexOfValueChecker(checker: ValueChecker) -> Int? { //__SILP__ + for (i, obj) in enumerate(_checkers) { //__SILP__ + if obj === checker { //__SILP__ + return i //__SILP__ + } //__SILP__ + } //__SILP__ + return nil //__SILP__ + } //__SILP__ + //__SILP__ + public final func addValueChecker(checker: ValueChecker) -> Bool { //__SILP__ + if getIndexOfValueChecker(checker) == nil { //__SILP__ + _checkers.append(checker) //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + public final func removeValueChecker(checker: ValueChecker) -> Bool { //__SILP__ + if let index = getIndexOfValueChecker(checker) { //__SILP__ + _checkers.removeAtIndex(index) //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + private func getIndexOfValueWatcher(watcher: ValueWatcher) -> Int? { //__SILP__ + for (i, obj) in enumerate(_watchers) { //__SILP__ + if obj === watcher { //__SILP__ + return i //__SILP__ + } //__SILP__ + } //__SILP__ + return nil //__SILP__ + } //__SILP__ + //__SILP__ + public final func addValueWatcher(watcher: ValueWatcher) -> Bool { //__SILP__ + if getIndexOfValueWatcher(watcher) == nil { //__SILP__ + _watchers.append(watcher) //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + public final func removeValueWatcher(watcher: ValueWatcher) -> Bool { //__SILP__ + if let index = getIndexOfValueWatcher(watcher) { //__SILP__ + _watchers.removeAtIndex(index) //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + private var _checkingValue = false //__SILP__ + private var _updatingValue = false //__SILP__ + //__SILP__ + public override func setValue(newValue: Double?) -> Bool { //__SILP__ + if _checkingValue { return false } //__SILP__ + if _updatingValue { return false } //__SILP__ + //__SILP__ + if (value != newValue) { //__SILP__ + _checkingValue = true //__SILP__ + for checker in _checkers { //__SILP__ + if !checker.isValid(path, value: value, newValue: newValue) { //__SILP__ + _checkingValue = false //__SILP__ + return false //__SILP__ + } //__SILP__ + } //__SILP__ + _checkingValue = false //__SILP__ + //__SILP__ + _updatingValue = true //__SILP__ + let lastValue = value //__SILP__ + //__SILP__ + if (!super.setValue(newValue)) { //__SILP__ + _updatingValue = false //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + for watcher in _watchers { //__SILP__ + watcher.onChanged(path, lastValue: lastValue, value: value) //__SILP__ + } //__SILP__ + _updatingValue = false //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ +} //__SILP__ + //__SILP__ //SILP: PROPERTY_CLASS(String, String) -public protocol StringValueChecker : class { //__SILP__ - func isValid(propertyPath: String, value: String?, newValue: String?) -> Bool //__SILP__ -} //__SILP__ - //__SILP__ -public protocol StringValueWatcher : class { //__SILP__ - func onChanged(propertyPath: String, lastValue: String?, value: String?) -> Void //__SILP__ -} //__SILP__ - //__SILP__ -public class StringProperty : StringVar, Property { //__SILP__ - public typealias ValueChecker = StringValueChecker //__SILP__ - public typealias ValueWatcher = StringValueWatcher //__SILP__ - //__SILP__ - public override var type: String? { //__SILP__ - return Properties.Consts.TypeStringProperty //__SILP__ - } //__SILP__ - //__SILP__ - public required init(entity: Entity, path: String) { //__SILP__ - super.init(entity: entity, path: path) //__SILP__ - } //__SILP__ - //__SILP__ - private var _checkers = [ValueChecker]() //__SILP__ - private var _watchers = [ValueWatcher]() //__SILP__ - //__SILP__ - private func getIndexOfValueChecker(checker: ValueChecker) -> Int? { //__SILP__ - for (i, obj) in enumerate(_checkers) { //__SILP__ - if obj === checker { //__SILP__ - return i //__SILP__ - } //__SILP__ - } //__SILP__ - return nil //__SILP__ - } //__SILP__ - //__SILP__ - public final func addValueChecker(checker: ValueChecker) -> Bool { //__SILP__ - if getIndexOfValueChecker(checker) == nil { //__SILP__ - _checkers.append(checker) //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - public final func removeValueChecker(checker: ValueChecker) -> Bool { //__SILP__ - if let index = getIndexOfValueChecker(checker) { //__SILP__ - _checkers.removeAtIndex(index) //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - private func getIndexOfValueWatcher(watcher: ValueWatcher) -> Int? { //__SILP__ - for (i, obj) in enumerate(_watchers) { //__SILP__ - if obj === watcher { //__SILP__ - return i //__SILP__ - } //__SILP__ - } //__SILP__ - return nil //__SILP__ - } //__SILP__ - //__SILP__ - public final func addValueWatcher(watcher: ValueWatcher) -> Bool { //__SILP__ - if getIndexOfValueWatcher(watcher) == nil { //__SILP__ - _watchers.append(watcher) //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - public final func removeValueWatcher(watcher: ValueWatcher) -> Bool { //__SILP__ - if let index = getIndexOfValueWatcher(watcher) { //__SILP__ - _watchers.removeAtIndex(index) //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - private var _checkingValue = false //__SILP__ - private var _updatingValue = false //__SILP__ - //__SILP__ - public override func setValue(newValue: String?) -> Bool { //__SILP__ - if _checkingValue { return false } //__SILP__ - if _updatingValue { return false } //__SILP__ - //__SILP__ - if (value != newValue) { //__SILP__ - _checkingValue = true //__SILP__ - for checker in _checkers { //__SILP__ - if !checker.isValid(path, value: value, newValue: newValue) { //__SILP__ - _checkingValue = false //__SILP__ - return false //__SILP__ - } //__SILP__ - } //__SILP__ - _checkingValue = false //__SILP__ - //__SILP__ - _updatingValue = true //__SILP__ - let lastValue = value //__SILP__ - //__SILP__ - if (!super.setValue(newValue)) { //__SILP__ - _updatingValue = false //__SILP__ - return false //__SILP__ - } //__SILP__ - //__SILP__ - for watcher in _watchers { //__SILP__ - watcher.onChanged(path, lastValue: lastValue, value: value) //__SILP__ - } //__SILP__ - _updatingValue = false //__SILP__ - return true //__SILP__ - } //__SILP__ - return false //__SILP__ - } //__SILP__ -} //__SILP__ - //__SILP__ +public protocol StringValueChecker : class { //__SILP__ + func isValid(propertyPath: String, value: String?, newValue: String?) -> Bool //__SILP__ +} //__SILP__ + //__SILP__ +public protocol StringValueWatcher : class { //__SILP__ + func onChanged(propertyPath: String, lastValue: String?, value: String?) -> Void //__SILP__ +} //__SILP__ + //__SILP__ +public final class BlockStringValueChecker : StringValueChecker { //__SILP__ + public typealias CheckerBlock = (String, String?, String?) -> Bool //__SILP__ + private let block: CheckerBlock //__SILP__ + //__SILP__ + public init(block: CheckerBlock) { //__SILP__ + self.block = block //__SILP__ + } //__SILP__ + //__SILP__ + public func isValid(propertyPath: String, value: String?, newValue: String?) -> Bool { //__SILP__ + return block(propertyPath, value, newValue) //__SILP__ + } //__SILP__ +} //__SILP__ + //__SILP__ +public final class BlockStringValueWatcher : StringValueWatcher { //__SILP__ + public typealias WatcherBlock = (String, String?, String?) -> Void //__SILP__ + private let block: WatcherBlock //__SILP__ + //__SILP__ + public init(block: WatcherBlock) { //__SILP__ + self.block = block //__SILP__ + } //__SILP__ + //__SILP__ + public func onChanged(propertyPath: String, lastValue: String?, value: String?) -> Void { //__SILP__ + block(propertyPath, lastValue, value) //__SILP__ + } //__SILP__ +} //__SILP__ + //__SILP__ +public class StringProperty : StringVar, Property { //__SILP__ + public typealias ValueChecker = StringValueChecker //__SILP__ + public typealias ValueWatcher = StringValueWatcher //__SILP__ + //__SILP__ + public override var type: String? { //__SILP__ + return Properties.Consts.TypeStringProperty //__SILP__ + } //__SILP__ + //__SILP__ + public required init(entity: Entity, path: String) { //__SILP__ + super.init(entity: entity, path: path) //__SILP__ + } //__SILP__ + //__SILP__ + private var _checkers = [ValueChecker]() //__SILP__ + private var _watchers = [ValueWatcher]() //__SILP__ + //__SILP__ + private func getIndexOfValueChecker(checker: ValueChecker) -> Int? { //__SILP__ + for (i, obj) in enumerate(_checkers) { //__SILP__ + if obj === checker { //__SILP__ + return i //__SILP__ + } //__SILP__ + } //__SILP__ + return nil //__SILP__ + } //__SILP__ + //__SILP__ + public final func addValueChecker(checker: ValueChecker) -> Bool { //__SILP__ + if getIndexOfValueChecker(checker) == nil { //__SILP__ + _checkers.append(checker) //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + public final func removeValueChecker(checker: ValueChecker) -> Bool { //__SILP__ + if let index = getIndexOfValueChecker(checker) { //__SILP__ + _checkers.removeAtIndex(index) //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + private func getIndexOfValueWatcher(watcher: ValueWatcher) -> Int? { //__SILP__ + for (i, obj) in enumerate(_watchers) { //__SILP__ + if obj === watcher { //__SILP__ + return i //__SILP__ + } //__SILP__ + } //__SILP__ + return nil //__SILP__ + } //__SILP__ + //__SILP__ + public final func addValueWatcher(watcher: ValueWatcher) -> Bool { //__SILP__ + if getIndexOfValueWatcher(watcher) == nil { //__SILP__ + _watchers.append(watcher) //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + public final func removeValueWatcher(watcher: ValueWatcher) -> Bool { //__SILP__ + if let index = getIndexOfValueWatcher(watcher) { //__SILP__ + _watchers.removeAtIndex(index) //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + private var _checkingValue = false //__SILP__ + private var _updatingValue = false //__SILP__ + //__SILP__ + public override func setValue(newValue: String?) -> Bool { //__SILP__ + if _checkingValue { return false } //__SILP__ + if _updatingValue { return false } //__SILP__ + //__SILP__ + if (value != newValue) { //__SILP__ + _checkingValue = true //__SILP__ + for checker in _checkers { //__SILP__ + if !checker.isValid(path, value: value, newValue: newValue) { //__SILP__ + _checkingValue = false //__SILP__ + return false //__SILP__ + } //__SILP__ + } //__SILP__ + _checkingValue = false //__SILP__ + //__SILP__ + _updatingValue = true //__SILP__ + let lastValue = value //__SILP__ + //__SILP__ + if (!super.setValue(newValue)) { //__SILP__ + _updatingValue = false //__SILP__ + return false //__SILP__ + } //__SILP__ + //__SILP__ + for watcher in _watchers { //__SILP__ + watcher.onChanged(path, lastValue: lastValue, value: value) //__SILP__ + } //__SILP__ + _updatingValue = false //__SILP__ + return true //__SILP__ + } //__SILP__ + return false //__SILP__ + } //__SILP__ +} //__SILP__ + //__SILP__ diff --git a/DapCore/context/silp_swift.md b/DapCore/context/silp_swift.md index 26f2168..eb41176 100644 --- a/DapCore/context/silp_swift.md +++ b/DapCore/context/silp_swift.md @@ -53,6 +53,32 @@ public protocol ${type}ValueWatcher : class { func onChanged(propertyPath: String, lastValue: ${swift_type}?, value: ${swift_type}?) -> Void } +public final class Block${type}ValueChecker : ${type}ValueChecker { + public typealias CheckerBlock = (String, ${swift_type}?, ${swift_type}?) -> Bool + private let block: CheckerBlock + + public init(block: CheckerBlock) { + self.block = block + } + + public func isValid(propertyPath: String, value: ${swift_type}?, newValue: ${swift_type}?) -> Bool { + return block(propertyPath, value, newValue) + } +} + +public final class Block${type}ValueWatcher : ${type}ValueWatcher { + public typealias WatcherBlock = (String, ${swift_type}?, ${swift_type}?) -> Void + private let block: WatcherBlock + + public init(block: WatcherBlock) { + self.block = block + } + + public func onChanged(propertyPath: String, lastValue: ${swift_type}?, value: ${swift_type}?) -> Void { + block(propertyPath, lastValue, value) + } +} + public class ${type}Property : ${type}Var, Property { public typealias ValueChecker = ${type}ValueChecker public typealias ValueWatcher = ${type}ValueWatcher