1 module uim.json.classes.value; 2 3 import std.stdio; 4 import std.traits; 5 import uim.json; 6 7 class DJSONValue { 8 /++ 9 + JSON values can be: 10 A number (integer or floating point) 11 A string (in double quotes) 12 A Boolean (true or false) 13 An array (in square brackets) 14 An object (in curly braces) 15 null 16 +/ 17 18 @property auto keys() { return null; } 19 20 @property size_t length() { return 0; } 21 O opIndexAssign(this O, T)(T value, string name) if ((isNarrowString!T) && (isArray!T)) { return cast(O)this; } 22 O opIndexAssign(this O, T)(T value, string name) if ((!isNarrowString!T) && (!isArray!T)) { return cast(O)this; } 23 O opIndexAssign(this O, T)(T values, string name) if ((!isNarrowString!T) && (isArray!T)) { return cast(O)this; } 24 25 O opIndexAssign(this O, T)(T value, size_t index) if ((isNarrowString!T) && (isArray!T)) { return cast(O)this; } 26 O opIndexAssign(this O, T)(T value, size_t index) if ((!isNarrowString!T) && (!isArray!T)) { return cast(O)this; } 27 O opIndexAssign(this O, T)(T values, size_t index) if ((!isNarrowString!T) && (isArray!T)) { return cast(O)this; } 28 29 DJSONValue opIndex(size_t index) { return null; } 30 DJSONValue opIndex(string name) { return null; } 31 32 bool exists(size_t index) { return (this[index] ? true : false); } 33 bool exists(string name) { return (this[name] ? true : false); } 34 bool pathExists(string[] names...) { 35 if (names.length == 0) return false; 36 if (auto first = this[names[0]]) { 37 if (names.length > 1) return first.pathExists(names[1..$]); 38 return true; 39 } 40 return false; 41 } 42 DJSONValue pathValue(string[] names...) { 43 if (names.length == 0) return null; 44 if (auto first = this[names[0]]) { 45 if (names.length > 1) return first.pathValue(names[1..$]); 46 return first; 47 } 48 return null; 49 } 50 51 DJSONValue dup() { return null; } 52 override string toString() { 53 return ""; 54 } 55 } 56 auto JSONValue() { return JSONNull; } 57 58 auto JSONValue(DJSONValue value) { return value/*.dup*/; } 59 auto JSONValue(string value) { return JSONString(value); } 60 auto JSONValue(int value) { return JSONNumber(value); } 61 auto JSONValue(double value) { return JSONNumber(value); } 62 auto JSONValue(bool value) { return JSONBoolean(value); } 63 //auto JSONValue(DJSONArray value) { return JSONArray(value); } 64 auto JSONValue(DJSONObject value) { return JSONObject(value); } 65 /* 66 auto JSONValue(DJSONValue[] values) { return JSONArray(values)/ *.dup* /; } 67 auto JSONValue(string[] values) { return JSONArray(values); } 68 auto JSONValue(int[] values) { return JSONArray(values); } 69 auto JSONValue(double[] values) { return JSONArray(values); } 70 auto JSONValue(bool[] values) { return JSONArray(values); } 71 */