Skip to content

Commit

Permalink
Merge pull request #12 from BrettRToomey/parent-node
Browse files Browse the repository at this point in the history
Added parent to node
  • Loading branch information
BrettRToomey authored Oct 19, 2017
2 parents 65e781b + dfa50d5 commit e8457d6
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions Sources/BML.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public final class BML {
var _name: Bytes
var _value: Bytes?

var nameCache: String?
var nameCache: String?
var valueCache: String?

public var name: String {
Expand Down Expand Up @@ -36,46 +36,52 @@ public final class BML {

public var attributes: [BML]
public var children: [BML]
public weak var parent: BML?

init(
name: Bytes,
value: Bytes? = nil,
attributes: [BML] = [],
children: [BML] = []
children: [BML] = [],
parent: BML? = nil
) {
_name = name
_value = value
self.attributes = attributes
self.children = children
self.parent = parent
}

convenience init(
name: String,
value: String? = nil,
attributes: [BML] = [],
children: [BML] = []
children: [BML] = [],
parent: BML? = nil
) {
self.init(
name: name.bytes,
value: value?.bytes,
attributes: attributes,
children: children
children: children,
parent: parent
)
}
}

extension BML {
func addChild(key: Bytes, value: Bytes) {
let sighting = BML(name: key, value: value)
let sighting = BML(name: key, value: value, parent: self)
add(child: sighting)
}

func addAttribute(key: Bytes, value: Bytes) {
let sighting = BML(name: key, value: value)
let sighting = BML(name: key, value: value, parent: self)
add(attribute: sighting)
}

func add(child: BML) {
child.parent = self
children.append(child)
}

Expand Down

0 comments on commit e8457d6

Please sign in to comment.