Example #1
0
void MapEditor::OnLevelMapCalc(Level& level, int number)
{
	if (level.GetMapBG().IsEmpty())
	{
		Exclamation(NFormat(t_("Please, select the image for level: %s"), level.GetName()));
		return;
	}

	String fp = AppendFileName( AppendFileName( GetFileDirectory(GetExeFilePath()), "Maps"),
		level.GetMapBG());

	if (!FileExists(fp))
	{
		Exclamation(NFormat(t_("Image file not exist: %s"), fp));
		return;
	}

	String name = level.GetName();
	double zx   = level.GetZoomDX();
	Size   pz   = level.GetPageSize();
	Size   sz   = level.GetCellSize();

	FileIn in(fp);
	One<StreamRaster> r = StreamRaster::OpenAny(in);
	if (!r)
	{
		Exclamation(NFormat(t_("Error while loading image file: %s"), fp));
		return;
	}

	Image img = r->GetImage();
	Calculate(sz.cx, sz.cy, pz.cx, pz.cy, zx,
		NFormat("%s-%d", _map.GetName(), number + 1), img);
}
Example #2
0
void Ide::Preprocess(bool asmout) {
    if(editfile.IsEmpty())
        return;
    int pi = GetPackageIndex();
    if(pi < 0) return;
    SwitchHeader();
    String pfn = ConfigFile(GetFileTitle(editfile) + ".i.tmp");
    DeleteFile(pfn);
    const Workspace& wspc = IdeWorkspace();
    if(pi >= wspc.GetCount())
        return;
    One<Host> host = CreateHost(true);
    One<Builder> b = CreateBuilder(~host);
    Vector<String> linkfile;
    String linkopt;
    b->config = PackageConfig(wspc, pi, GetMethodVars(method), mainconfigparam, *host, *b);
    console.Clear();
    PutConsole((asmout ? "Compiling " : "Preprocessing ") + editfile);
    b->Preprocess(wspc[pi], editfile, pfn, asmout);
    HideBottom();
    if(FileExists(pfn)) {
        EditFile(pfn);
        if(!editor.IsReadOnly())
            ToggleReadOnly();
    }
}
Example #3
0
void Draw::DrawDataOp(int x, int y, int cx, int cy, const String& data, const char *id)
{
	bool tonative = !IsNative();
	if(tonative) {
		BeginNative();
		Native(x, y);
		Native(cx, cy);
	}
	One<DataDrawer> dd = DataDrawer::Create(id);
	if(dd) {
		dd->Open(data, cx, cy);
		if((cx > 2048 || cy > 2048) && (GetInfo() & DATABANDS)) {
			int yy = 0;
			while(yy < cy) {
				int ccy = min(cy - yy, 32);
				ImageBuffer ib(cx, ccy);
				dd->Render(ib);
				DrawImageBandRLE(*this, x, y + yy, ib, 16);
				yy += ccy;
			}
		}
		else {
			ImageBuffer m(cx, cy);
			dd->Render(m);
			DrawImage(x, y, m);
		}
	}
	if(tonative)
		EndNative();
}
Example #4
0
int run_main (int, ACE_TCHAR *[])
{
  ACE_START_TEST (ACE_TEXT ("Intrusive_Auto_Ptr_Test"));


  One *theone (new One(0));

  {
    ACE_TEST_ASSERT (theone->has_refs (0));
    ACE_TEST_ASSERT (!One::was_released ());

    ACE_Intrusive_Auto_Ptr<One> ip2(theone);

    {
      ACE_TEST_ASSERT (theone->has_refs (1));
      ACE_TEST_ASSERT (!One::was_released ());

      ACE_Intrusive_Auto_Ptr<One> ip2(theone);
      ACE_TEST_ASSERT (theone->has_refs (2));
      ACE_TEST_ASSERT (!One::was_released ());
    }

    ACE_TEST_ASSERT (theone->has_refs (1));
    ACE_TEST_ASSERT (!One::was_released ());
  }

  ACE_TEST_ASSERT (One::was_released());

  ACE_END_TEST;
  return 0;
}
Example #5
0
One<Debugger> PdbCreate(One<Host> host, const String& exefile, const String& cmdline)
{
	One<Debugger> dbg;
	if(!dbg.Create<Pdb>().Create(host, exefile, cmdline))
		dbg.Clear();
	return dbg;
}
Example #6
0
Size RichRawImage::GetPixelSize(const Value& data) const
{
	String s = data;
	StringStream ss(s);
	One<StreamRaster> r = StreamRaster::OpenAny(ss);
	if(r)
		return r->GetSize();
	return Size(0, 0);
}
Example #7
0
Size RichRawImage::GetPhysicalSize(const Value& data) const
{
	String s = data;
	StringStream ss(s);
	One<StreamRaster> r = StreamRaster::OpenAny(ss);
	if(r)
		return r->GetInfo().dots;
	return Size(0, 0);
}
Example #8
0
One<Host> Ide::CreateHostRunDir()
{
	One<Host> h = CreateHost(false);
	if(IsNull(rundir))
		h->ChDir(GetFileFolder(target));
	else
		h->ChDir(rundir);
	return h;
}
Example #9
0
void Ide::BuildAndDebug(bool runto)
{
	VectorMap<String, String> bm = GetMethodVars(method);
	String builder = bm.Get("BUILDER", "");
	if(!Build())
		return;
	if(!FileExists(target))
		return;
	if(designer)
		EditAsText();
	One<Host> host = CreateHostRunDir();
	host->ChDir(Nvl(rundir, GetFileFolder(target)));
	HideBottom();
	editor.Disable();
#ifdef COMPILER_MSC
	if(builder == "GCC")
		if(gdbSelector)
			debugger = Gdb_MI2Create(host, target, runarg);
		else
			debugger = GdbCreate(host, target, runarg);
	else
		debugger = PdbCreate(host, target, runarg);
#else
	if(gdbSelector)
		debugger = Gdb_MI2Create(host, target, runarg);
	else
		debugger = GdbCreate(host, target, runarg);
#endif
	if(!debugger) return;
	debuglock = 0;
	const Workspace& wspc = IdeWorkspace();
	for(int i = 0; i < wspc.GetCount(); i++) {
		const Package& pk = wspc.GetPackage(i);
		String n = wspc[i];
		for(int i = 0; i < pk.file.GetCount(); i++) {
			String file = SourcePath(n, pk.file[i]);
			LineInfo& ln = Filedata(file).lineinfo;
			for(int i = 0; i < ln.GetCount(); i++) {
				LineInfoRecord& lr = ln[i];
				if(!lr.breakpoint.IsEmpty())
					if(!debugger->SetBreakpoint(file, lr.lineno, lr.breakpoint)) {
						lr.breakpoint = "\xe";
						if(PathIsEqual(file, editfile))
							editor.SetBreakpoint(lr.lineno, "\xe");
					}
			}
		}
	}
	SetBar();
	editor.Enable();
	if(runto) {
		if(!debugger->RunTo())
			IdeEndDebug();
	}
	else
		debugger->Run();
}
Example #10
0
bool Socket::Data::Accept(Socket& socket, dword *ipaddr, bool nodelay, int timeout_msec)
{
	SOCKET connection = AcceptRaw(ipaddr, timeout_msec);
	if(connection == INVALID_SOCKET)
		return false;
	One<Socket::Data> data = new Data;
	data->Attach(connection, nodelay, is_blocking);
	socket.Attach(data);
	return true;
}
Example #11
0
void Compiler::OptimizeConst(One<Exe>& exe)
{
	One<Exe> oxe;
	Vector<Value> stack;
	ExeContext x(stack);
	oxe.Create<ExeConst>().value = exe->Eval(x);
	LLOG("OPTIMIZED constant: " << exe->Eval(stack, out));
	exe = pick(oxe);
	optimized = true;
}
Example #12
0
void MakeBuild::CleanPackage(const Workspace& wspc, int package)
{
	PutConsole(NFormat("Cleaning %s", wspc[package]));
	One<Host> host = CreateHost(false);
	One<Builder> builder = CreateBuilder(~host);
	if(!builder)
		return;
	host->DeleteFolderDeep(OutDir(PackageConfig(wspc, package, GetMethodVars(method), mainconfigparam,
		*host, *builder), wspc[package], GetMethodVars(method)));
}
Example #13
0
Image RichRawImage::ToImage(const Value& data, Size sz, void *) const
{
	String s = data;
	StringStream ss(s);
	One<StreamRaster> r = StreamRaster::OpenAny(ss);
	if(r) {
		Image x = r->GetImage();
		return Rescale(x, sz);
	}
	return Null;
}
Example #14
0
bool Pdb::Create(One<Host> local, const String& exefile, const String& cmdline)
{
	STARTUPINFO si;
	ZeroMemory(&si, sizeof(STARTUPINFO));
	si.cb = sizeof(STARTUPINFO);
	si.dwFlags = 0;
	String cl;
	if(exefile.Find(' ') >= 0)
		cl << '\"' << exefile << '\"';
	else
		cl << exefile;
	if(!IsNull(cmdline))
		cl << ' ' << cmdline;

	Buffer<char> cmd(cl.GetLength() + 1);
	memcpy(cmd, cl, cl.GetLength() + 1);
	PROCESS_INFORMATION pi;
	ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
	Buffer<char> env(local->GetEnvironment().GetCount() + 1);
	memcpy(env, ~local->GetEnvironment(), local->GetEnvironment().GetCount() + 1);
	bool h = CreateProcess(exefile, cmd, NULL, NULL, TRUE,
	                       NORMAL_PRIORITY_CLASS|CREATE_NEW_CONSOLE|DEBUG_ONLY_THIS_PROCESS|DEBUG_PROCESS,
	                       ~env, NULL, &si, &pi);
	if(!h) {
		Exclamation("Error creating process&[* " + DeQtf(exefile) + "]&" +
		            "Windows error: " + DeQtf(GetLastErrorMessage()));
		return false;
	}
	hProcess = pi.hProcess;
	CloseHandle(pi.hThread);

	IdeSetBottom(*this);
	IdeSetRight(disas);

	LoadFromGlobal(*this, CONFIGNAME);

	if(!SymInitialize(hProcess, 0, FALSE)) {
		Error();
		return false;
	}
	SymSetOptions(SYMOPT_LOAD_LINES|SYMOPT_UNDNAME|SYMOPT_NO_UNQUALIFIED_LOADS);

	lock = 0;
	stop = false;
	refreshmodules = true;
	terminated = false;

	running = true;

	RunToException();
//	Sync();

	return true;
}
Example #15
0
void Ide::BuildAndDebug0(const String& srcfile)
{
	if(Build()) {
		One<Host> h = CreateHostRunDir();
		h->ChDir(GetFileFolder(target));
		VectorMap<String, String> bm = GetMethodVars(method);
		String dbg = bm.Get("DEBUGGER", Null);
		if(IsNull(dbg)) {
			if(bm.Get("BUILDER", Null) == "MSC71") {
				String sln = ForceExt(target, ".sln");
				if(GetFileLength(sln) > 0)
					h->Launch("devenv \"" + h->GetHostPath(sln) + "\" "
					// + "\"" + h->GetHostPath(srcfile) + "\"" //TRC, 2011/09/26: wrong devenv argument
					);
				else
					h->Launch("devenv \"" + h->GetHostPath(target)
					//+ "\" \"" + h->GetHostPath(srcfile) //TRC, 2011/09/26: wrong devenv argument
					+ "\" /debugexe "
					);
				return;
			}
			dbg = "gdb";
		}
		else
			h->Launch('\"' + dbg + "\" \""
//			          + h->GetHostPath(srcfile) + ' '
			          + h->GetHostPath(target) + "\"", true);
	}
}
Example #16
0
void RichRawImage::Paint(const Value& data, Draw& w, Size sz, void *) const
{
	String s = data;
	StringStream ss(s);
	One<StreamRaster> r = StreamRaster::OpenAny(ss);
	if(r) {
		Size isz = r->GetSize();
		if(isz.cx * isz.cy > sz.cx * sz.cy) { // conserve memory by scaling down from source
			ImageEncoder m;
			Rescale(m, sz, *r, r->GetSize());
			w.DrawImage(0, 0, sz.cx, sz.cy, m);
		}
		else
			w.DrawImage(0, 0, sz.cx, sz.cy, r->GetImage()); // scale up by Draw to give e.g. PDF chance to store unscaled
	}
}
Example #17
0
String Render(const One<Exe>& exe, Renderer *r, Vector<Value>& var)
{
	LTIMING("Render0");
	ExeContext x(var, r);
	Value v = exe->Eval(x);
	x.out.Cat(AsString(v));
	return x.out;
}
Example #18
0
void cDrawRasterData::Open(const String& data, int _cx, int cy)
{
	cx = _cx;
	ss.Open(data);
	raster = StreamRaster::OpenAny(ss);
	if(raster)
		si.Create(Size(cx, cy), *raster, raster->GetSize());
}
Example #19
0
void ImageMT::LoadImage()
{
	FileSel dlg;
	dlg.Type("Image files","*.bmp *.png *.tif *.jpg");
	dlg.Type("Image: JPEG","*.jpg");
	dlg.Type("Image: Portable Nework Graphics","*.png");
	dlg.Type("Image: Tagged Image Format","*.tif");
	dlg.Type("Image: Windows Bitmap (24bit)","*.bmp");
	dlg.ActiveDir(GetCurrentDirectory());

	if(!dlg.ExecuteOpen("Open Image"))return;

	SetCurrentDirectory(dlg.GetActiveDir());

	String path = ~dlg;

	FileIn in(path);

	if(in.IsError())
	{
		String s = Format("Error opening image file %s",path);
		PromptOK(s);
		return;
	}

	One<StreamRaster> r = StreamRaster::OpenAny(in);

	if(!r)
	{
		String s = Format("Error opening streamraster file %s",path);
		PromptOK(s);
		return;
	}

	Layer* pLayer = new Layer;

	Size sz = GetSize();

	pLayer->m_img = r->GetImage();
	pLayer->m_rc.left = 0;
	pLayer->m_rc.right = 1;
	pLayer->m_rc.top = 0;
	pLayer->m_rc.bottom = 1;

	m_pLayers.Add(pLayer);
}
Example #20
0
 void DoThat(uint32_t id)
 {
     switch(id)
     {
         case 11:  one.DoThat();break;
         case 12:  two.DoThat();break;
         case 103: three.DoThat();break;
     }
 }
