Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Init a ctrl inside INITBLOCK
Re: Init a ctrl inside INITBLOCK [message #35111 is a reply to message #35090] Thu, 12 January 2012 18:23 Go to previous messageGo to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Just for the sake of completeness, here is another solution, based on templates:
template<class T>
inline Ctrl& Create() {
	return Single<T>();
};

typedef Ctrl& (*CreateFunc)();
GLOBAL_VAR(Vector<CreateFunc>,sRegisteredObjects);

template<class T>
void Register(){
	sRegisteredObjects().Add(Create<T>);
};

GUI_APP_MAIN{
	App a;
	for(int i=0;i<sRegisteredObjects().GetCount();i++){
		Ctrl& c = sRegisteredObjects()[i]();
		//do something with it...
	}
	a.Run();
};


INITBLOCK{
	Register<Button>();
	Register<EditString>();
};

It is not as simple as yours, but it is less demanding on the registered objects. Also, I'm pretty sure there is many other ways to do this Smile

Honza
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Date& operator++
Next Topic: random functions proposal
Goto Forum:
  


Current Time: Thu May 09 18:04:46 CEST 2024

Total time taken to generate the page: 0.02329 seconds