Exemplo n.º 1
0
 //-------------------------------------------------------------------------
 Ogre::StringVectorPtr
 LGPArchive::list( bool recursive, bool dirs )
 {
     //OGRE_LOCK_AUTO_MUTEX
     Ogre::StringVector* file_names( OGRE_NEW_T( Ogre::StringVector, Ogre::MEMCATEGORY_GENERAL)() );
     FileList::const_iterator it( m_files.begin() );
     FileList::const_iterator it_end( m_files.end() );
     while( it != it_end )
     {
         file_names->push_back( it->file_name );
         ++it;
     }
     return Ogre::StringVectorPtr( file_names, Ogre::SPFM_DELETE_T );
 }
Exemplo n.º 2
0
    //-------------------------------------------------------------------------
    Ogre::StringVectorPtr
    LGPArchive::find( const String& pattern, bool recursive, bool dirs )
    {
        LOG_DEBUG( pattern );

        //OGRE_LOCK_AUTO_MUTEX
        Ogre::StringVector* file_names( OGRE_NEW_T( Ogre::StringVector, Ogre::MEMCATEGORY_GENERAL)() );

        Ogre::FileInfoListPtr found_infos( findFileInfo( pattern, recursive, dirs ) );
        Ogre::FileInfoList::const_iterator it( found_infos->begin() ), it_end( found_infos->end() );
        while( it != it_end )
        {
            file_names->push_back( it->filename );
            ++it;
        }

        return Ogre::StringVectorPtr( file_names, Ogre::SPFM_DELETE_T );
    }
Exemplo n.º 3
0
void server_main(int argc, char* argv[])
{
  ///////////////////////////////////////////////////////////////
  //set up global data structures
  Syncronizer<Env::K>                       syncronizer;
  std::cout <<"before env"<<std::endl;
  Env                                       env(argc,argv);
  std::cout <<"after env"<<std::endl;


  Time_frame::Interval_color                player_a_color = PLAYER_A_COLOR;
  Time_frame::Interval_color                player_b_color = PLAYER_B_COLOR;
  Time_frame                                time_frame( player_a_color, //player a is red
                                                        get_colored_sleep_time());
  File_names                                file_names(&time_frame);
  Targets_manager                           target_configurations_manager(env.get_target_configurations(),
                                                                          env.get_additional_target_configurations());
  Additional_target_configurations_manager  additional_target_configurations_manager(5,&time_frame); //add additional targets at fifth interval
                                                                                    
  Robot_location                            robot_location_a(env.get_source_configuration_a());
  Robot_location                            robot_location_b(env.get_source_configuration_b());
  Writen_paths_filenames                    writen_paths_filenames_a;
  Writen_paths_filenames                    writen_paths_filenames_b;

  Safe_bool									is_game_over(false);
  Result                                    result;

  ///////////////////////////////////////////////////////////////
  //set up sockets 
  Socket* socket_g= set_up_connection__gui(robot_location_a, robot_location_b, &target_configurations_manager);
#if USE_PLAYER_A
  Socket* socket_a= set_up_connection__player_a();
#endif //USE_PLAYER_A
#if USE_PLAYER_B   
  Socket* socket_b= set_up_connection__player_b();   
#endif //USE_PLAYER_B

  ///////////////////////////////////////////////////////////////
  //set up request handlers
#if USE_PLAYER_A
  Client_request_handler request_handler_a;
  request_handler_a.start(socket_a, player_a_color,
                          &time_frame, &file_names,
                          &additional_target_configurations_manager,
                          &writen_paths_filenames_a,
                          &robot_location_b,
						  &is_game_over);
  
#endif //USE_PLAYER_A
#if USE_PLAYER_B
  Client_request_handler request_handler_b;
  request_handler_b.start(socket_b, player_b_color,
                          &time_frame, &file_names,
                          &additional_target_configurations_manager,
                          &writen_paths_filenames_b,
                          &robot_location_a,
						  &is_game_over);
#endif //USE_PLAYER_B

  ///////////////////////////////////////////////////////////////
  //start up syncronizer

  std::cout <<"in main thread : " <<boost::this_thread::get_id()<<std::endl;
  std::cout <<"before synchronizer"<<std::endl<<std::endl;

  syncronizer.start(&time_frame, &env, &result, socket_g,
                    &target_configurations_manager,
                    &additional_target_configurations_manager,
                    &robot_location_a, &robot_location_b,
                    &writen_paths_filenames_a, &writen_paths_filenames_b,
					&is_game_over);
  
  syncronizer.join();
  
  std::cout <<"player a score: " 
            <<result.first 
            <<"player b score: "
            <<result.second 
            <<std::endl;
  
#if USE_PLAYER_A
  request_handler_a.join();
#endif //USE_PLAYER_A
#if USE_PLAYER_B
  request_handler_b.join();
#endif //USE_PLAYER_B

  end_connection__gui(socket_g);
  
  return ;
}
Exemplo n.º 4
0
void handleIO() {
#ifdef FILE_IO
    std::string problem = "11557";
    std::ifstream inFile(problem + "_in.txt");
    std::streambuf *cinbuf = std::cin.rdbuf(); //save old buf
    std::cin.rdbuf(inFile.rdbuf()); //redirect std::cin to inFile!

    std::ofstream outFile(problem + "_out.txt");
    std::streambuf *coutbuf = std::cout.rdbuf();
    std::cout.rdbuf(outFile.rdbuf());
#endif

    int n = 0;

    while (std::cin >> n) {
        std::vector<code_fragment> fragments(n);
        std::vector<std::string> file_names(n);

        std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
        // n file names and n code fragments
        for (int i = 0; i < n; i++) {
            // input file name
            std::getline(std::cin, file_names[i]);
            // std::cout << "got file name " << file_names[i] << std::endl;

            // input code fragment
            std::string line;
            while (std::getline(std::cin, line) && line != "***END***") {
                std::string tline = reduce(line);
                if (tline.length() > 0)
                    fragments[i].push_back(tline);
            }
        }

        // input repo code fragment
        code_fragment repo_fragment;
        std::string line;
        while (std::getline(std::cin, line) && line != "***END***") {
            std::string tline = reduce(line);
            if (tline.length() > 0)
                repo_fragment.push_back(tline);
        }

        int maxLen = 0;
        std::vector<int> lc_match(n);
        // compare repo code fragment with each code fragment
        for (int i = 0; i < n; i++) {
            lc_match[i] = longest_common_substr(fragments[i], repo_fragment);
            maxLen = std::max(maxLen, lc_match[i]);
        }

        if (maxLen == 0)
            std::cout <<0<< std::endl;
        else {
            std::cout << maxLen;
            for (int i = 0; i < n; i++) {
                auto len_match = lc_match[i];
                if (len_match == maxLen)
                    std::cout << " " << file_names[i];
            }
            std::cout << std::endl;
        }
    }

#ifdef FILE_IO
    std::cin.rdbuf(cinbuf);
    inFile.close();
    std::cout.rdbuf(coutbuf);
    outFile.close();
#endif
}