Exemplo n.º 1
0
int main() {


	cout << "Hello world !" << endl;



	shared_ptr<ISource> loadChannel(new SourceFile(".", false));
	shared_ptr<ISource> saveChannel(new SourceFile(".", true));

	DynamicObjectManager *pom = DynamicObjectManager::getInstancePtr();

	pom->addLoadSource(loadChannel);
	pom->addSaveSource(saveChannel);
/*
	shared_ptr<DynamicObject> Zelda = pom->load("zelda");

	shared_ptr<Integer> ageZelda = Zelda->getAttribute< Integer > ("age");
	shared_ptr<Integer> newAge(new Integer((*ageZelda)() + 1));
	Zelda->setAttribute("age2", newAge);
*/
	shared_ptr<Integer> newAge(new Integer(1));

	PJ pj("zelda32");
	pj.computeAge();
	pj.setAttribute("age2", newAge);
	pj.save();
	return 0;
}
Exemplo n.º 2
0
	void Application::analyzeArguments (int argc, char* argv[])
	{

		// Declare the supported options.
		options_description desc("Allowed options");
		desc.add_options()
			("help,h", "Produce help message")
			("log,l", value<std::string>(), "Log file name")
			("load-source-directory", value< vector<string> >()->composing(), "Add a directory as a load source")
			("save-source-directory", value< vector<string> >()->composing(), "Add a directory as a save source")
		;

		variables_map vm;
		store(parse_command_line(argc, argv, desc), vm);
		notify(vm);


		/**
		 * If help is required
		 *  -> Display usage
		 *  -> Exit
		 */
		if (vm.count("help"))
		{
			cout << desc;
			::exit(1);
		}


		CLogModule *logModule = CLogModule::getInstancePtr();

		if (vm.count("log"))
		{
			std::string logFile = vm["log"].as<std::string>();

			logModule->setLogFileName(logFile);
		}

		logModule->init();



		DynamicObjectManager *pom = DynamicObjectManager::getInstancePtr();
		SoundManager *soundManager = SoundManager::getInstancePtr();
		CameraManager *cameraManager = CameraManager::getInstancePtr();

		/**
		 * If a loading source has to be added
		 */
		if (vm.count("load-source-directory"))
		{


			vector<string> lsd = vm["load-source-directory"].as< vector<string> >();
			for (vector<string>::iterator it = lsd.begin(); it != lsd.end(); it++)
			{

				GNOLL_LOG() << "Adding new load source directory : \n";
				shared_ptr<ISource> userLoadChannel(new SourceFile(*it, false, 10));
				pom->addLoadSource(userLoadChannel);
				soundManager->addLoadSource(userLoadChannel);
				cameraManager->addLoadSource(userLoadChannel);
			}
		}


		/**
		 * If a saving source has to be added
		 */
		if (vm.count("save-source-directory"))
		{

			vector<string> lsd = vm["save-source-directory"].as< vector<string> >();
			for (vector<string>::iterator it = lsd.begin(); it != lsd.end(); it++)
			{

				GNOLL_LOG() << "Adding new save source directory : \n";
				shared_ptr<ISource> userSaveChannel(new SourceFile( *it, true, 10 ));
				pom->addSaveSource(userSaveChannel);
				soundManager->addSaveSource(userSaveChannel);
				cameraManager->addLoadSource(userSaveChannel);
			}
		}


	}
