0001    //
0002    //  Event.swift
0003    //  Transporter
0004    //
0005    //  Created by Denys Telezhkin on 28.10.14.
0006    //  Copyright (c) 2014 Denys Telezhkin. All rights reserved.
0007    //
0008    // Permission is hereby granted, free of charge, to any person obtaining a copy
0009    // of this software and associated documentation files (the "Software"), to deal
0010    // in the Software without restriction, including without limitation the rights
0011    // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0012    // copies of the Software, and to permit persons to whom the Software is
0013    // furnished to do so, subject to the following conditions:
0014    //
0015    // The above copyright notice and this permission notice shall be included in
0016    // all copies or substantial portions of the Software.
0017    //
0018    // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0019    // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0020    // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0021    // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0022    // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0023    // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
0024    // THE SOFTWARE.
0025    
0026    /**
0027        Instance of enum is returned from fireEvent method on StateMachine. Use it to determine, whether transition was successful.
0028    */
0029    public enum Transition
StateMachine.swift:190
    public func fireEvent(event: Event<T>) -> Transition<T> {
StateMachine.swift:197
    public func fireEvent(eventName: String) -> Transition<T> {
StateMachine.swift:231
    public func possibleTransitionForEvent(event: Event<T>) -> Transition<T> {
StateMachine.swift:236
            return Transition.Success(sourceState: currentState, destinationState: State(event.destinationValue))
StateMachine.swift:284
    func _fireEventNamed(eventName: String) -> Transition<T> {
<T
Event.swift:47
    case Success(sourceState: State<T>, destinationState: State<T>)
Event.swift:47
    case Success(sourceState: State<T>, destinationState: State<T>)
:Hashable> { 0030 0031 /** 0032 Returns whether transition was successful 0033 */ 0034 public var successful: Bool { 0035 switch self { 0036 case .Success(_,_): 0037 return true 0038 0039 case .Error(_): 0040 return false 0041 } 0042 } 0043 0044 /** 0045 Success case with source state, from which transition happened, and destination state, to which state machine switched 0046 */ 0047 case Success
Event.swift:36
            case .Success(_,_):
StateMachine.swift:236
            return Transition.Success(sourceState: currentState, destinationState: State(event.destinationValue))
StateMachine.swift:288
            case .Success(let sourceState, let destinationState):
StateMachine.swift:294
                        return .Success(sourceState: sourceState, destinationState: destinationState)
StateMachine.swift:305
                    return .Success(sourceState: sourceState, destinationState: destinationState)
(sourceState: State<T>, destinationState: State<T>) 0048 0049 /** 0050 Error case, containing error. Error domain and status codes are described in Errors struct. 0051 */ 0052 case Error
Event.swift:39
            case .Error(_):
StateMachine.swift:206
        if case .Error(_) = possibleTransition {
StateMachine.swift:233
            return .Error(.UnknownEvent)
StateMachine.swift:238
        return .Error(.WrongSourceState)
StateMachine.swift:297
                        return .Error(.TransitionDeclined)
StateMachine.swift:312
            return .Error(.UnknownEvent)
(TransitionError) 0053 } 0054 0055 /** 0056 `Event` class encapsulates some event with array of possible source states and one destination state, to which state machine should transition, when this event fires. 0057 */ 0058 public class Event
Event.swift:70
    public var shouldFireEvent: ( (event : Event) -> Bool )?
Event.swift:73
    public var willFireEvent:   ( (event : Event) -> Void )?
Event.swift:76
    public var didFireEvent:    ( (event : Event) -> Void )?
Event.swift:89
extension Event: Equatable {}
Event.swift:92
public func ==<T>(lhs:Event<T>,rhs:Event<T>) -> Bool {
Event.swift:92
public func ==<T>(lhs:Event<T>,rhs:Event<T>) -> Bool {
StateMachine.swift:72
    private lazy var events : [Event<T>] = []
StateMachine.swift:146
    public func addEvent(event: Event<T>) throws {
StateMachine.swift:168
    public func addEvents(events: [Event<T>]) {
StateMachine.swift:190
    public func fireEvent(event: Event<T>) -> Transition<T> {
StateMachine.swift:204
    public func canFireEvent(event: Event<T>) -> Bool {
StateMachine.swift:231
    public func possibleTransitionForEvent(event: Event<T>) -> Transition<T> {
StateMachine.swift:256
    public func eventWithName(name: String) -> Event<T>? {
<T
Event.swift:64
    public let sourceValues: [T]
Event.swift:67
    public let destinationValue: T
Event.swift:82
    required public init(name: String, sourceValues sources: [T], destinationValue destination: T) {
Event.swift:82
    required public init(name: String, sourceValues sources: [T], destinationValue destination: T) {
:Hashable> { 0059 0060 /// Name of event 0061 public let name
Event.swift:83
        self.name = name
Event.swift:93
    return lhs.name == rhs.name
Event.swift:93
    return lhs.name == rhs.name
StateMachine.swift:172
                print("failed adding event with name: %@",event.name)
StateMachine.swift:191
        return _fireEventNamed(event.name)
StateMachine.swift:258
            return element.name == name
: String 0062 0063 /// Array of source values, in which event can be fired 0064 public let sourceValues
Event.swift:84
        self.sourceValues = sources
StateMachine.swift:147
        if event.sourceValues.isEmpty
StateMachine.swift:152
        for state in event.sourceValues
StateMachine.swift:235
        if event.sourceValues.contains(currentState.value) {
: [T] 0065 0066 /// Destination value for state, to which state machine will switch after firing event. 0067 public let destinationValue
Event.swift:85
        self.destinationValue = destination
StateMachine.swift:159
        if (self.stateWithValue(event.destinationValue) == nil) {
StateMachine.swift:236
            return Transition.Success(sourceState: currentState, destinationState: State(event.destinationValue))
StateMachine.swift:292
                        activateState(event.destinationValue)
StateMachine.swift:303
                    activateState(event.destinationValue)
: T 0068 0069 /// If this closure return value is false, event will not be fired 0070 public var shouldFireEvent
StateMachine.swift:289
                if let shouldBlock = event.shouldFireEvent {
: ( (event : Event) -> Bool )? 0071 0072 /// This closure will be executed before event is fired. 0073 public var willFireEvent
StateMachine.swift:291
                        event.willFireEvent?(event: event)
StateMachine.swift:302
                    event.willFireEvent?(event: event)
: ( (event : Event) -> Void )? 0074 0075 /// This closure will be executed after event was fired. 0076 public var didFireEvent
StateMachine.swift:293
                        event.didFireEvent?(event: event)
StateMachine.swift:304
                    event.didFireEvent?(event: event)
: ( (event : Event) -> Void )? 0077 0078 /// Initializer for Event. 0079 /// - Parameter name: name of the event 0080 /// - Parameter sourceValues: Array of source values, in which event can be fired 0081 /// - Parameter destinationValue: Destination state value 0082 required public init(name: String, sourceValues sources: [T], destinationValue destination: T) { 0083 self.name = name 0084 self.sourceValues = sources 0085 self.destinationValue = destination 0086 } 0087 } 0088 0089 extension Event: Equatable {} 0090 0091 /// Returns true, if events have the same name 0092 public func ==<T>(lhs:Event<T>,rhs:Event<T>) -> Bool { 0093 return lhs.name == rhs.name 0094 }