/
Config.swift
59 lines (48 loc) · 1.43 KB
/
Config.swift
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
//
// Config.swift
// TLSphinx
//
// Created by Bruno Berisso on 5/29/15.
// Copyright (c) 2015 Bruno Berisso. All rights reserved.
//
import Foundation
import Sphinx.Base
public final class Config {
var cmdLnConf: OpaquePointer?
fileprivate var cArgs: [UnsafeMutablePointer<Int8>?]
public init?(args: (String,String)...) {
// Create [UnsafeMutablePointer<Int8>].
cArgs = args.flatMap { (name, value) -> [UnsafeMutablePointer<Int8>?] in
//strdup move the strings to the heap and return a UnsageMutablePointer<Int8>
return [strdup(name),strdup(value)]
}
cmdLnConf = cmd_ln_parse_r(nil, ps_args(), CInt(cArgs.count), &cArgs, STrue32)
if cmdLnConf == nil {
return nil
}
}
deinit {
for cString in cArgs {
free(cString)
}
cmd_ln_free_r(cmdLnConf)
}
public var showDebugInfo: Bool {
get {
if cmdLnConf != nil {
return cmd_ln_str_r(cmdLnConf, "-logfn") == nil
} else {
return false
}
}
set {
if cmdLnConf != nil {
if newValue {
cmd_ln_set_str_r(cmdLnConf, "-logfn", nil)
} else {
cmd_ln_set_str_r(cmdLnConf, "-logfn", "/dev/null")
}
}
}
}
}