Exemplo n.º 3
0
	void Application::init()
	{
		// The very first thing to do is to add the current directory in DynamicObjectManager's list of repositories
		// In case some modules would need to load some config files
		shared_ptr<ISource> loadChannel(new SourceFile(".", false));
		shared_ptr<ISource> saveChannel(new SourceFile(".", true));

		DynamicObjectManager *pom = DynamicObjectManager::getInstancePtr();
		SoundManager *soundManager = SoundManager::getInstancePtr();

		GNOLL_LOG() << "Adding load/save source for current path to the DynamicObjectManager\n";
		pom->addLoadSource(loadChannel);
		pom->addSaveSource(saveChannel);

		GNOLL_LOG() << "Adding load/save source for current path to the SoundManager\n";
		soundManager->addLoadSource(loadChannel);
		soundManager->addSaveSource(saveChannel);

		/**
		 * Now program options have been parsed,
		 * program is initialized
		 */

		GNOLL_LOG() << "Instanciating modules...\n";
		logModule             = CLogModule::getInstancePtr();
		graphicmanager        = CGraphicModule::getInstancePtr();
		timeModule            = CTimeModule::getInstancePtr();
		messageModule         = CMessageModule::getInstancePtr();
		soundmanager          = CSoundModule::getInstancePtr();
		inputEventsTranslator = CInputEventsTranslator::getInstancePtr();
		statsModule           = CStatsModule::getInstancePtr();
		GNOLL_LOG() << "Instanciating modules...[DONE]\n";


		try
		{
			GNOLL_LOG() << "Initializing message module\n";
			messageModule->init();
			GNOLL_LOG() << "Initializing message module [DONE]\n";

			GNOLL_LOG() << "Initializing graphic module\n";
			graphicmanager->init();
			GNOLL_LOG() << "Initializing graphic module [DONE]\n";

			GNOLL_LOG() << "Initializing input manager\n";
			inputmanager.init();
			GNOLL_LOG() << "Initializing input manager [DONE]\n";

			GNOLL_LOG() << "Initializing sound manager\n";
			soundmanager->init();
			GNOLL_LOG() << "Initializing sound manager [DONE]\n";

			GNOLL_LOG() << "Initializing time module\n";
			timeModule->init();
			GNOLL_LOG() << "Initializing time module [DONE]\n";

			GNOLL_LOG() << "Initializing input event translator\n";
			inputEventsTranslator->init();
			GNOLL_LOG() << "Initializing input event translator [DONE]\n";

			GNOLL_LOG() << "Initializing stats module\n";
			statsModule->init();
			GNOLL_LOG() << "Initializing stats module [DONE]\n";
		}
		catch (Glib::ustring str)
		{
			cout << str << endl;
		}

		/*
		 * Define the listener of the application
		 * like the message on quit
		 */
		shared_ptr<Gnoll::ApplicationListener> listenerInput = shared_ptr<Gnoll::ApplicationListener>(
															   new Gnoll::ApplicationListener());
		messageModule->getMessageManager()->addListener ( listenerInput, Messages::MessageType(Gnoll::Input::ACTION_EVENT_TYPE) );

		/**
		 * Define the listener for the button
		 */
		CEGUI::PushButton *button_quit;
		button_quit = (CEGUI::PushButton *) CEGUI::WindowManager::getSingleton().getWindow("buttonQuit");
		button_quit->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&Application::quit_OnClick, this));
	}
