|
@@ -2,7 +2,7 @@ using Invercargill;
|
|
|
|
|
|
namespace InvercargillJson {
|
|
|
|
|
|
- public class JsonObject : Associative<string, JsonElement>, Properties {
|
|
|
+ public class JsonObject : Enumerable<KeyValuePair<string, JsonElement>>, ReadOnlyCollection<KeyValuePair<string, JsonElement>>, ReadOnlyAssociative<string, JsonElement>, Associative<string, JsonElement>, Properties {
|
|
|
|
|
|
private Json.Object object;
|
|
|
|
|
@@ -15,16 +15,16 @@ namespace InvercargillJson {
|
|
|
internal JsonObject.from_existing(Json.Object object) {
|
|
|
this.object = object;
|
|
|
}
|
|
|
- public override void clear (string key) {
|
|
|
+ public void clear () {
|
|
|
object.foreach_member ((o, n) => o.remove_member (n));
|
|
|
}
|
|
|
- public override bool has (string key) {
|
|
|
+ public bool has (string key) {
|
|
|
return object.has_member(key);
|
|
|
}
|
|
|
- public new override void @set (string key, JsonElement value) {
|
|
|
+ public new void @set (string key, JsonElement value) {
|
|
|
object.set_member(key, value.assert_as<Json.Node>());
|
|
|
}
|
|
|
- public override bool try_get (string key, out JsonElement value) {
|
|
|
+ public bool try_get (string key, out JsonElement value) {
|
|
|
if(has(key)) {
|
|
|
value = new JsonElement.from_node(object.get_member(key));
|
|
|
return true;
|
|
@@ -32,15 +32,15 @@ namespace InvercargillJson {
|
|
|
value = null;
|
|
|
return false;
|
|
|
}
|
|
|
- public override Tracker<KeyValuePair<string, Element>> get_tracker () {
|
|
|
+ public override Tracker<KeyValuePair<string, JsonElement>> get_tracker () {
|
|
|
var keys = object.get_members ();
|
|
|
var i = 0;
|
|
|
- return new LambdaTracker<KeyValuePair<string, Element>>(
|
|
|
+ return new LambdaTracker<KeyValuePair<string, JsonElement>>(
|
|
|
() => {
|
|
|
return i < keys.length();
|
|
|
},
|
|
|
() => {
|
|
|
- return new KeyValuePair<string, Element> (keys.nth_data(i), new JsonElement.from_node(object.get_member(keys.nth_data(i++))));
|
|
|
+ return new KeyValuePair<string, JsonElement> (keys.nth_data(i), new JsonElement.from_node(object.get_member(keys.nth_data(i++))));
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -76,7 +76,7 @@ namespace InvercargillJson {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- public void set_native<T>(string key, T value) throws ElementError {
|
|
|
+ public void set_native<T>(string key, T value, bool? defined = false) throws ElementError {
|
|
|
set(key, new JsonElement.from_element(new NativeElement<T>(value)));
|
|
|
}
|
|
|
|
|
@@ -86,6 +86,23 @@ namespace InvercargillJson {
|
|
|
return new JsonElement.from_node(node);
|
|
|
}
|
|
|
|
|
|
+ public bool add(string key, JsonElement value) {
|
|
|
+ if(has(key)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ @set(key, value);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ public bool remove(string key, out JsonElement value) {
|
|
|
+ if(try_get(key, out value)) {
|
|
|
+ object.remove_member(key);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ public Invercargill.Enumerable<string> keys { owned get; }
|
|
|
+ public Invercargill.Enumerable<JsonElement> values { owned get; }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|