void CheckValueMap() { RLOG("------------------------------"); RLOG("CheckValueMap"); Value x = 123; Value y = x; ValueMap h; h.Add("0", 123); RDUMP(h["0"]); h.Add("1", Date(2001, 12, 1)); h.Add("2", "test"); Value v = h; ASSERT(v.GetCount() == 3); RDUMP(v["0"]); ASSERT(v["0"] == 123); ASSERT(v["1"] == Date(2001, 12, 1)); ASSERT(v["2"] == "test"); ASSERT(IsValueMap(v)); ASSERT(IsValueArray(v)); ValueMap hh = v; ASSERT(hh == h); hh.Add(123, "foo"); ASSERT(hh.GetCount() == 4); ASSERT(v.GetCount() == 3); ASSERT(hh[123] == "foo"); ValueArray va = v; ASSERT(va.GetCount() == 3); ASSERT(va[0] == 123); ASSERT(va[1] == Date(2001, 12, 1)); ASSERT(va[2] == "test"); }
EscValue EscFromStdValue(const Value& v) { EscValue r; Time t; if(!IsNull(v)) switch(v.GetType()) { case BOOL_V: case INT_V: case INT64_V: case DOUBLE_V: r = (double)v; break; case STRING_V: case WSTRING_V: r = (WString)v; break; case TIME_V: t = v; r.MapSet("hour", t.hour); r.MapSet("minute", t.minute); r.MapSet("second", t.second); case DATE_V: t = v; r.MapSet("year", t.year); r.MapSet("month", t.month); r.MapSet("day", t.day); break; case VALUEARRAY_V: ValueArray va = v; r.SetEmptyArray(); for(int i = 0; i < va.GetCount(); i++) r.ArrayAdd(EscFromStdValue(va[i])); } return r; }
String FormatXmlRpcParams(const ValueArray& params) { String r; r = "<params>"; for(int i = 0; i < params.GetCount(); i++) r << FormatXmlRpcParam(params[i]); r << "</params>"; return r; }
void Ide::EditMacroMenu(Bar& menu, ValueArray mx) { const Array<IdeMacro>& mlist = UscMacros(); Vector<String> names; Vector<int> index; names.Reserve(mx.GetCount()); for(int i = 0; i < mx.GetCount(); i++) { int ii = mx[i]; if(ii >= 0 && ii < mlist.GetCount()) { const IdeMacro& m = mlist[ii]; names.Add(Nvl(m.submenu, m.menu)); index.Add(ii); } } IndexSort(names, index); for(int i = 0; i < index.GetCount(); i++) menu.Add(names[i], THISBACK1(EditMacro, index[i])) .Key(mlist[index[i]].hotkey); }
String FormatXmlRpcValue(const Value& _v) { String r; Value v = _v; if(v.GetType() == INT64_V) { int64 x = v; if((int)x == x) v = (int)x; } if(IsNull(v) && !IsString(v) && !IsValueArray(v)) r = XmlTag("nil")(); else if(v.GetType() == INT_V) r = XmlTag("int")(Format("%d", (int)v)); else if(v.GetType() == BOOL_V) r = XmlTag("boolean")(AsString((int)(bool)v)); else if(IsNumber(v)) r = XmlTag("double")(Format("%.16g", (double)v)); else if(IsDateTime(v)) { Time t = v; r = XmlTag("dateTime.iso8601") (Format("%04.4d%02.2d%02.2d`T%02.2d`:%02.2d`:%02.2d", t.year, t.month, t.day, t.hour, t.minute, t.second)); } else if(v.GetType() == VALUEMAP_V) { r = "<struct>"; ValueMap vm = v; const Index<Value>& k = vm.GetKeys(); ValueArray va = vm.GetValues(); for(int i = 0; i < k.GetCount(); i++) r << XmlTag("member")(XmlTag("name")(k[i]) + FormatXmlRpcValue(va[i])); r << "</struct>"; } else if(v.GetType() == VALUEARRAY_V) { r = "<array><data>"; ValueArray va = v; for(int i = 0; i < va.GetCount(); i++) r << FormatXmlRpcValue(va[i]); r << "</data></array>"; } else if(v.Is<RawJsonText>()) r = XmlTag("string").Text(v.To<RawJsonText>().json); else r = XmlTag("string").Text(v); return XmlTag("value")(r); }
void PropListCtrl::Updated() { gl.SetData(Null); sl.SetData(Null); if(!ctrl) return; Ctrl& e = *ctrl; Value v; bool b; String t; b = Props<Ctrl>::Get(e, "listset", v); ValueArray vs = v; t << "Set Properties: (" << vs.GetCount() << ")\n" << v; gl.SetData(t); v = Value(); b = Props<Ctrl>::Get(e, "listget", v); t.Clear(); ValueArray vg = v; t << "Get Properties: (" << vg.GetCount() << ")\n"; { for(int i = 0; i < vg.GetCount(); i++) { String s = vg.Get(i); Value v; t << s << " = "; b = Props<Ctrl>::Get(e, s, v); if(b) t << v; else t << "##ERR##"; t << "\n"; } } sl.SetData(t); }
Value Compiler::ExeBracket::Eval(ExeContext& x) const { Value m = value->Eval(x); Value q = index->Eval(x); if(IsNumber(q) && m.Is<ValueArray>()) { ValueArray va = m; int i = q; if(i >= 0 && i < va.GetCount()) return va[i]; } if(IsValueMap(m)) { ValueMap map = m; return map[q]; } return Value(); }
ValueMap::ValueMap(const Value& src) { if(!IsNull(src)) { if(IsType<ValueArray>(src)) { ValueArray va = src; Init0(); for(int i = 0; i < va.GetCount(); i++) Add(i, va[i]); return; } else { if(src.GetType() != VALUEMAP_V) throw ValueTypeError(String().Cat() << "Invalid value conversion: " << src.GetTypeName() << " -> ValueMap", src, VALUEMAP_V); data = (ValueMap::Data *)src.GetVoidPtr(); } } else data = &Single<NullData>(); data->Retain(); }
String AsJSON(const Value& v, const String& sep, bool pretty) { String r; if(v.GetType() == VALUEMAP_V) { r << "{"; String sep1; if(pretty) { r << "\r\n"; sep1 = sep + '\t'; } ValueMap m = v; ValueArray va = m.GetValues(); for(int i = 0; i < m.GetCount(); i++) { if(i) { r << ","; if(pretty) r << "\r\n"; } if(pretty) r << sep1; r << AsJSON((String)m.GetKey(i)) << (pretty ? ": " : ":") << AsJSON(va[i], sep1, pretty); } if(pretty) r << "\r\n" << sep; r << "}"; return r; } if(v.GetType() == VALUEARRAY_V) { r << "["; String sep1; if(pretty) { r << "\r\n"; sep1 = sep + '\t'; } ValueArray va = v; for(int i = 0; i < va.GetCount(); i++) { if(i) { r << ","; if(pretty) r << "\r\n"; } if(pretty) r << sep1; r << AsJSON(va[i], sep1, pretty); } if(pretty) r << "\r\n" << sep; r << "]"; return r; } if(IsNumber(v) && IsNull(v)) return "null"; if(v.GetType() == INT_V) return Format("%d", (int)v); if(v.GetType() == BOOL_V) return (bool)v ? "true" : "false"; if(IsNumber(v)) return Format("%.16g", (double)v); if(IsString(v)) return AsCString((String)v, INT_MAX, NULL, ASCSTRING_JSON); if(IsDateTime(v)) return AsJSON((Time)v); if(IsNull(v)) return "null"; NEVER_("Non-JSON value in AsJSON: " + v.GetTypeName()); return "null"; }
SqlSet SqlSetFrom(const ValueArray& va) { return SqlSetFrom(va, 0, va.GetCount()); }