Example #21
0
One<SlaveProcess> StartProcess(const char *cmdline, const char *envptr, int timeout)
{
    if(*cmdline != '(')
        return StartLocalProcess(cmdline, envptr);
    const char *b = cmdline + 1, *p = b;
    while(*p && *p != ')' && *p != ':')
        p++;
    String host(b, p);
    int port = 0;
    if(*p == ':')
        port = stou(p + 1, &p);
    while(*p && *p++ != ')')
        ;
    if(*p == 0)
        throw Exc(NFormat(t_("Missing command line (host = %s)."), host));
    One<RemoteSlaveProcess> rsp = new RemoteSlaveProcess(host, port, p, envptr, timeout);
    return rsp.Detach();
}
Example #22
0
	virtual Vector<FileInfo> GetFileInfo(const Vector<String>& path) {
		Vector<FileInfo> fi = host->GetFileInfo(path);
		for(int i = 0; i < path.GetCount(); i++)
			if(path[i] == onefile)
				(Time &)fi[i] = GetSysTime();
			else
				(Time &)fi[i] = Time::Low();
		return fi;
	}
Example #23
0
bool RasterPlayer::LoadBuffer(const String &buffer) {
	if (buffer.IsEmpty())
		return false;
	StringStream str(buffer);
	One<StreamRaster> raster = StreamRaster::OpenAny(str);
	if(!raster) 
		return false;
	
	Stop();	
	images.Clear();
	delays.Clear();	
	
	Size sz = raster->GetSize();
	ImageDraw iw(sz); 
	Image previous;
	Rect r;
	for (int i = 0; i < raster->GetPageCount(); ++i) {
		if (previous) {
			iw.Alpha().DrawImage(r, previous, GrayColor(255));
			iw.DrawImage(r, previous);
			previous = Null;
		}
		raster->SeekPage(i);
		r = raster->GetPageRect(i);
		switch (raster->GetPageDisposal(i)) {
		case 1:
		case 2:	iw.DrawRect(r, SColorFace());
				break;
		//case 2: iw.DrawRect(sz, White());	  // It seems gif files do not comply with standard
		//		break;
		case 4:	if (i > 0) 
					previous = GetRect_(images[i-1], r);
				iw.DrawRect(sz, SColorFace()); 
				break;
		}
		iw.Alpha().DrawImage(r.left, r.top, raster->GetImage(0, 0, r.right-r.left, r.bottom-r.top), GrayColor(255));
		iw.DrawImage(r.left, r.top, raster->GetImage(0, 0, r.right-r.left, r.bottom-r.top));
		images.Add(iw);
		delays.Add(max(50, 10*raster->GetPageDelay(i)));
	}
	ind = 0;
	return true;	
}
Example #24
0
	virtual IdeDesigner *CreateDesigner(const char *path, byte) {
		if(IsImgFile(path)) {
			FileIn in(path);
			One<StreamRaster> o = StreamRaster::OpenAny(in);
			if(o) {
				Size sz = o->GetSize();
				if(ToLower(GetFileExt(path)) == ".png" && sz.cx <= 768 && sz.cy <= 512) {
					IdePngDes *d = new IdePngDes;
					d->Load(path);
					d->RestoreEditPos();
					return d;
				}
				else {
					IdeImgView *d = new IdeImgView;
					d->img_sz = sz;
					d->filename = path;
					if(sz.cx <= 1024 && sz.cy <= 768)
						d->img = o->GetImage();
					else {
						ImageEncoder m;
						Rescale(m, GetFitSize(sz, Size(1024, 768)), *o, sz);
						d->img = m;
					}
					return d;
				}
			}
			else
			if(ToLower(GetFileExt(path)) == ".png" && GetFileLength(path) <= 0) {
				IdePngDes *d = new IdePngDes;
				d->Create(path);
				d->RestoreEditPos();
				return d;
			}
		}
		return NULL;
	}