Exemplo n.º 4
0
int main() {


	cout << "Hello world !" << endl;

	DynamicObject toto = DynamicObject("toto");

	shared_ptr<Scalar<float> > pi( new Scalar<float>("float", 3.145) );
	shared_ptr<Integer> age( new Integer(345) );
	shared_ptr<Scalar<Glib::ustring> > phrase ( new Scalar<Glib::ustring>("string", "c'etait un cafard qui vivait dans le noir") );

	toto.setAttribute( Glib::ustring("pi"), pi);
	toto.setAttribute( "phrase", phrase);
	toto.setAttribute( "age", age);

	cout << (*pi)() << endl;
	cout << (*phrase)() << endl;

	cout << "Toto has attribute 'pi' : " << toto.hasAttribute("pi") << endl;
	cout << "Toto has attribute 'phrase' : " << toto.hasAttribute("phrase") << endl;
	cout << "Toto has attribute 'tournoyant' : " << toto.hasAttribute("tournoyant") << endl;

	const Glib::ustring pi_name("pi");


	shared_ptr<Scalar<float> > pi2 = toto.getAttribute< Scalar<float> > (pi_name);
	shared_ptr<Scalar<Glib::ustring> > phrase2 = toto.getAttribute< Scalar<Glib::ustring> > ("phrase");


	cout << "Get attribute 'pi' : " << *pi2 << endl;
	cout << "Get attribute 'phrase' : " << *phrase2 << endl;

	try
	{
		shared_ptr<Scalar<Glib::ustring> > phrase3 = toto.getAttribute< Scalar<Glib::ustring> > ("aioli");
	}
	catch(Glib::ustring e)
	{
		cout << e << endl;
	}


	cout << endl << "Serializationed (I'am sure it exists :) toto : " << endl;

	shared_ptr<xmlpp::Document> output = toto.serializeXML();
	cout << output->write_to_string_formatted()  << endl;


	SourceFile sf("./");

	shared_ptr<IStream> stream = sf.loadStream("testpo.cpp");
	unsigned int bytesRead = 0;
	while (!stream->eof())
	{
		char buffer[256];
		unsigned int nbRead = stream->read(buffer, 255);
		buffer[nbRead] = 0;
//	cout << buffer;
		bytesRead += nbRead;
	}
	stream->close();

	cout << endl << "Bytes Read : " << bytesRead << endl;

	sf.setOverWrite(true);

	shared_ptr<IStream> streamW = sf.saveStream("testpo.cppW");

	unsigned int bytesWritten = streamW->write("Jesuislorsdelajusticeetdel'emeriteca\nvalier", 40);
	streamW->close();

	cout << endl << "Bytes Written : " << bytesWritten << endl;



	shared_ptr<ISource> loadChannel(new SourceFile(".", false));
	shared_ptr<ISource> saveChannel(new SourceFile(".", true));

	DynamicObjectManager *pom = DynamicObjectManager::getInstancePtr();

	pom->addLoadSource(loadChannel);
	pom->addSaveSource(saveChannel);

	shared_ptr<DynamicObject> Zelda = pom->load("zelda");

	shared_ptr<Integer> ageZelda = Zelda->getAttribute< Integer > ("age");
	shared_ptr<Integer> newAge(new Integer((*ageZelda)() + 1));
	Zelda->setAttribute("age2", newAge);


	try
	{

		shared_ptr< Float > piZelda = Zelda->getAttribute< Float > ("pi");
		cout << "Float pi**2 zelda : " << (*piZelda) * (*piZelda) << endl;



		shared_ptr< String > nut = Zelda->getAttribute< String > ("nut");
		cout << "Attribute nut = '" << *nut << "'" << endl;



		shared_ptr< Double > dpi = Zelda->getAttribute< Double > ("dpi");
		cout << "Double PI in Zelda : " << setprecision(16) << *dpi << endl;
		cout << "Squared Double PI in Zelda : " << setprecision(16) << (*dpi) * (*dpi) << endl;


		typedef list< shared_ptr<IAttribute> >::iterator ListIterator;
		shared_ptr< List > list = Zelda->getAttribute< List > ("ListPreums");
		for (ListIterator it = list->begin(); it != list->end(); it++)
		{
			if (shared_ptr<String> str = dynamic_pointer_cast<String>(*it))
			{
				cout << "String element in list : '" << (*str) << "'" << endl;
			}

			if (shared_ptr<Integer> integer = dynamic_pointer_cast<Integer>(*it))
			{
				cout << "Integer element in list : [" << (*integer) + 2 << "]" << endl;
			}

			if (shared_ptr<Double> dbl = dynamic_pointer_cast<Double>(*it))
			{
				cout << "Double element in list : [" << (*dbl) << "]" << endl;
			}

			if (shared_ptr<Float> flt = dynamic_pointer_cast<Float>(*it))
			{
				cout << "Float element in list : [" << (*flt) << "]" << endl;
			}
		}

	}
	catch(Glib::ustring e)
	{
		cout << e << endl;
	}

	pom->save(Zelda->getInstance());

	cout << endl << "Serializationed (I'am sure it exists :) Zelda : " << endl;

	shared_ptr<xmlpp::Document> outputZelda = Zelda->serializeXML();
	cout << outputZelda->write_to_string_formatted()  << endl;


	cout << endl << endl << "--------------------------------------------" << endl << endl;


	shared_ptr<DynamicObject> Zelda2 = pom->load("zelda2");

	shared_ptr<xmlpp::Document> outputZelda2 = Zelda2->serializeXML();
	cout << outputZelda2->write_to_string_formatted()  << endl;

	return 0;
}