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"); }
void test_set_diff(Ardb& db) { DBID dbid = 0; db.SClear(dbid, "myset1"); db.SClear(dbid, "myset2"); db.SClear(dbid, "myset3"); db.SAdd(dbid, "myset1", "a"); db.SAdd(dbid, "myset1", "b"); db.SAdd(dbid, "myset1", "c"); db.SAdd(dbid, "myset1", "d"); db.SAdd(dbid, "myset2", "c"); db.SAdd(dbid, "myset3", "a"); db.SAdd(dbid, "myset3", "c"); db.SAdd(dbid, "myset3", "e"); std::string str; SliceArray keys; keys.push_back("myset1"); keys.push_back("myset2"); keys.push_back("myset3"); ValueArray values; db.SDiff(dbid, keys, values); CHECK_FATAL(values.size() != 2, "Sdiff failed:"); CHECK_FATAL(values.begin()->ToString(str) != "b", "Sdiff store failed:"); //CHECK_FATAL(FATAL, values[1] != "d") << "Sdiff store failed:"; int len = db.SDiffStore(dbid, "myset2", keys); CHECK_FATAL(len != 2, "SDiffStore myset2 failed:%d", len); len = db.SCard(dbid, "myset2"); CHECK_FATAL(len != 2, "SDiffStore myset2 failed:%d", len); }
void test_set_inter(Ardb& db) { DBID dbid = 0; db.SClear(dbid, "myset1"); db.SClear(dbid, "myset2"); db.SClear(dbid, "myset3"); db.SAdd(dbid, "myset1", "a"); db.SAdd(dbid, "myset1", "b"); db.SAdd(dbid, "myset1", "c"); db.SAdd(dbid, "myset1", "d"); db.SAdd(dbid, "myset2", "c"); db.SAdd(dbid, "myset3", "a"); db.SAdd(dbid, "myset3", "c"); db.SAdd(dbid, "myset3", "e"); SliceArray keys; keys.push_back("myset1"); keys.push_back("myset2"); keys.push_back("myset3"); ValueArray values; db.SInter(dbid, keys, values); std::string str; CHECK_FATAL( values.size() != 1, "Sinter failed:"); CHECK_FATAL(values.begin()->ToString(str) != "c", "Sinter store failed."); db.SInterStore(dbid, "myset4", keys); CHECK_FATAL( db.SCard(dbid, "myset4") != 1, "SInterStore myset4 failed"); }
Value Compiler::ExeArray::Eval(ExeContext& x) const { ValueArray va; for(int i = 0; i < item.GetCount(); i++) va.Add(item[i]->Eval(x)); return va; }
void test_set_union(Ardb& db) { DBID dbid = 0; db.SClear(dbid, "myset1"); db.SClear(dbid, "myset2"); db.SClear(dbid, "myset3"); db.SAdd(dbid, "myset1", "a"); db.SAdd(dbid, "myset1", "b"); db.SAdd(dbid, "myset1", "c"); db.SAdd(dbid, "myset1", "d"); db.SAdd(dbid, "myset2", "c"); db.SAdd(dbid, "myset3", "a"); db.SAdd(dbid, "myset3", "c"); db.SAdd(dbid, "myset3", "e"); SliceArray keys; keys.push_back("myset1"); keys.push_back("myset2"); keys.push_back("myset3"); ValueArray values; db.SUnion(dbid, keys, values); CHECK_FATAL(values.size() != 5, "SUnion failed:"); std::string str; CHECK_FATAL( values.begin()->ToString(str) != "a", "SUnion store failed:"); db.SUnionStore(dbid, "myset2", keys); CHECK_FATAL(db.SCard(dbid, "myset2") != 5, "SUnionStore myset2 failed:"); }
ValueArray Client::FetchResults(const CommitFilter& f) const { SQLR * Select(SqlAll(RESULT), DT, CMT, BRANCH, UID, ToSqlVal(Regexp(PATH,data["SRC"])).As("FITS")) .From(COMMITS) .LeftJoin(RESULT).On(UID == CMT_UID && CLIENT_ID == data["ID"]) .Where(f) .OrderBy(Descending(DT)) .Limit(f.offset, f.limit); ValueArray res; ValueMap vm; Time t = GetUtcTime(); int maxage = int(data["MAX_AGE"])*24*60*60; while(SQLR.Fetch(vm)){ SetComputedAttributes(vm); SetDuration(vm, vm["STATUS"]); if (IsNull(vm["STATUS"])) { if (!vm["FITS"]) vm.Set("STATUSSTR", "Not interested"); else if (t-Time(vm["DT"]) > maxage) vm.Set("STATUSSTR", "Too old"); else vm.Set("STATUSSTR", "Ready"); } res.Add(vm); } return res; }
void Ide::MacroMenu(Bar& menu) { const Array<IdeMacro>& mlist = UscMacros(); if(!mlist.IsEmpty() && menu.IsMenuBar()) { VectorMap< String, Vector<int> > submenu_map; for(int i = 0; i < mlist.GetCount(); i++) { const IdeMacro& m = mlist[i]; if(!IsNull(m.menu)) { if(IsNull(m.submenu)) submenu_map.GetAdd(Null).Add(i); else submenu_map.GetAdd(m.menu).Add(i); } } if(!submenu_map.IsEmpty()) { Vector<int> order = GetSortOrder(submenu_map.GetKeys()); for(int o = 0; o < order.GetCount(); o++) { String m = submenu_map.GetKey(order[o]); Vector<int>& mx = submenu_map[order[o]]; ValueArray va; for(int i = 0; i < mx.GetCount(); i++) va.Add(mx[i]); if(!IsNull(m)) menu.Add(m, THISBACK1(EditMacroMenu, va)); else EditMacroMenu(menu, va); } } } }
void ValueMap::Data::Jsonize(JsonIO& jio) { if(jio.IsStoring()) { ValueArray va; int n = min(value.GetCount(), key.GetCount()); for(int i = 0; i < n; i++) { ValueMap m; m.Add("key", StoreAsJsonValue(key[i])); m.Add("value", StoreAsJsonValue(value[i])); va.Add(m); } jio.Set(va); } else { Value va = jio.Get(); key.Clear(); value.Clear(); for(int i = 0; i < va.GetCount(); i++) { Value k, v; LoadFromJsonValue(k, va[i]["key"]); LoadFromJsonValue(v, va[i]["value"]); key.Add(k); value.Add(v); } } }
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; }
ValueArray ParseXmlRpcParams(XmlParser& p) { ValueArray va; if(p.Tag("params")) while(!p.End()) va.Add(ParseXmlRpcParam(p)); return va; }
CountPtr<Value> ValueArray::iterator(void) const { ValueArray* tmp = new ValueArray(); tmp->m_val = m_val; tmp->resetIterator(); return CountPtr<Value>(tmp); }
ValueArray Sql::operator/(const SqlStatement& q) { ValueArray va; Execute(q); ValueMap m; while(Fetch(m)) va.Add(m); return va; }
/** * parse the special value "array". this method parses the complexer value "array" and returns it * @param p XmlParser holding the xml document * @return the parsed array as Value (not ValueArray!) */ Value XmlRpcParser::ParseArray(XmlParser& p) { ValueArray va; p.PassTag("data"); while(!p.End()) { Value v = Parse(p); va.Add(v); } return Value(va); }
Value FormatConvert::Format(const Value& v) const { ValueArray va; if(IsValueArray(v)) va = v; else va.Add(v); return UPP::Format(format, va.Get()); }
ValueArray Alias::selfTemplateArgs() const { ValueArray templateArgs; templateArgs.reserve(templateVariables().size()); for (const auto templateVar: templateVariables()) { // Refer to the template variables of this type alias. templateArgs.push_back(templateVar->selfRefValue()); } return templateArgs; }
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); }
ValueArray Commit::FetchResults() const { SQLR * Select(SqlAll()) .From(RESULT).InnerJoin(CLIENT).On(ID == CLIENT_ID) .Where(CMT_UID == data["UID"]); ValueArray res; ValueMap vm; while(SQLR.Fetch(vm)){ SetComputedAttributes(vm); SetDuration(vm, vm["STATUS"]); res.Add(vm); } return res; }
NAMESPACE_UPP Value ParseJSON(CParser& p) { p.UnicodeEscape(); if(p.IsDouble()) return p.ReadDouble(); if(p.IsString()) { bool dt = p.IsChar2('\"', '\\'); String s = p.ReadString(); if(dt) { CParser p(s); if(p.Char('/') && p.Id("Date") && p.Char('(') && p.IsInt()) { int64 n = p.ReadInt64(); if(!IsNull(n)) return Time(1970, 1, 1) + n / 1000; } } return s; } if(p.Id("null")) return Null; if(p.Id("true")) return true; if(p.Id("false")) return false; if(p.Char('{')) { ValueMap m; while(!p.Char('}')) { String key = p.ReadString(); p.PassChar(':'); m.Add(key, ParseJSON(p)); if(p.Char('}')) // Stray ',' at the end of list is allowed... break; p.PassChar(','); } return m; } if(p.Char('[')) { ValueArray va; while(!p.Char(']')) { va.Add(ParseJSON(p)); if(p.Char(']')) // Stray ',' at the end of list is allowed... break; p.PassChar(','); } return va; } p.ThrowError("Unrecognized JSON element"); return Null; }
void test_set_member(Ardb& db) { DBID dbid = 0; std::string str; db.SClear(dbid, "myset"); db.SAdd(dbid, "myset", "v1"); db.SAdd(dbid, "myset", "v2"); db.SAdd(dbid, "myset", "v3"); CHECK_FATAL(db.SIsMember(dbid, "myset", "v0") != false, "SIsMember myset failed:"); ValueArray members; db.SMembers(dbid, "myset", members); CHECK_FATAL( members.size() != 3, "SMembers myset failed:"); CHECK_FATAL( members[0].ToString(str) != "v1", "SMembers myset failed:"); }
inline bool operator==(const ValueArray& x, const ValueArray& y) { if (x.size() != y.size()) { return false; } for (uint32 i = 0; i < x.size(); i++) { if (x[i].Compare(y[i]) != 0) { return false; } } return true; }
void CAniClientConnection::OnPrivateChatUserListReceived( int iChatID, ValueArray<int>& arUsers ) { ASSERT( m_pDialog ); CDlgUserList* pChat = m_pDialog->CreateChatWindow( iChatID ); for ( int iUser = 0; iUser < arUsers.GetSize( ); iUser++ ) AddUserToPrivateChat( pChat, arUsers[ iUser ] ); }
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(); }
/** * Calculates vector a-b. * @return A new array holding a-b. */ static ValueArray subtractValues(const ValueArray& a, const ValueArray& b) { ValueArray result; for (unsigned int i = 0; i < a.size(); i++) { result[i] = a[i] - b[i]; } return result; }
Value Alias::selfRefValue(ValueArray templateArguments) const { assert(templateArguments.size() == templateVariables().size()); if (type()->isBuiltInTypename()) { const auto aliasRef = selfRefType(std::move(templateArguments)); return Value::TypeRef(aliasRef, type()->createStaticRefType(aliasRef)); } else { return Value::Alias(*this, std::move(templateArguments)); } }
void ValueArray::Insert(int i, const ValueArray& va) { if(va.data == data) { ValueArray va2 = va; Clone().Insert(i, va2.Get()); } else Clone().Insert(i, va.Get()); }
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; }
std::pair<std::complex<T> , std::complex<T> > operator()( const ValueArray<std::complex<T> > &ref ) const { BOOST_STATIC_ASSERT( sizeof( std::complex<T> ) == sizeof( T ) * 2 ); // we need this for the calcMinMax-hack below //use complex as a two element array and find the respective minmax for the two elements const std::pair<T, T > minmax[] = { calcMinMax<T, 2>( reinterpret_cast<const T *>( &ref[0] ), ref.getLength() * 2 ), calcMinMax<T, 2>( reinterpret_cast<const T *>( &ref[0] ) + 1, ref.getLength() * 2 ) }; //also use return as two element array and stuff results from above in there std::pair<std::complex<T> , std::complex<T> > ret; T *min = reinterpret_cast<T *>( &ret.first ), *max = reinterpret_cast<T *>( &ret.second ); for( int_fast8_t i = 0; i < 2; i++ ) { min[i] = minmax[i].first; max[i] = minmax[i].second; } return ret; }
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); }
std::pair<util::color<T> , util::color<T> > operator()( const ValueArray<util::color<T> > &ref ) const { std::pair<util::color<T> , util::color<T> > ret; for( uint_fast8_t i = 0; i < 3; i++ ) { const std::pair<T, T> buff = calcMinMax<T, 3>( &ref[0].r + i, ref.getLength() * 3 ); *( &ret.first.r + i ) = buff.first; *( &ret.second.r + i ) = buff.second; } return ret; }
ValueArray Commit::LoadPage(const CommitFilter& f) { SQLR * Select(SqlAll(), CountIf(1, STATUS==WD_INPROGRESS).As("RUNNING"), SqlFunc("sum",OK).As("OK"), SqlFunc("sum",FAIL).As("FAIL"), SqlFunc("sum",ERR).As("ERR"), SqlFunc("sum",SKIP).As("SKIP")) .From(COMMITS) .LeftJoin(RESULT).On(UID==CMT_UID) .Where(f) .GroupBy(UID) .OrderBy(Descending(DT)) .Limit(f.offset, f.limit); ValueArray res; ValueMap vm; while (SQLR.Fetch(vm)){ SetComputedAttributes(vm); res.Add(vm); } return res; }