1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// ConversionOptions.swift
// EVReflection
//
// Created by Edwin Vermeer on 9/5/16.
// Copyright © 2015 evict. All rights reserved.
//
/**
For specifying what conversion options should be executed
*/
public struct ConversionOptions: OptionSet, CustomStringConvertible {
/// The numeric representation of the options
public let rawValue: Int
/**
Initialize with a raw value
- parameter rawValue: the numeric representation
- returns: The ConversionOptions
*/
public init(rawValue: Int) { self.rawValue = rawValue }
/// No conversion options
public static let None = ConversionOptions(rawValue: 0)
/// Execute property converters
public static let PropertyConverter = ConversionOptions(rawValue: 1)
/// Execute property mapping
public static let PropertyMapping = ConversionOptions(rawValue: 2)
/// Skip specific property values
public static let SkipPropertyValue = ConversionOptions(rawValue: 4)
/// Do a key cleanup (CameCase, snake_case)
public static let KeyCleanup = ConversionOptions(rawValue: 8)
/// Execute the decoding function for all values
public static let Decoding = ConversionOptions(rawValue: 16)
/// Execute an encoding function on all values
public static let Encoding = ConversionOptions(rawValue: 32)
// Just for bein able to show all
public static var All: ConversionOptions = [PropertyConverter, PropertyMapping, SkipPropertyValue, KeyCleanup, Decoding, Encoding]
/// Default used for NSCoding
public static var DefaultNSCoding: ConversionOptions = [None]
/// Default used for comparing / hashing functions
public static var DefaultComparing: ConversionOptions = [PropertyConverter, PropertyMapping, SkipPropertyValue]
/// Default used for deserialization
public static var DefaultDeserialize: ConversionOptions = [PropertyConverter, PropertyMapping, SkipPropertyValue, KeyCleanup, Decoding]
/// Default used for serialization
public static var DefaultSerialize: ConversionOptions = [PropertyConverter, PropertyMapping, SkipPropertyValue, Encoding]
/// Get a nice description of the ConversionOptions
public var description: String {
let strings = ["PropertyConverter", "PropertyMapping", "SkipPropertyValue", "KeyCleanup", "Decoding", "Encoding"]
var members = [String]()
for (flag, string) in strings.enumerated() where contains(ConversionOptions(rawValue:1<<(flag + 1))) {
members.append(string)
}
if members.count == 0 {
members.append("None")
}
return members.description
}
}