Example #25
0
void Ide::ExecuteApk()
{
	AndroidSDK sdk(GetAndroidSdkPath(), true);
	if(!sdk.Validate())
		return;
	
	SelectAndroidDeviceDlg select(&sdk);
	if(select.GetDeviceCount() != 1 && select.Run() != IDOK)
		return;
	if(!select.GetDeviceCount())
		return;
	
	One<Host> host = CreateHost(false);
	Apk apk(target, sdk);
	String packageName = apk.FindPackageName();
	String activityName = apk.FindLaunchableActivity();
	
	Adb adb = sdk.MakeAdb();
	adb.SetSerial(select.GetSelectedSerial());
	host->Execute(adb.MakeInstallCmd(target));
	
	if(!packageName.IsEmpty() && !activityName.IsEmpty())
		host->Execute(adb.MakeLaunchOnDeviceCmd(packageName, activityName));
}
Example #26
0
void Ide::BuildAndExecute()
{
	if(Build()) {
		int time = msecs();
		One<Host> h = CreateHostRunDir();
		h->ChDir(Nvl(rundir, GetFileFolder(target)));
		String cmdline;
		if(!runexternal)
			cmdline << '\"' << h->GetHostPath(target) << "\" ";
		cmdline << ToSystemCharset(runarg);
		int exitcode;
		switch(runmode) {
		case RUN_WINDOW:
			HideBottom();
			h->Launch(cmdline, FindIndex(SplitFlags(mainconfigparam, true), "GUI") < 0);
			break;
		case RUN_CONSOLE:
			ShowConsole();
			PutConsole(String().Cat() << "Executing: " << cmdline);
			console.Sync();
			exitcode = h->ExecuteWithInput(cmdline);
			PutConsole("Finished in " + GetPrintTime(time) + ", exit code: " + AsString(exitcode));
			break;
		case RUN_FILE: {
				HideBottom();
				String fn;
				if(IsNull(stdout_file))
					fn = ForceExt(target, ".ol");
				else
					fn = stdout_file;
				FileOut out(fn);
				if(!out) {
					PromptOK("Unable to open output file [* " + DeQtf(stdout_file) + "] !");
					return;
				}
				if(h->Execute(cmdline, out) >= 0) {
					out.Close();
					EditFile(fn);
				}
			}
		}
	}
}
Example #27
0
void Ide::Valgrind()
{
	if(!IsValgrind())
		return;
	static String ValgrindLogFile;
	if(IsNull(ValgrindLogFile)) {
		StringStream ss;
		CreateHostRunDir()->Execute("valgrind --help", ss);
		String txt = ss;
		if(txt.Find("--log-file-exactly") > 0)
		   ValgrindLogFile = "--log-file-exactly=";
		else
		   ValgrindLogFile = "--log-file=";
		if(txt.Find("--xml-file") > 0)
		   ValgrindLogFile = "--xml-file=";
	}
	if(!Build())
		return;
	One<Host> h = CreateHostRunDir();
	h->ChDir(Nvl(rundir, GetFileFolder(target)));
	String cmdline;
	String fn = GetTempFileName();
	cmdline << "valgrind --xml=yes --num-callers=40 " << ValgrindLogFile << fn << ' ';
	String ValgSupp = ConfigFile("valgrind.supp");
	if(!IsNull(LoadFile(ValgSupp)))
		cmdline << "--suppressions=" << ValgSupp << ' ';
	cmdline << '\"' << h->GetHostPath(target) << "\" ";
	cmdline << runarg;
	ConsoleClear();
	PutConsole("Valgrind..");
	if(IsNull(h->Execute(cmdline))) {
		PutConsole("Error executing valgrind");
		return;
	}
	PutConsole("Parsing valgrind output..");
	Sync();
	String txt = LoadFile(fn);
	DeleteFile(fn);
	try {
		XmlParser p(txt);
		while(!p.IsTag())
			p.Skip();
		p.PassTag("valgrindoutput");
		while(!p.End()) {
			if(p.Tag("error")) {
				String hdr = "Error (missing description)";
				String pos;
				Vector<String> ln;
				bool src = false;
				while(!p.End()) {
					if(p.Tag("what")) {
						hdr = p.ReadText();
						p.SkipEnd();
					}
					else
					if(p.Tag("stack")) {
						while(!p.End()) {
							String ip = "?";
							String obj;
							String fn;
							String dir;
							String file;
							String line;
							if(p.Tag("frame")) {
								bool hasdir = false;
								bool hasfile = false;
								bool hasline = false;
								bool haspos = false;
								while(!p.End()) {
									if(p.Tag("ip")) {
										ip = p.ReadText();
										p.SkipEnd();
									}
									else
									if(p.Tag("obj")) {
										obj = p.ReadText();
										p.SkipEnd();
										haspos = true;
									}
									else
									if(p.Tag("fn")) {
										fn = p.ReadText();
										p.SkipEnd();
									}
									else
									if(p.Tag("dir")) {
										dir = p.ReadText();
										p.SkipEnd();
										hasdir = true;
									}
									else
									if(p.Tag("file")) {
										file = p.ReadText();
										p.SkipEnd();
										hasfile = true;
									}
									else
									if(p.Tag("line")) {
										line = p.ReadText();
										p.SkipEnd();
										hasline = true;
									}
									else
										p.Skip();
								}
								src = src || hasline && hasdir && hasfile;
								if(pos.IsEmpty() && haspos)
									pos << fn << ' ' << ip << ' '<< obj;
								if(hasline && hasdir && hasfile)
									ln.Add(AppendFileName(dir, file) + ':' + line);
								else {
									String h;
									h << fn << ' ' << ip << ' ' << obj;
									if(hasdir && hasfile)
										h << AppendFileName(dir, file);
									else
										h << file << ' ';
									h << line;
									ln.Add(h);
								}
							}
							else
								p.Skip();
						}
					}
					else
						p.Skip();
				}
				PutConsole(hdr);
				PutConsole("  " + pos);
				if(src)
					for(int i = 0; i < ln.GetCount(); i++)
						PutConsole("     " + ln[i]);
			}
			else
				p.Skip();
		}
	}
	catch(XmlError) {
		PutConsole("Error parsing valgrind output");
	}
}
Example #28
0
IterTest::IterTest()
{
	CtrlLayout(*this, "Window title");

	//generally, an iter interface needs its underlying container to live as long as interface is present.
	//no checks are performed to keep code small
	//an Iter interface will not modify the underlying container.
	//if container is changed while an Iter interface is bound to it, it may become undefined in behaviour (Vector i.e)
	//an Iter interface is always created on heap, so use means to delete it after usage, best is One<Iter<int > > foo, destroyed when scope is left

	//==========================================================================================	

	//Vector or any common linear container	

	Vector<int> vi;
	vi.SetCount(10);

	//use the explicit interface to do things
	One<Iter<int> > ii = IterCreator::GetIter(vi);
	while(ii->Next())
		ii->Get() = Random();

	//an iterator can be copied, without knowing its underlying type
	//and can be reinitiated
	One<Iter<int> > ii2 = ii->PartialCopy();
	while(ii2->Next())
		LOG(ii2->Get());

	//the const variant of Iter, ConstIter
	One<ConstIter<int> > ii3 = IterCreator::GetIter((const Vector<int>&)vi);
	while(ii3->Next())
		LOG(ii3->Get());

	FOREACH(int, e, vi)
		LOG(e);

	//and the const version
	FOREACHC(int, e, (const Vector<int>&)vi)
		LOG(e);

	//helpers to define the scope safe iterators
	ITER(int) _ii = IterCreator::GetIter(vi);
	ITERC(int) _cii = IterCreator::GetIter((const Vector<int>&)vi);

	//a macro for usual containers only without using Iter interface
	//can speed up things because no virtual stuff involved
	FOREACHCONT(int, e, vi)
		LOG(e);

	//the const variant
	FOREACHCONTC(int, e, (const Vector<int>&)vi)
		LOG(e);

	//other 'containers' also yield a Iter interface

	//usual pointer

	int in = 123;
	int* inp = &in;

	FOREACH(int, e, inp)
		LOG(e);

	FOREACHC(int, e, (const int*)inp)
		LOG(e);

	//Ptr

	EditInt ei;
	Ptr<Ctrl> eip(&ei);

	FOREACH(Ctrl, e, eip)
		e.SetData(123); 

	FOREACHC(Ctrl, e, (const Ptr<Ctrl>&)eip)
		e.GetData(); 

	//One

	One<Ctrl> oei;
	oei.Create<EditInt>();

	FOREACH(Ctrl, e, oei)
		e.SetData(123); 

	FOREACHC(Ctrl, e, (const One<Ctrl>&)oei)
		e.GetData(); 

	//Any

	Any a;
	a.Create<int>() = 345;
	One<Iter<int> > ia = IterCreator::GetIter<int>(a);
	
	FOREACH(int, e, a)
		LOG(e); 

	FOREACHC(int, e, (const Any&)a)
		LOG(e); 

	//Value

	Value v = 789;
	One<Iter<int> > iv = IterCreator::GetIter<int>(v);

	FOREACH(int, e, v)
		LOG(e);
	
	FOREACHC(int, e, (const Value&)v)
		LOG(e);

	//Link

	LinkOwner<Foo> lf;
	for(int i = 0; i < 10; i++)
		lf.InsertPrev()->d = i;

	FOREACH(Foo, e, (Link<Foo>&)lf)
		LOG(e.d);

	FOREACHC(Foo, e, (const Link<Foo>&)lf)
		LOG(e.d);

	//all containers can be handled in a common interface	
	ITER(int) iii;

	iii = IterCreator::GetIter(vi);
	CommonHandler(*iii);

	Array<int> ai;
	iii = IterCreator::GetIter(ai);
	CommonHandler(*iii);	
}
Example #29
0
int main(int argc, char* argv[]) {
    One o;
    cout << typeid(*o.nested()).name() << endl;

    return 0;
} ///:~
Example #30
0
void MakeBuild::SaveMakeFile(const String& fn, bool exporting)
{
	BeginBuilding(false, true);

	VectorMap<String, String> bm = GetMethodVars(method);
	One<Host> host = CreateHost(false);
	One<Builder> b = CreateBuilder(~host);
	
	if(!b)
		return;
	
	const TargetMode& tm = GetTargetMode();

	String makefile;

	Vector<String> uppdirs = GetUppDirs();
	String uppout = exporting ? host->GetHostPath(GetVar("OUTPUT")) : "_out/";
	String inclist;

	Index<String> allconfig = PackageConfig(GetIdeWorkspace(), 0, bm, mainconfigparam, *host, *b);
	bool win32 = allconfig.Find("WIN32") >= 0;

	Workspace wspc;
	wspc.Scan(GetMain(), allconfig.GetKeys());

	for(int i = 1; i < wspc.GetCount(); i++) {
		Index<String> modconfig = PackageConfig(wspc, i, bm, mainconfigparam, *host, *b);
		for(int a = allconfig.GetCount(); --a >= 0;)
			if(modconfig.Find(allconfig[a]) < 0)
				allconfig.Remove(a);
	}

	if(!exporting)
		for(int i = 0; i < uppdirs.GetCount(); i++) {
			String srcdir = GetMakePath(AdjustMakePath(host->GetHostPath(AppendFileName(uppdirs[i], ""))), win32);
			makefile << "UPPDIR" << (i + 1) << " = " << srcdir << "\n";
			inclist << " -I$(UPPDIR" << (i + 1) << ")";
		}
	else
		inclist << "-I./";
	Vector<String> includes = SplitDirs(bm.Get("INCLUDE",""));
	for(int i = 0; i < includes.GetCount(); i++)
		inclist << " -I" << includes[i];

	makefile << "\n"
		"UPPOUT = " << (exporting ? "_out/" : GetMakePath(AdjustMakePath(host->GetHostPath(AppendFileName(uppout, ""))), win32)) << "\n"
		"CINC = " << inclist << "\n"
		"Macro = ";

	for(int i = 0; i < allconfig.GetCount(); i++)
		makefile << " -Dflag" << allconfig[i];
	makefile << "\n";

	String output, config, install, rules, linkdep, linkfiles, linkfileend;

	for(int i = 0; i < wspc.GetCount(); i++) {
		b->config = PackageConfig(wspc, i, bm, mainconfigparam, *host, *b);
		b->version = tm.version;
		b->method = method;
		MakeFile mf;
		b->AddMakeFile(mf, wspc[i], GetAllUses(wspc, i),
		               GetAllLibraries(wspc, i, bm, mainconfigparam, *host, *b), allconfig,
		               exporting);
		if(!i) {
			String tdir = mf.outdir;
			String trg;
			if(tm.target_override) {
				trg = GetMakePath(AdjustMakePath(tm.target), win32);
				if(!trg.IsEmpty() && *trg.Last() == (win32 ? '\\' : '/'))
					trg << mf.outfile;
				else if(trg.Find(win32 ? '\\' : '/') < 0)
					trg.Insert(0, "$(OutDir)");
			}
			output = Nvl(trg, mf.output);
			if(exporting)
				output = wspc[i] + ".out";
			install << "\n"
				"OutDir = " << tdir << "\n"
				"OutFile = " << output << "\n"
				"\n"
				".PHONY: all\n"
				"all: prepare $(OutFile)\n"
				"\n"
				".PHONY: prepare\n"
				"prepare:\n";
		}
		config << mf.config;
		install << mf.install;
		rules << mf.rules;
		linkdep << mf.linkdep;
		linkfiles << mf.linkfiles;
		linkfileend << mf.linkfileend;
	}

	makefile
		<< config
		<< install
		<< "\n"
		"$(OutFile): " << linkdep << "\n\t" << linkfiles << linkfileend << " -Wl,--end-group\n\n"
		<< rules
		<< ".PHONY: clean\n"
		<< "clean:\n"
		<< "\tif [ -d $(UPPOUT) ]; then rm -rf $(UPPOUT); fi;\n";

	bool sv = ::SaveFile(fn, makefile);
	if(!exporting)
		if(sv)
			PutConsole(NFormat("%s(1): makefile generation complete", fn));
		else
			PutConsole(NFormat("%s: error writing makefile", fn));

	EndBuilding(true);
}