Example #1
0
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);
		}
	}
}
Example #2
0
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);
			}
		}
	}
}
Example #3
0
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;
}
Example #4
0
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;
}
Example #5
0
ValueArray ParseXmlRpcParams(XmlParser& p)
{
	ValueArray va;
	if(p.Tag("params"))
		while(!p.End())
			va.Add(ParseXmlRpcParam(p));
	return va;
}
Example #6
0
/**
* 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);
}
Example #7
0
Value FormatConvert::Format(const Value& v) const
{
	ValueArray va;
	if(IsValueArray(v))
		va = v;
	else
		va.Add(v);
	return UPP::Format(format, va.Get());
}
Example #8
0
ValueArray Sql::operator/(const SqlStatement& q)
{
	ValueArray va;
	Execute(q);
	ValueMap m;
	while(Fetch(m))
		va.Add(m);
	return va;
}
Example #9
0
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;
}
Example #10
0
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;
}
Example #11
0
/**
* parse a method call. it parses a xml message sent by a client and returns the method name and
* the parameter it contains.
* @param s the received data
* @return the value, which includes an ValueArray with first element beeing the method name
* @see ParseMethodResponse()
*/
Value XmlRpcParser::ParseMethodCall(String s){
	XmlParser p(s);
	ValueArray va;

	try {
		while(!p.Tag("methodCall"))
		      p.Skip();
		p.PassTag("methodName");
		va.Add(Value(p.ReadText()));
		p.PassEnd(); //methodName
		p.PassTag("params");
		while(p.Tag("param")) {
			va.Add(Parse(p));
			p.PassEnd(); //param
		}
		p.PassEnd(); //params
		p.PassEnd(); //methodCall
		LOG("request parsed");
	} catch(Exc e) {
		return ErrorValue(NFormat("EXCEPTION: %s",e));
	}
	return Value(va);
}
Example #12
0
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;
}
Example #13
0
NAMESPACE_UPP

Value ParseJSON(CParser& p)
{
	p.UnicodeEscape();
	if(p.IsNumber())
		return p.ReadDouble();
	if(p.IsString())
		return p.ReadString();
	if(p.Id("null"))
		return Null;
	if(p.Id("true"))
		return true;
	if(p.Id("false"))
		return false;
	if(p.Char('{')) {
		ValueMap m;
		if(!p.IsChar('}'))
			do {
				String key = p.ReadString();
				p.PassChar(':');
				m.Add(key, ParseJSON(p));
			}
			while(p.Char(','));
		p.PassChar('}');
		return m;
	}
	if(p.Char('[')) {
		ValueArray va;
		if(!p.IsChar(']'))
			do
				va.Add(ParseJSON(p));
			while(p.Char(','));
		p.PassChar(']');
		return va;		
	}
	p.ThrowError("Unrecognized JSON element");
	return Null;
}
Example #14
0
NAMESPACE_UPP

Value ParseXmlRpcValue(XmlParser& p)
{
	Value r;
	p.PassTag("value");
	if(p.Tag("int") || p.Tag("i4")) {
		String s = p.ReadText();
		CParser p(s);
		if(!p.IsInt())
			throw XmlError("integer expected");
		r = p.ReadInt();
	}
	else
	if(p.Tag("boolean")) {
		int n = StrInt(p.ReadText());
		if(n != 0 && n != 1)
			throw XmlError("boolean expected");
		r = (bool)n;
	}
	else
	if(p.Tag("double")) {
		String s = p.ReadText();
		CParser p(s);
		if(!p.IsDouble())
			throw XmlError("double expected");
		r = p.ReadDouble();
	}
	else
	if(p.Tag("string") || p.Tag("base64"))
		r = p.ReadText();
	else
	if(p.TagE("nil")) {
		p.PassEnd();
		return r;
	}
	else
	if(p.Tag("dateTime.iso8601")) {
		String s = TrimBoth(p.ReadText());
		// 19980717T14:08:55
		// 01234567890123456
		if(s.GetCount() != 17 || s[8] != 'T' || s[11] != ':' || s[14] != ':')
			throw XmlError("invalid dateTime format");
		Time tm;
		tm.year = atoi(s.Mid(0, 4));
		tm.month = atoi(s.Mid(4, 2));
		tm.day = atoi(s.Mid(6, 2));
		tm.hour = atoi(s.Mid(9, 2));
		tm.minute = atoi(s.Mid(12, 2));
		tm.second = atoi(s.Mid(15, 2));
		r = tm;
	}
	else
	if(p.Tag("array")) {
		ValueArray va;
		p.PassTag("data");
		while(!p.End())
			va.Add(ParseXmlRpcValue(p));
		r = va;
	}
	else
	if(p.Tag("struct")) {
		ValueMap vm;
		while(p.Tag("member")) {
			p.PassTag("name");
			String name = p.ReadText();
			p.PassEnd();
			vm.Add((Value)name, ParseXmlRpcValue(p));
			p.PassEnd();
		}
		r = vm;
	}
	else
		throw XmlError("unknown value type");
	p.PassEnd();
	p.PassEnd();
	return r;
}