Example #1
0
		Vector<String> String::SplitNoEmptyEntries(const String& string, const Vector<char>& delimiter, int count)
		{
			// variables
			int lastIndex = -1;
			Vector<String> vector;

			// compute result
			for (int i = 0; i < string._length; i++) {
				foreach(item, delimiter) {
					if (string._data[i] != item->CurrentItem()) {
						continue;
					} else if (i != lastIndex + 1) {
						vector.Add(String(string._data, lastIndex + 1, i - lastIndex - 1));
					}

					lastIndex = i;

					if (vector.Length >= count - 1) {
						vector.Add(String(string._data, lastIndex + 1, string._length - i - 1));
						return vector;
					}

					break;
				}
			}

			if (lastIndex != string._length - 1) {
				vector.Add(String(string._data, lastIndex + 1, string._length - lastIndex - 1));
			}

			return vector;
		}
Example #2
0
Vector<String> GetClipFiles(const String& data)
{
	GuiLock __;
	Vector<String> f;
	if((unsigned)data.GetCount() < sizeof(sDROPFILES) + 2)
		return f;
	const sDROPFILES *df = (const sDROPFILES *)~data;
	const char *s = ((const char *)df + df->offset);
	if(df->unicode) {
		const wchar *ws = (wchar *)s;
		while(*ws) {
			WString fn;
			while(*ws)
				fn.Cat(*ws++);
			f.Add(fn.ToString());
			ws++;
		}
	}
	else
		while(*s) {
			String fn;
			while(*s)
				fn.Cat(*s++);
			f.Add(fn.ToString());
			s++;
		}
	return f;
}
Example #3
0
		Vector<String> String::SplitEmptyEntries(const String& string, const String& delimiter, int count)
		{
			// variables
			int index = 0;
			int lastIndex = -1;
			Vector<String> vector;

			while (index != -1) {
				index = string.IndexOf(delimiter, lastIndex + 1);
				
				if (lastIndex + 1 == index) {
					vector.Add(String());
				} else {
					// TODO: readable calculation
					int startIndex = ((lastIndex == -1) ? (0) : (lastIndex + delimiter._length));
					int length = ((index == -1) ? (string._length - lastIndex - delimiter._length) : (index - lastIndex - delimiter._length));
					vector.Add(String(string._data, startIndex, length));
				}

				lastIndex = index;

				if (vector.Length >= count - 1) {
					// TODO: readable calculation
					int startIndex = ((lastIndex == -1) ? (0) : (lastIndex + delimiter._length));
					int length = ((lastIndex == -1) ? (string._length) : (string._length - lastIndex - delimiter._length));
					vector.Add(String(string._data, startIndex, length));
					return vector;
				}
			}

			return vector;
		}
