Example #1
0
HRESULT
AccessibleHandler::QueryService(REFGUID aServiceId, REFIID aIid,
                                void** aOutInterface)
{
  static_assert(&NEWEST_IA2_IID == &IID_IAccessible2_3,
                "You have modified NEWEST_IA2_IID. This code needs updating.");
  /* We're taking advantage of the fact that we are implementing IA2 as part
     of our own object to implement this just like a QI. */
  if (aIid == IID_IAccessible2_3 || aIid == IID_IAccessible2_2 ||
      aIid == IID_IAccessible2) {
    RefPtr<NEWEST_IA2_INTERFACE> ia2(this);
    ia2.forget(aOutInterface);
    return S_OK;
  }

  for (uint32_t i = 0; i < ArrayLength(kUnsupportedServices); ++i) {
    if (aServiceId == kUnsupportedServices[i]) {
      return E_NOINTERFACE;
    }
  }

  if (!mServProvPassThru) {
    RefPtr<IUnknown> proxy(GetProxy());
    if (!proxy) {
      return E_UNEXPECTED;
    }

    HRESULT hr = proxy->QueryInterface(IID_IServiceProvider,
                                       reinterpret_cast<void**>(&mServProvPassThru));
    if (FAILED(hr)) {
      return hr;
    }

    // mServProvPassThru is a weak reference (see comments in
    // AccessibleHandler.h)
    mServProvPassThru->Release();
  }

  return mServProvPassThru->QueryService(aServiceId, aIid, aOutInterface);
}
Example #2
0
int main(int argc, char* argv[])
{
    std::string     filename1, filename2;

    po::options_description hidden("Hidden options");
    hidden.add_options()
        ("input-file1",  po::value<std::string>(&filename1), "The first collection of persistence diagrams")
        ("input-file2",  po::value<std::string>(&filename2), "The second collection of persistence diagrams");

    po::positional_options_description p;
    p.add("input-file1", 1);
    p.add("input-file2", 2);
    
    po::options_description all; all.add(hidden);

    po::variables_map vm;
    po::store(po::command_line_parser(argc, argv).
                  options(all).positional(p).run(), vm);
    po::notify(vm);

    if (!vm.count("input-file1") || !vm.count("input-file2"))
    { 
        std::cout << "Usage: " << argv[0] << " input-file1 input-file2" << std::endl;
        std::cout << hidden << std::endl; 
        return 1; 
    }

    std::ifstream ifs1(filename1.c_str()), ifs2(filename2.c_str());
    boost::archive::binary_iarchive ia1(ifs1), ia2(ifs2);

    std::map<Dimension, PDgm>       dgms1, dgms2;

    ia1 >> dgms1;
    ia2 >> dgms2;

    std::cout << "Distance between dimension 0: " << bottleneck_distance(dgms1[0], dgms2[0]) << std::endl;
    std::cout << "Distance between dimension 1: " << bottleneck_distance(dgms1[1], dgms2[1]) << std::endl;
    std::cout << "Distance between dimension 2: " << bottleneck_distance(dgms1[2], dgms2[2]) << std::endl;
}
Example #3
0
int main(int argc, char *argv[]){

    if( argc != 3 ){
        std::cout<<"provide filename with the blob"<<std::endl;
        return 0;
    }

//    L1TriggerKeyStage1 deserializedObject;
    l1t::CaloParams deserializedObject1, deserializedObject2;

    std::ifstream ifs(argv[1], std::ios::in | std::ios::binary);
    cond::serialization::InputArchive ia(ifs);
    std::cout << "Deserializing " << typeid(l1t::CaloParams).name() << " ..." << std::endl;
    ia >> deserializedObject1;


    std::ifstream ifs2(argv[2], std::ios::in | std::ios::binary);
    cond::serialization::InputArchive ia2(ifs2);
    std::cout << "Deserializing " << typeid(l1t::CaloParams).name() << " ..." << std::endl;
    ia2 >> deserializedObject2;

    return 0;
}
Example #4
0
HRESULT
AccessibleHandler::QueryHandlerInterface(IUnknown* aProxyUnknown, REFIID aIid,
                                         void** aOutInterface)
{
  MOZ_ASSERT(aProxyUnknown);

  static_assert(&NEWEST_IA2_IID == &IID_IAccessible2_3,
                "You have modified NEWEST_IA2_IID. This code needs updating.");
  if (aIid == IID_IDispatch || aIid == IID_IAccessible2_3 ||
      aIid == IID_IAccessible2_2 || aIid == IID_IAccessible2 ||
      aIid == IID_IAccessible) {
    RefPtr<NEWEST_IA2_INTERFACE> ia2(static_cast<NEWEST_IA2_INTERFACE*>(this));
    ia2.forget(aOutInterface);
    return S_OK;
  }

  if (aIid == IID_IServiceProvider) {
    RefPtr<IServiceProvider> svcProv(static_cast<IServiceProvider*>(this));
    svcProv.forget(aOutInterface);
    return S_OK;
  }

  if (aIid == IID_IAccessibleText || aIid == IID_IAccessibleHypertext) {
    RefPtr<IAccessibleHypertext> textTearoff(new AccessibleTextTearoff(this));
    textTearoff.forget(aOutInterface);
    return S_OK;
  }

  if (aIid == IID_IProvideClassInfo) {
    RefPtr<IProvideClassInfo> clsInfo(this);
    clsInfo.forget(aOutInterface);
    return S_OK;
  }

  return E_NOINTERFACE;
}
Example #5
0
int main(int argc, char *argv[]){

	srand(time(NULL));
	int mouse_x, mouse_y; 

	sf::RenderWindow window_game (sf::VideoMode(900, 700), "Gamemilans!",
	sf::Style::Resize|sf::Style::Close);
	
//	sf::RenderWindow window_game (sf::VideoMode::getDesktopMode(), "Gamemilans!",
//		sf::Style::Resize|sf::Style::Close);

	sf::Music music;
	if (!music.openFromFile("music/GameSong1.ogg")) std::cout << " no puc carregar la musica " << std::endl;
	music.play();
	music.setPitch(1);
	music.setLoop(true);

		sf::Clock clock;
		
	window_game.setVerticalSyncEnabled(true);

		window_game.display();
		Presentacio p(window_game);
		p.portada();
		window_game.display();

			p.portada(); 
			window_game.display();
		while (p.handler() != 0){
		}
		window_game.clear();

			p.inst(1); 
			window_game.display();
		while (p.handler() != 0){
		}
		window_game.clear();

			p.inst(2); 
			window_game.display();
		while (p.handler() != 0){
		}
		window_game.clear();

		p.prepareText();
		int n_murs = p.handler();
		int oldmurs = n_murs;
			p.murs(); 
			window_game.display();
		while (n_murs < 0){
			n_murs = p.handler();
			if(n_murs != oldmurs){
				p.murs(); 
				window_game.display();
				oldmurs = n_murs;
			}
		}
		window_game.clear();

	Board taulell(window_game);
	Logica logica(taulell);
 	Ia ia(0);
 	Ia ia2(1);

	taulell.draw();
	logica.print_me_the_players();
	for(int i = 0; i < n_murs; ++i)
		logica.print_me_random_wall();

	bool is_server = false;
	bool online = false;
	bool ia_playing = false;

	int port;
	if(argc >= 2){
		int n;
		if(argc >= 3) {
			if((*(argv[2])) == 'S') is_server = true;
			if((*(argv[2])) == 'I') ia_playing = true;
			if((*(argv[2])) != 'I') online = true;
		}
		if((*(argv[1]))-'0' >= 0) n = atoi((argv[1]));
		else n = 2; /*(?) think it have no sense*/
		for(int i = 0; i < n; ++i) logica.print_me_random_wall();	
	}
	taulell.draw();
	window_game.display(); 
	
	sf::TcpSocket socket;
	sf::TcpSocket client;
	sf::TcpListener listener;

	if( (argc >= 3) and online) { 	//Is online so you have to connect the socket
		port = 53000;
		if(not is_server){
			//Connect the socket
			sf::Socket::Status status = socket.connect("127.0.0.1", port);
			if (status != sf::Socket::Done)	{
				std::cout << "Not conected the socket okly" << std::endl;
			}
			else std::cout << "I'm Conected to the port " << port << std::endl;
		} else /*if (is_server)*/ {
			//Bind the listener to a port
			if (listener.listen(port) != sf::Socket::Done) {
				std::cout << "Not listened okly" << std::endl;
			}
			else std::cout << "Im Listening at the port " << port << std::endl;
			// Accept the connection
			if (listener.accept(client) != sf::Socket::Done) {
				std::cout << "Not accepted the client okly" << std::endl;
			}
			else std::cout << "Conection Accepted" << std::endl;
		}
	}

//	std::cout << "-----------------The gaem is starting here biach ---------------------" << std::endl;

	bool serverTurn = true;
	clock.restart();
	int asong = 0;
	int msong = 6;
	// Mentre estigui oberta 
	while(window_game.isOpen()){

		if(asong == 0 or clock.getElapsedTime().asSeconds() >= 54){
			if(asong == 0) asong = 2;
				std::stringstream s;
				s << "music/GameSong" << asong+1 << ".ogg";
				if (!music.openFromFile(s.str())) std::cout << " no puc carregar la song " << asong+1 << std::endl;
				music.play();
				++asong;
				if(asong > msong) asong = 3;
			clock.restart();
		}
		sf::Event event;
		// If you are playing online and it is not your turn
		while(online and ((not is_server and serverTurn) or (is_server and not serverTurn))){

			float data[2];
			std::size_t received;

			//	std::cout << " I'm gonna wait for data... " << std::endl;
			if(not is_server){
				if (socket.receive(&data, sizeof(float)*2, received) != sf::Socket::Done)	{
				//	std::cout << "Not recived okly" << std::endl;
				} 
				else {
					logica.click(taulell.fixed(data[0], true), taulell.fixed(data[1], true));
					serverTurn = false;
				//	std::cout << "Rebut" << std::endl;
				}
			}
			else if(is_server){
				if (client.receive(&data, sizeof(float)*2, received) != sf::Socket::Done)	{
				//	std::cout << "Not recived okly" << std::endl;
				} 
				else {
					logica.click(taulell.fixed(data[0], true), taulell.fixed(data[1], true));
					serverTurn = true;
				//	std::cout << "rebut" << std::endl;
				}
			}

			//Empty the pollEvent
			while(window_game.pollEvent(event)){
				switch (event.type)	{
					// window closed 
					case sf::Event::Closed:
					window_game.close();
					break;
					default:
					break;
				}
			}
			window_game.display(); 
		}

		bool acted = false;
		while(window_game.pollEvent(event)){

			// mira els events
			switch (event.type) {
				// window closed 
				case sf::Event::Closed:
				window_game.close();
				break;

				// mouse pressed
				case sf::Event::MouseButtonPressed:
//					std::cout << " clicked " << std::endl;
					if (event.mouseButton.button == sf::Mouse::Left) {
						mouse_x = event.mouseButton.x;
						mouse_y = event.mouseButton.y;
					}
					if(not acted and (online and ((is_server and serverTurn) or (not is_server and not serverTurn))) ){
						if(online) {
							float data[2];
							data[0] = mouse_x;
							data[1] = mouse_y;
							// TCP socket:
							if(is_server and logica.click(taulell.fixed(data[0], true), taulell.fixed(data[1], true))){
								//	std::cout << " I'm the server who will send u data biach! " << std::endl;
								if (client.send(&data, sizeof(float)*2) != sf::Socket::Done) {
								//	std::cout << "not sent okly server->client" << std::endl;
								}
								else {
									serverTurn = false;
								//	std::cout << "sent okly S->C!!!" << std::endl;
								}
							}
							else if(not is_server and logica.click(taulell.fixed(data[0], true), taulell.fixed(data[1], true))){
								//	std::cout << " This client want's to send u shiet... " << std::endl;
								if (socket.send(&data, sizeof(float)*2) != sf::Socket::Done) {
								//	std::cout << "not sent okly client->server" << std::endl;
								}
								else {
								serverTurn = true;
								//	std::cout << "sent okly S->C!!!" << std::endl;
								}
							}
						}
						acted = true;
					}
					else {
						if(ia_playing and serverTurn) {
							int movement, deep, i, j;
							double bestvalue;
							movement = -1;
							deep = 2;
							std::cout << "Calculant..." << std::endl;
							if(serverTurn) bestvalue = ia.minMax(logica, deep, false, movement);
							else bestvalue = ia2.minMax(logica, deep, true, movement);

							std::cout << "bestval: " << bestvalue << " movement: "<< movement<< std::endl;

							if(movement < 4){
								if(serverTurn){
									i = logica.get_player_position_x(ia.getPlayer())+movx[movement];
									j = logica.get_player_position_y(ia.getPlayer())+movy[movement];
								}
								else{
									i = logica.get_player_position_x(ia2.getPlayer())+movx[movement];
									j = logica.get_player_position_y(ia2.getPlayer())+movy[movement];	
								}
							}
							else{
								movement -= 4;
								i = (movement*2+1)%17;
								j = (movement*2+1)/17;
							}
							
							std::cout << "initial pos " << logica.get_player_position_x(logica.getActualPlayer()) << " , " << logica.get_player_position_y(logica.getActualPlayer()) << " delay: " << movx[movement] << " , " << movy[movement] << std::endl;
							std::cout << "ia "<< logica.getActualPlayer() << " clicked on " << i << " " << j << std::endl;
							
							if(logica.click(i, j)) {
								if(serverTurn)serverTurn = false;
								else serverTurn = true;
								std::cout << "Torn acabat " << std::endl;
							}
						}
						else {
							int mx, my;
							mx = taulell.fixed(mouse_x, true);
							my = taulell.fixed(mouse_y, true);
							if(logica.click(mx, my)){
								if(serverTurn)serverTurn = false;
								else serverTurn = true;
							}
						}
					}
					break;
					
				case  sf::Event::KeyPressed:		/* These is not working online :$ */
					if (online and is_server and event.key.code == sf::Keyboard::R or (not online and event.key.code == sf::Keyboard::R)) {
						taulell.restart();
						logica.restart();
						taulell.draw();
						logica.print_me_the_players();
						if(argc >= 2) {	
							int n;
							if((*(argv[1]))-'0' >= 0 or true) n = atoi((argv[1]))/* - '0'*/;
							else n = 2;
							for(int i = 0; i < n; ++i) logica.print_me_random_wall();
						}
					}
				break;
				
				// we don't process other types of events
				default:
				break;
			}  
		}
		window_game.display(); 
	}
	return 0;
}
Example #6
0
void testArray2D()
{
	fdk::Array2D<int> ia(2, 3);
	for (size_t y = 0; y < 3; ++y)
	{
		for (size_t x = 0; x < 2; ++x)
		{
			FDK_ASSERT(ia(x, y) == 0);
			ia(x, y) = x+y;
		}
	}
	FDK_ASSERT(ia.is_valid_index(1, 1));
	FDK_ASSERT(ia.is_valid_index(1, 2));
	FDK_ASSERT(ia.is_valid_index(0));
	FDK_ASSERT(ia.is_valid_index(5));
	FDK_ASSERT(!ia.is_valid_index(6));
	FDK_ASSERT(ia.to_index(1, 2) == 5);
	size_t x, y;
	ia.to_index(5, x, y);
	FDK_ASSERT(x == 1 && y == 2);	

	fdk::Array2D<int> ia1(2, 2, 5);
	FDK_ASSERT(ia1.is_valid_index(1, 1));
	FDK_ASSERT(!ia1.is_valid_index(1, 2));
	FDK_ASSERT(ia1(0, 0) == 5);
	FDK_ASSERT(ia1(0, 1) == 5);
	FDK_ASSERT(ia1(1, 0) == 5);
	FDK_ASSERT(ia1(1, 1) == 5);
	ia1(1, 1) = 3;
	FDK_ASSERT(ia1(1, 1) == 3);

	fdk::Array2D<int> ia2(ia);
	for (size_t y = 0; y < ia2.size_y(); ++y)
	{
		for (size_t x = 0; x < ia2.size_x(); ++x)
		{
			FDK_ASSERT(ia2(x, y) == x+y);
		}
	}

	ia1 = ia2;
	for (size_t y = 0; y < ia2.size_y(); ++y)
	{
		for (size_t x = 0; x < ia2.size_x(); ++x)
		{
			FDK_ASSERT(ia1(x, y) == x+y);
		}
	}

	ia1.clear();
	FDK_ASSERT(ia1.empty());
	FDK_ASSERT(ia1.count() == 0);
	FDK_ASSERT(ia1.size_x() == 0);
	FDK_ASSERT(ia1.size_y() == 0);
	FDK_ASSERT(!ia1.raw_data());
	ia1.reset(2, 1, 3);
	for (size_t y = 0; y < ia1.size_y(); ++y)
	{
		for (size_t x = 0; x < ia1.size_x(); ++x)
		{
			FDK_ASSERT(ia1(x, y) == 3);
		}
	}
	ia1.refill(100);
	for (size_t y = 0; y < ia1.size_y(); ++y)
	{
		for (size_t x = 0; x < ia1.size_x(); ++x)
		{
			FDK_ASSERT(ia1(x, y) == 100);
		}
	}

	{
		fdk::Array2D<int*> ar;
		ar.reset(5, 10);
		for (size_t y = 0; y < 10; ++y)
		{
			for (size_t x = 0; x < 5; ++x)
			{
				FDK_ASSERT(ar(x, y) == 0);
			}
		}		
	}
}