Example #4
0
static void CalcHash(Vector<HashBase>& hash, const Vector<String>& file, int limit)
{
	{ // 1st row
		HashBase& first = hash.Add();
		for(int i = 0; i < file.GetCount(); i++)
			first.Add(GetHashValue(file[i]));
	}
	static const int prime[] =
	{
		3,  5,  7,   11,  13,  17,  19,  21,
		23, 29, 31,  37,  41,  43,  47,  51,
		53, 61, 67,  71,  73,  79,  83,  87,
		89, 97, 101, 103, 107, 109, 113, 117,
	};
	const int *pp = prime;
	for(int l = 1; l < limit; l <<= 1) {
		HashBase& nhash = hash.Add();
		const HashBase& ohash = hash[hash.GetCount() - 2];
		int pri = *pp++;
		int t;
		for(t = l; t < ohash.GetCount(); t++)
			nhash.Add(ohash[t - l] + pri * ohash[t]);
		for(t -= l; t < ohash.GetCount(); t++)
			nhash.Add(ohash[t]);
	}
}
Example #5
0
File: t.cpp Project: pedia/raidget
void AddModule(const LngEntry__* l, const char *name)
{
	CriticalSection::Lock __(slng);
	Array<LngModule>& ma = sMod();
	LngModule& m = ma.Add();
	m.name = name;
	Vector<LngRec> *lr = NULL;
	while(l->lang) {
		if(l->lang == 1) {
			CharS ids;
			ids.s = l->text;
			lr = &m.map.GetAdd(ids);
			LngRec& r = lr->Add();
			r.lang = LNG_('E','N','U','S');
			r.text = GetENUSc(l->text);
		}
		else
		if(l->text && *l->text) {
			LngRec& r = lr->Add();
			r.lang = l->lang;
			r.text = l->text;
		}
		l++;
	}
}
Example #6
0
String MakeBuild::OutDir(const Index<String>& cfg, const String& package, const VectorMap<String, String>& bm,
                   bool use_target)
{
	Index<String> excl;
	excl.Add(bm.Get("BUILDER", "GCC"));
	excl.Add("MSC");
	LocalHost().AddFlags(excl);
	Vector<String> x;
	bool dbg = cfg.Find("DEBUG_FULL") >= 0 || cfg.Find("DEBUG_MINIMAL") >= 0;
	if(cfg.Find("DEBUG") >= 0) {
		excl.Add("BLITZ");
		if(cfg.Find("BLITZ") < 0)
			x.Add("NOBLITZ");
	}
	else
		if(dbg)
			x.Add("RELEASE");
	if(use_target)
		excl.Add("MAIN");
	for(int i = 0; i < cfg.GetCount(); i++)
		if(excl.Find(cfg[i]) < 0)
			x.Add(cfg[i]);
	Sort(x);
	for(int i = 0; i < x.GetCount(); i++)
		x[i] = InitCaps(x[i]);
	String outdir = GetVar("OUTPUT");
	if(output_per_assembly)
		outdir = AppendFileName(outdir, GetVarsName());
	if(!use_target)
		outdir = AppendFileName(outdir, package);
	outdir = AppendFileName(outdir, GetFileTitle(method) + "." + Join(x, "."));
	outdir = Filter(outdir, CharFilterSlash);
	return outdir;
}
Example #7
0
void HeaderCtrl::Distribute(const Vector<int>& sci, double delta)
{
	Vector<int> ci(sci, 1);
	int szcx = GetSize().cx;
	if(szcx == 0)
		return;
	double rs = Denominator();
	double eps = max(1.0e-6, rs / 1.0e6);
	double epsr = max(1.0e-4, rs / 1.0e4);
	bool checkmin = SumMin(0) < szcx;
	for(;;) {
		double psm = 0;
		for(int i = 0; i < ci.GetCount(); i++)
			psm += col[ci[i]].ratio;
		if(fabs(psm) < eps)
			return;
		double q = 1 + delta / psm;
		double x = 0;
		Vector<int> nci;
		for(int i = 0; i < ci.GetCount(); i++) {
			Column& c = col[ci[i]];
			c.ratio *= q;
			if(c.ratio < epsr)
				c.ratio = epsr;
			else
			if(c.ratio < c.min * rs / szcx && checkmin) {
				c.ratio = c.min * rs / szcx;
				if(delta > 0)
					nci.Add(ci[i]);
			}
			else
			if(c.ratio > c.max * rs / szcx) {
				c.ratio = c.max * rs / szcx;
				if(delta < 0)
					nci.Add(ci[i]);
			}
			else
				nci.Add(ci[i]);
			x += c.ratio;
		}

		delta = (psm + delta) - x;

		if(fabs(delta) < eps)
			break;
		ci = pick(nci);
		if(ci.GetCount() == 0) {
			double psm = 0;
			for(int i = 0; i < sci.GetCount(); i++)
				psm += col[sci[i]].ratio;
			if(fabs(psm) < eps)
				return;
			double q = 1 + delta / psm;
			for(int i = 0; i < sci.GetCount(); i++)
				col[sci[i]].ratio *= q;
			return;
		}
	}
}
Example #8
0
void MainWindow::AddName(int i, const char * a_name)
{
	Vector<Value> vec;
	vec.Add(i);
	vec.Add(a_name);
	vec.Add(i*10);
	m_array.Add(vec);
}
Example #9
0
void ContainerClientTypes()
{
	/// .Client types in U++ containers

	/// So far we were using int as type of elements. In order to store client defined types
	/// into the `Vector` (and the Vector ^topic://Core/src/Overview$en-us:flavor^) the type
	/// must satisfy ^topic://Core/src/Moveable$en-us:moveable^ requirement - in short, it must
	/// not contain back-pointers nor virtual methods. Type must be marked as %moveable% in
	/// order to define interface contract using `Moveable`
	/// ^https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern:CRTP idiom^:

	struct Distribution : Moveable<Distribution> {
		String      text;
		Vector<int> data;
		
		String ToString() const { return text + ": " + AsString(data); }
	};


	/// Now to add `Distribution` elements you cannot use `Vector::Add(const T&)`, because it requires
	/// elements to have default deep-copy constructor - and `Distribution does not have one, as
	/// `Vector<int>` has default pick-constructor, so Distribution itself has pick-constructor.
	/// It would no be a good idea either, because deep-copy would involve expensive copying of
	/// inner Vector.
	
	/// Instead, Add without parameters has to be used - it default constructs (that is cheap)
	/// element in Vector and returns reference to it:

	Vector<Distribution> dist;
	for(int n = 5; n <= 10; n++) {
		Distribution& d = dist.Add();
		d.text << "Test " << n;
		for(int i = 0; i < 10000; i++)
			d.data.At(Random(n), 0)++;
	}
	
	DUMPC(dist);

	/// Another possibility is to use `Vector::Add(T&&)` method, which uses pick-constructor
	/// instead of deep-copy constructor. E.g. `Distribution` elements might be generated by
	/// some function:

#if 0
	Distribution CreateDist(int n);

	/// and code for adding such elements to Vector then looks like:

	for(n = 5; n <= 10; n++)
		dist.Add(CreateDist(n));

	/// alternatively, you can use default-constructed variant too

		dist.Add() = CreateDist();
#endif

	///
}
Example #10
0
Vector<Ctrl *> Ctrl::GetTopCtrls()
{
	Vector<Ctrl *> ctrl;
	if(desktop)
		ctrl.Add(desktop);
	for(int i = 0; i < topctrl.GetCount(); i++)
		if(!dynamic_cast<TopWindowFrame *>(topctrl[i]))
			ctrl.Add(topctrl[i]);
	return ctrl;
}
Example #11
0
File: t.cpp Project: pedia/raidget
char *ZoneAlloc::Alloc(int sz)
{
	if(sz >= 1024)
		return zbig.Add() = new char[sz];
	if(ptr + sz >= lim) {
		zsmall.Add() = ptr = new char[4096];
		lim = ptr + 4096;
	}
	char *s = ptr;
	ptr += sz;
	return s;
}
Example #12
0
void Scan(const XmlNode& n, bool nano)
{
	for(int i = 0; i < n.GetCount(); i++) {
		total_len += n.GetText().GetCount();
		if(nano)
			ws.Add(ns.Add(n.GetText()));
		else
			ss.Add(n.GetText());
		if(n[i].IsTag()) {
			Scan(n[i], nano);
		}
	}
}
Example #13
0
void RichEdit::ReadStyles()
{
	int i;
	style.Clear();
	Vector<Uuid> id;
	Vector<String> name;
	for(i = 0; i < text.GetStyleCount(); i++) {
		id.Add(text.GetStyleId(i));
		name.Add(text.GetStyle(i).name);
	}
	IndexSort(name, id, sCompareLess());
	for(i = 0; i < id.GetCount(); i++)
		style.Add(id[i], name[i]);
}
Example #14
0
void sGatherAllExt(Vector<String>& files, Vector<String>& dirs, const String& pp, const String& p)
{
	dirs.Add(p);
	FindFile ff(pp + "/" + p + "/*.*");
	while(ff) {
		String n = Merge("/", p, ff.GetName());
		if(ff.IsFile())
			files.Add(n);
		else
		if(ff.IsFolder()) {
			sGatherAllExt(files, dirs, pp, n);
		}
		ff.Next();
	}
}
Example #15
0
		virtual Vector<String> AutoComplete (const CommandEvent & event) override {
		
			Vector<String> retr;
			
			if (
				//	If there's more than two arguments,
				//	the two arguments we could make suggestions
				//	based on are out the window, so just return
				//	no suggestions
				(event.Arguments.Count()>2) ||
				//	If there's exactly two arguments, and the
				//	first argument isn't the quiet arg, the
				//	first argument is the username, so we still
				//	can't make any suggestions
				(
					(event.Arguments.Count()==2) &&
					(event.Arguments[0]!=quiet_arg)
				)
			) return retr;
			
			//	Can we suggest the quiet arg?
			if (
				//	If there are no arguments, we
				//	definitely can
				(event.Arguments.Count()==0) ||
				//	Otherwise the first argument has
				//	to match the quiet arg in some way
				(
					(event.Arguments.Count()==1) &&
					Regex(
						String::Format(
							regex,
							Regex::Escape(event.Arguments[0])
						)
					).IsMatch(quiet_arg)
				)
			) retr.Add(quiet_arg);
			
			//	Loop over all clients that we can
			//	suggest
			for (auto & client : Server::Get().Clients.Get(
				event.Arguments[event.Arguments.Count()-1],
				ClientSearch::Begin
			)) if (client->GetState()==ProtocolState::Play) retr.Add(client->GetUsername());
			
			return retr;
		
		}
Example #16
0
String GetExeFilePath()
{
	static String exepath;
	ONCELOCK {
		const char *exe = procexepath_();
		if(*exe)
			exepath = exe;
		else {
			String x = Argv0__;
			if(IsFullPath(x) && FileExists(x))
				exepath = x;
			else {
				exepath = GetHomeDirFile("upp");
				Vector<String> p = Split(FromSystemCharset(Environment().Get("PATH")), ':');
				if(x.Find('/') >= 0)
					p.Add(GetCurrentDirectory());
				for(int i = 0; i < p.GetCount(); i++) {
					String ep = NormalizePath(AppendFileName(p[i], x));
					if(FileExists(ep))
						exepath = ep;
				}
			}
		}
	}
	return exepath;
}
Example #17
0
Vector<String> SplitFlags(const char *flags, bool main, const Vector<String>& accepts)
{
	Vector<String> v = SplitFlags0(flags);
	Vector<String> h;
	for(int i = 0; i < v.GetCount(); i++)
		if(v[i][0] == '.') {
			String f = v[i].Mid(1);
			if(main || FindIndex(accepts, f) >= 0)
				h.Add(v[i].Mid(1));
		}
		else
			h.Add(v[i]);
	if(main)
		h.Add("MAIN");
	return h;
}
Example #18
0
Vector<SqlColumnInfo> Sqlite3Session::EnumColumns(String database, String table) {
	Vector<SqlColumnInfo> out;
	SqlColumnInfo info;
	String ColType;
	Sql sql(*this);
	sql.Execute("PRAGMA table_info("+table+");");
	while (sql.Fetch()) {
		info.width = info.scale = info.precision = 0;
		info.name = sql[1];
		ColType   = sql[2];
		if(ColType =="integer")
			info.type = INT_V;
		else
		if(ColType =="real")
			info.type = DOUBLE_V;
		else
		if (ColType =="date")
			info.type = DATE_V;
		else
		if (ColType == "datetime")
			info.type = TIME_V;
		else
			info.type = STRING_V;
		out.Add(info);
	}
	return out;
}
void AresDataCollectorSystem::PopLog(Vector &v_tmp)
{
	if(mv_log.Size()>0){
		v_tmp.Add(mv_log.Get(0));
		mv_log.Remove(0);
	}
}
void AresSupernodeSystem::PopQueryLog(Vector& v)
{
	if(mv_query_log.Size()>0){
		v.Add(mv_query_log.Get(0));
		mv_query_log.Remove(0);
	}
}
Example #21
0
bool ODBCConnection::Fetch()
{
	if(rowi >= rowcount)
		return false;
	fetchrow.Clear();
	for(int i = 0; i < info.GetCount(); i++) {
		Value v;
		switch(info[i].type) {
		case DOUBLE_V:
			v = number[number_i++];
			break;
		case INT64_V:
			v = num64[num64_i++];
			break;
		case TIME_V:
			v = time[time_i++];
			break;
		case DATE_V:
			v = date[date_i++];
			break;
		case STRING_V:
			v = text[text_i++];
			break;
		default:
			NEVER();
		}
		fetchrow.Add(v);
	}
	++rowi;
	return true;
}
Example #22
0
String NormalizePath(const char *path, const char *currdir) {
	Vector<String> si = Split(path, CharFilterTextTest(sDirSep));
	Vector<String> p;
	int i = 0;
	String out;
	if(path[0] == '~') {
		out = GetHomeDirectory();
		i++;
	}
	else
	if(sDirSep(path[0]))
		out = (sDirSep(path[1]) ? "//" : "/");
	else {
		out = (sDirSep(currdir[0]) && sDirSep(currdir[1]) ? "//" : "/");
		p = Split(currdir, CharFilterTextTest(sDirSep));
	}
	for(; i < si.GetCount(); i++) {
		String s = si[i];
		if(s != "." && !s.IsEmpty())
			if(s[0] == '.' && s[1] == '.') {
				if(!p.IsEmpty()) p.Drop();
			}
			else
				p.Add(s);
	}
	out.Cat(Join(p, DIR_SEPS));
	return out;
}
Example #23
0
Vector<String> RegExp::GetStrings()
{
	Vector<String> subs;
	for(int i = 0; i < GetCount(); i++)
		subs.Add(GetString(i));
	return subs;
}
Example #24
0
//true indicates it is still ok
//false indicates there has been a serious error and this connection is lost
bool ComConnection::CheckData(Vector &v_received_objects)
{
	if(!mb_dirty)
		return true;
	mb_dirty=false;
	while(true){
		DataBuffer* db=new DataBuffer();
		int stat=db->ReadFromBuffer(m_peer.c_str(),m_received_data.GetMutableBufferPtr(),m_received_data.GetLength());
			
		if(stat<0){
			delete db;
			return false;
		}
		else if(stat==0){
			delete db;
			return true;
		}
		else{
			v_received_objects.Add(db);
			m_received_data.RemoveRange(0,stat);
			g_com_dialog.PostReceive(db->GetOpCode(),m_peer.c_str(),stat);
		}
	}

	//should never get here
	ASSERT(0);
	return false;
}
Example #25
0
static bool MatchAlias(const char *s, const char *t, Vector<String>& a)
{
	while(*t)
		switch(*t++)
		{
		case '*':
			{
				const char *b = s;
				do
				{
					a.Add(String(b, s));
					if(MatchAlias(s, t, a))
						return true;
					a.Drop();
				}
				while(*s++);
				return false;
			}

		default:
			if(t[-1] != *s++)
				return false;
			break;
		}
	return !*s;
}
Example #26
0
void BoundaryNormalLFIntegrator::AssembleRHSElementVect(
    const FiniteElement &el, ElementTransformation &Tr, Vector &elvect)
{
    int dim = el.GetDim()+1;
    int dof = el.GetDof();
    Vector nor(dim), Qvec;

    shape.SetSize(dof);
    elvect.SetSize(dof);
    elvect = 0.0;

    const IntegrationRule *ir = IntRule;
    if (ir == NULL)
    {
        int intorder = oa * el.GetOrder() + ob;  // <----------
        ir = &IntRules.Get(el.GetGeomType(), intorder);
    }

    for (int i = 0; i < ir->GetNPoints(); i++)
    {
        const IntegrationPoint &ip = ir->IntPoint(i);

        Tr.SetIntPoint(&ip);
        CalcOrtho(Tr.Jacobian(), nor);
        Q.Eval(Qvec, Tr, ip);

        el.CalcShape(ip, shape);

        elvect.Add(ip.weight*(Qvec*nor), shape);
    }
}
Example #27
0
void Print(Draw& w, const RichText& text, const Rect& page)
{
	int n = text.GetHeight(page).page;
	Vector<int> pg;
	for(int i = 0; i <= n; i++)
		pg.Add(i);
	Print(w, text, page, pg);
}
Example #28
0
Vector<Ctrl *> Ctrl::GetTopCtrls()
{
	GuiLock __;
	Vector<Ctrl *> h;
	for(int i = 0; i < wins.GetCount(); i++)
		h.Add(wins[i].ctrl);
	return h;
}
Example #29
0
Vector<Rect> Ctrl::GetPaintRects()
{
	Vector<Rect> r;
	r.Add(GetScreenRect());
	for(int i = max(FindTopCtrl() + 1, 0); i < topctrl.GetCount(); i++)
		Subtract(r, topctrl[i]->GetScreenRect());
	return r;
}
Example #30
0
Vector<int> HeaderCtrl::GetVisibleCi(int from)
{
	Vector<int> sci;
	for(int i = from; i < col.GetCount(); i++)
		if(col[i].visible)
			sci.Add(i);
	return sci;
}