Example #1
0
void Strings::addStrings(const Strings& strings)
{
	AutoUpdater autoUpdater(*this);

	for (int i = 0; i < strings.getCount(); i++)
		add(strings.getString(i).c_str(), strings.getData(i));
}
Example #2
0
Strings dir_children(const std::string& d) {
    Strings result;
    fs::directory_iterator dir(d), end;
    BOOST_FOREACH (const fs::path& child,
                  std::make_pair(dir, end)) {
        result.push_back(child.string());
    }
Example #3
0
///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
bool FindAllFilesOfType( const std::string& directory, const std::string& searchPattern, Strings& out_filesFound  )
{
#ifdef WIN32

    _finddata_t fd;

    std::string searchPath = directory + searchPattern;
    intptr_t searchHandle = _findfirst( searchPath.c_str(), &fd );

    if (searchHandle != -1)
    {
        do
        {
//             ConsolePrintf( "%s  %i\n", (directory + std::string(fd.name)).c_str(), fd.attrib );
            out_filesFound.push_back( directory + std::string( fd.name ) );
        } while (_findnext( searchHandle, &fd ) == 0);

    }
    else return false;

    if (_findclose( searchHandle ) == 0 && out_filesFound.size() != 0)
        return true;
    return false;
#else
    return false;
#endif


}
Example #4
0
void ConfigTool::writeConfig() const
{
    Global* global = Global::instance();
    global->setConfigFAttribute( Config::FATTR_VERSION, 1.2f );
    global->setWindowIAttribute( eq::server::Window::IATTR_HINT_FULLSCREEN,
                                 eq::fabric::ON );
    if( _mode != MODE_WALL )
    {
        global->setWindowIAttribute(eq::server::Window::IATTR_HINT_DOUBLEBUFFER,
                                    eq::fabric::OFF );
        global->setWindowIAttribute( eq::server::Window::IATTR_HINT_DRAWABLE,
                                     eq::fabric::PBUFFER );
    }
    if( _mode >= MODE_DB && _mode <= MODE_DB_STREAM )
        global->setWindowIAttribute( eq::server::Window::IATTR_PLANES_STENCIL,
                                     eq::fabric::ON );

    ServerPtr server = new eq::server::Server;
    const Strings nodeNames = readNodenames( _nodesFile );
    co::ConnectionDescriptionPtr desc = new ConnectionDescription;
    if( !nodeNames.empty( ))
        desc->setHostname( nodeNames.front( ));
    server->addConnectionDescription( desc );

    Config* config = new Config( server );
    _writeResources( config, nodeNames );
    _writeCompound( config );

    lunchbox::Log::instance( "", 0 )
        << lunchbox::disableHeader << global << *server << std::endl
        << lunchbox::enableHeader << lunchbox::disableFlush;
}
Example #5
0
void NeighbourJoining::buildTree(Matrix& distMatrix, const Strings& labels, Tree* tree)
{
	// allocation space for temporary variables
  m_separationSums = new double[distMatrix.size()];
  m_separations = new double[distMatrix.size()];
  m_numActiveClusters = distMatrix.size();      
  m_activeClusters = new bool[distMatrix.size()];

	//calculate initial seperation rows
  for(uint i = 0; i < distMatrix.size(); i++)
	{
    double sum = 0;
    for(uint j = 0; j < distMatrix.size(); j++)
      sum += distMatrix[i][j];

    m_separationSums[i] = sum;
    m_separations[i] = sum / (m_numActiveClusters-2); 
    m_activeClusters[i] = true;
  }

	// create initial singleton clusters
	std::vector< Node* > clusters;
	for(uint i = 0; i < labels.size(); ++i)
	{
		Node* node = new Node(labels.at(i));
		clusters.push_back(node);
	}

  while(m_numActiveClusters > 2)
	{
    findNearestClusters(distMatrix);
    updateClusters(distMatrix, clusters);
    updateDistanceMatrix(distMatrix);                       
  }

  // finish by joining the two remaining clusters
  int index1 = -1;
  int index2 = -1;

  // find the last nodes
  for(uint i = 0; i < distMatrix.size(); i++)
	{
    if(m_activeClusters[i])
		{
      if(index1 == -1)
				index1 = i;
      else
			{
				index2 = i;	
				break;
      }            
    }
  }  

	// connect remaining subtrees and define arbitrary root of tree
	clusters.at(index1)->addChild(clusters.at(index2));
	clusters.at(index2)->distanceToParent(distMatrix[index1][index2]);

	tree->root(clusters.at(index1));
}
Example #6
0
Strings expandShellWildcard( const std::string& filename )
{
    Strings expandedFilenames;

    namespace fs = boost::filesystem;

    const fs::path& filePath( filename );
    const fs::path& parent = filePath.parent_path();

    if( !fs::exists( parent ) || !fs::is_directory( parent ))
        LBTHROW( std::runtime_error( "Not a valid path" ));

    // Convert the filename with shell-like wildcard into a POSIX regex
    const boost::regex regex = convertToRegex( filename );

    for( fs::directory_iterator it( parent );
         it != fs::directory_iterator(); ++it )
    {
        const std::string& candidate = it->path().string();
        if( boost::regex_match( candidate, regex ))
            expandedFilenames.push_back( candidate );
    }

    return expandedFilenames;
}
Example #7
0
bool Client::initLocal( const int argc, char** argv )
{
    if( _impl->name.empty() && argc > 0 && argv )
    {
        const boost::filesystem::path prog = argv[0];
        setName( prog.stem().string( ));
    }

    const auto options = _getProgramOptions();
    arg::variables_map vm;
    try
    {
        Strings args;
        for( int i = 0; i < argc; ++i )
            if( strcmp( argv[i], "--" ) != 0 )
                args.push_back( argv[i] );

        arg::store( arg::command_line_parser( args )
                        .options( options ).allow_unregistered().run(), vm );
        arg::notify( vm );
    }
    catch( const std::exception& e )
    {
        LBERROR << "Error in argument parsing: " << e.what() << std::endl;
        return false;
    }

    const bool isClient = vm.count( "eq-client" );
    std::string clientOpts;

    if( vm.count( "eq-layout" ))
        _impl->activeLayouts.push_back( vm["eq-layout"].as< std::string >( ));
    if( vm.count( "eq-gpufilter" ))
        _impl->gpuFilter = vm["eq-gpufilter"].as< std::string >();
    if( vm.count( "eq-modelunit" ))
        _impl->modelUnit = vm["eq-modelunit"].as< float >();

    LBVERB << "Launching " << getNodeID() << std::endl;
    if( !Super::initLocal( argc, argv ))
        return false;

    if( isClient )
    {
        LBVERB << "Client node started from command line with option "
               << clientOpts << std::endl;

        if( !_setupClient( clientOpts ))
        {
            exitLocal();
            return false;
        }

        _impl->running = true;
        clientLoop();
        exitClient();
    }

    _impl->initQt( argc, argv );
    return true;
}
Example #8
0
std::string 
StringTools::wrap( const std::string &text,
                   int wrapColumn )
{
  const char lineBreak = '\n';
  Strings lines = split( text, lineBreak );

  std::string wrapped;
  for ( Strings::const_iterator it = lines.begin(); it != lines.end(); ++it )
  {
    if ( it != lines.begin() )
      wrapped += lineBreak;

    const std::string &line = *it;
    unsigned int index =0;
    while ( index < line.length() )
    {
      std::string lineSlice( line.substr( index, wrapColumn ) );
      wrapped += lineSlice;
      index += wrapColumn;
      if ( index < line.length() )
        wrapped += lineBreak;
    }
  }

  return wrapped;
}
// Split string cs into a vector of strings.
// Character c is used to split the strings.
// Strings in the result vector do not include the c character.
Strings Split(const std::string& cs, char c)
{
  Strings r;
  std::string s(cs);
  while (true) 
  {
    int i = s.find(c);
    if (i == std::string::npos)
    {
      // No special character found, so push back the entire string and finish.
      r.push_back(s);
      break; 
    }    
    else
    {
      // Found the special character. 
      // Push back whatever is before the character, then work on the remainder
      // of the string.
      r.push_back(s.substr(0, i));
      s = s.substr(i + 1);
      Trim(&s);
      if (s.empty())
      {
          break;
      }
    }
  }
  return r;
}
Example #10
0
    void initComponents()
    {
        setBackground(BG_COLOR);
        setBounds(120, 120, ICON_WIDTH * 3 + PROGRESS_SIZE + PADDING * 3 + 40, ICON_HEIGHT + PROGRESS_SIZE + 50);

        statusLabel_ = new Label("ready");
        statusLabel_->setBounds(START_X, START_Y, ICON_WIDTH * 4, ICON_HEIGHT);
        statusLabel_->setBackground(BG_COLOR);
        statusLabel_->setForeground(monagui::Color::gray);
        add(statusLabel_);

        playButton_ = new ImageSinkButton(playImage_, stopImage_, playImageFocused_);
        playButton_->setBounds(ICON_WIDTH + PADDING + START_X, ICON_HEIGHT + START_Y + PADDING, ICON_WIDTH, ICON_HEIGHT);
        add(playButton_);

        backButton_ = new ImageButton(backImage_, backImageFocused_);
        backButton_->setBounds(START_X, ICON_HEIGHT + START_Y + PADDING, ICON_WIDTH, ICON_HEIGHT);
        add(backButton_);

        forwardButton_ = new ImageButton(forwardImage_, forwardImageFocused_);
        forwardButton_->setBounds(ICON_WIDTH * 2 + PADDING * 2 + START_X, ICON_HEIGHT + START_Y + PADDING, ICON_WIDTH, ICON_HEIGHT);
        add(forwardButton_);

        Strings icons;
        icons.push_back(APPLICATION_DATA_DIR"/BAR0.JPG");
        icons.push_back(APPLICATION_DATA_DIR"/BAR1.JPG");
        icons.push_back(APPLICATION_DATA_DIR"/BAR2.JPG");
        icons.push_back(APPLICATION_DATA_DIR"/BAR3.JPG");
        icons.push_back(APPLICATION_DATA_DIR"/BAR4.JPG");
        progressIcon_ = new ProgressIcon(icons, PROGRESS_SIZE, PROGRESS_SIZE);
        progressIcon_->setBounds(ICON_WIDTH * 3 + PADDING * 3 + START_X, ICON_HEIGHT + START_Y + PADDING, PROGRESS_SIZE, PROGRESS_SIZE);
        add(progressIcon_);
    }
Example #11
0
Position stringToHypergraph(Strings const& inputTokens, IMutableHypergraph<Arc>* pHgResult,
                            StringToHypergraphOptions const& opts = StringToHypergraphOptions(),
                            TokenWeights const& inputWeights = TokenWeights()) {
  IVocabularyPtr const& pVoc = pHgResult->getVocabulary();
  if (!pVoc) SDL_THROW_LOG(Hypergraph, InvalidInputException, "pHgResult hypergraph must contain vocabulary");
  for (std::size_t i = 0, numNonlexicalStates = inputTokens.size() + 1; i < numNonlexicalStates; ++i)
    pHgResult->addState();
  pHgResult->setStart(0);
  StateId prevState = 0;

  typedef typename Arc::Weight Weight;
  typedef FeatureInsertFct<Weight> FI;
  Position i = 0, n = inputTokens.size();
  for (; i != n; ++i) {
    std::string const& token = inputTokens[i];
    SDL_TRACE(Hypergraph.StringToHypergraph, i << ": " << token);
    const Sym sym = opts.terminalMaybeUnk(pVoc.get(), token);
    const StateId nextState = prevState + 1;
    Arc* pArc = new Arc(nextState, Tails(prevState, pHgResult->addState(sym)));
    Weight& weight = pArc->weight();
    assert(opts.inputFeatures != NULL);
    for (FeatureId featureId : opts.inputFeatures->getFeaturesForInputPosition(i)) {
      FI::insertNew(&weight, featureId, 1);
      if (opts.tokens) opts.tokens->insert(sym, featureId);
    }
    inputWeights.reweight(i, weight);
    pHgResult->addArc(pArc);
    prevState = nextState;
  }
  pHgResult->setFinal(prevState);
  return n;
}
Example #12
0
Strings PlayerInfoManager::GetPlayerNames() const
{
  // TODO Sort strings in order of use, most recent first, i.e. descending order

  typedef std::map<unsigned int, std::string, std::greater<unsigned int> > TimestampName;
  TimestampName tn;

  // Put names into map so they will be sorted, most recent first
  for (PIMap::const_iterator it = m_map.begin(); it != m_map.end(); ++it)
  {
    unsigned int timestamp = it->second.first;
    tn[timestamp] = it->first; 
  }

  // Copy names in order into vector
  Strings s;
  for (TimestampName::const_iterator it = tn.begin(); it != tn.end(); ++it)
  {
    s.push_back(it->second);
  }

  // TODO something like
//  std::copy(tn.begin, tn.end, std::back_inserter(s));

  return s;
}
Example #13
0
bool User_Program::Compile (string &text, bool list_flag)
{
	Strings lines;
	Str_Itr line_itr;

	//---- split the text into lines ----

	String_Ptr (text)->Parse (lines, "\n\r\f");

	for (line_itr = lines.begin (); line_itr != lines.end (); line_itr++) {
		line_num++;

		if (list_flag) {
			exe->Print (1, "\t") << *line_itr;
		}
		line_itr->Clean ();
		if (line_itr->empty ()) continue;

		if (declare_flag) {
			if (!Initial_Declare (*line_itr)) break;
		} else if (table_flag) {
			if (!Initial_Table (*line_itr)) break;
		} else {
			while (Get_Token (*line_itr)) {
				if (!Process_Token ()) break;
			}
		}
	}
	return (true);
}
Example #14
0
co::ConnectionPtr _startLocalServer()
{
    Strings dirNames;
    dirNames.push_back( "" );
    dirNames.push_back( "./" );
// Add path of current .so so search paths for EqualizerServer    
#ifndef _WIN32
    Dl_info dl_info;
    dladdr((void *)_startLocalServer, &dl_info);
    
    char libPath[1024];
    strncpy(libPath, dl_info.dli_fname, 1024);
    char* k = strrchr(libPath, '/');
    *(k + 1) = '\0';
    dirNames.push_back( libPath );
#endif
#ifdef EQ_BUILD_DIR
#ifdef NDEBUG
    dirNames.push_back( std::string( EQ_BUILD_DIR ) + "libs/server/Release/" );
#else
    dirNames.push_back( std::string( EQ_BUILD_DIR ) + "libs/server/Debug/" );
#endif
    dirNames.push_back( std::string( EQ_BUILD_DIR ) + "libs/server/" );
#endif

#ifdef _MSC_VER
    const std::string libName = "EqualizerServer.dll";
#elif defined (_WIN32)
    const std::string libName = "libEqualizerServer.dll";
#elif defined (Darwin)
    const std::string libName = "libEqualizerServer.dylib";
#else
    const std::string libName = "libEqualizerServer.so";
#endif

    while( !_libeqserver.isOpen() && !dirNames.empty( ))
    {
        _libeqserver.open( dirNames.back() + libName );
        dirNames.pop_back();
    }

    if( !_libeqserver.isOpen( ))
    {
        EQWARN << "Can't open Equalizer server library" << std::endl;
        return 0;
    }

    eqsStartLocalServer_t eqsStartLocalServer = (eqsStartLocalServer_t)
        _libeqserver.getFunctionPointer( "eqsStartLocalServer" );

    if( !eqsStartLocalServer )
    {
        EQWARN << "Can't find server entry function eqsStartLocalServer"
               << std::endl;
        return 0;
    }

    return eqsStartLocalServer( Global::getConfigFile( ));
}
Example #15
0
bool PlayerInfo::Load()
{
  // FileExists doesn't append File::Root
  if (FileExists(File::GetRoot() + m_filename))
  {
#ifdef PI_DEBUG
std::cout << "Loading player info " << m_filename << "...\n";
#endif
  }
  else
  {
#ifdef PI_DEBUG
std::cout << "Loading player info " << m_filename << " doesn't exist! - - it's a new file\n";
#endif
    // We assume the player is new and has not saved any player info yet - this is OK.
    return true;
  }

#ifdef PI_DEBUG
std::cout << "Loading player info " << m_filename << "...\n";
#endif

  File f;
  if (!f.OpenRead(m_filename))
  {
    return false;
  }
  int num = 0;
  if (!f.GetInteger(&num))
  {
    return false;
  }
  for (int i = 0; i < num; i++)
  {
    std::string s;
    if (!f.GetDataLine(&s))
    {
      return false;
    }

#ifdef PI_DEBUG
std::cout << " Got line: " << s << "\n";
#endif

    Strings strs = Split(s, ',');
    if (strs.size() != 2)
    {
      f.ReportError("Bad line in player info: " + s);
      return false;
    }
    PISetString(strs[0], strs[1]);
  }
#ifdef PI_DEBUG
std::cout << "End of player info load.\n";
#endif

  return true;
}
Example #16
0
// joining
String::String(Strings const& rList, String const& rSeparator) {
    Strings::ConstIterator i_string;
    for (i_string = rList.Begin(); i_string != rList.End(); i_string++) {
        if (i_string != rList.Begin()) {
            *this += rSeparator;
        }
        *this += *i_string;
    }
}
Example #17
0
Strings setup_from_argv(const Strings &iargv, std::string description,
                        std::string usage, int num_positional) {
    char **argv = new char *[iargv.size()];
    for (unsigned int i = 0; i < iargv.size(); ++i) {
        argv[i] = const_cast<char *>(iargv[i].c_str());
    }
    return setup_from_argv(iargv.size(), &argv[0], description, usage,
                           num_positional);
}
Example #18
0
void
ZStream::setZipFileSuffixes(Strings const& suffixes)
{
	m_suffixes.clear();
	m_suffixes.reserve(suffixes.size());

	for (unsigned i = 0; i < suffixes.size(); ++i)
		m_suffixes.push_back(suffixes[i].front() == '.' ? suffixes[i] : '.' + suffixes[i]);
}
Example #19
0
// Find all strings
StringFinder::Strings
StringFinder::findAllStrings(MemoryMap::ConstConstraints where) const {
    Strings retval;
    while (Sawyer::Optional<String> string = findString(where)) {
        retval.insert(string->address(), *string);
        where = where.atOrAfter(string->address() + string->nBytes());
    }
    return retval;
}
Example #20
0
 void toHypergraph(std::string const& line, IMutableHypergraph<A>* phg, std::size_t lineNum = 0) const {
   Strings words = parseTokens(line, (ParseTokensOptions const&)*this);
   SDL_DEBUG(Hypergraph.HgConvertString, lineNum << ": " << printer(words, Util::RangeSep(" ", "", "")));
   SDL_INFO(Hypergraph.HgConvertString, lineNum << ": len=" << words.size());
   phg->clear(properties());
   assert(phg->storesArcs());
   assert(phg->getVocabulary());
   stringToHypergraph(words, phg);
 }
Example #21
0
void CInPlaceList::UpdateText(const CString& text)
{
    Strings strings;
    SplitList(text, L"=", strings);

    CString val = (strings.size() == 2)
                  ? strings[0] : text;

    SetWindowText(val);
}
Example #22
0
const Strings
SqlSource::options() const
{
    Strings options;
    Strings k = keys();
    for (size_t i = 0; i < k.size(); ++i)
        if (!starts_with(k[i], _T("&")))
            options.push_back(k[i]);
    return options;
}
Example #23
0
void FileUtils::close(Mapper * mapper) {
	Strings * columnNames = mapper->getColumnNames();
	for (Strings::iterator it = columnNames->begin(); it != columnNames->end();
			++it) {
		std::string columnName = *it;
		BulkFileWriter * bulkFileWriter =
				(*(mapper->getColumnsToWriters()))[columnName];
		delete bulkFileWriter;
	}
}
Example #24
0
void AbstractAligner::align_block(Block* block) const {
    TimeIncrementer ti(this);
    if (!alignment_needed(block)) {
        return;
    }
    Fragments fragments((block->begin()), block->end());
    Strings rows;
    BOOST_FOREACH (Fragment* f, fragments) {
        rows.push_back(f->str(/* gap */ 0));
    }
Example #25
0
 Strings getInstances() const
 {
     Strings instances;
     for( InstanceMapCIter i = _instanceMap.begin();
          i != _instanceMap.end(); ++i )
     {
         instances.push_back( i->first );
     }
     return instances;
 }
Example #26
0
	static Strings split(const std::string &str, char delim) 
	{
		Strings elems;

    std::stringstream ss(str);
    std::string item;
    while(std::getline(ss, item, delim))
        elems.push_back(item);

    return elems;
	}
Example #27
0
//------------------------------------------------------------------------
MaterialTypes::Strings MaterialTypes::GetTypeNames() const
{
	Strings result;

	for( uint32_t i = 0, e = mEntries.Count(); i < e; i ++ )
	{
		result.push_back( mEntries[ i ].name.c_str() );
	}

	return result;
}
Example #28
0
int  String::Parse (Strings &result, const char *chars) 
{
	String element;

	result.clear ();

	while (Split (element, chars)) {
		result.push_back (element);
	}
	return ((int) result.size ());
}
Example #29
0
bool AbstractAligner::test(bool gaps) const {
    Strings aln;
    aln.push_back("AT");
    aln.push_back(gaps ? "T" : "A");
    try {
        align_seqs(aln);
    } catch (...) {
        return false;
    }
    return aln[0] == "AT" && aln[1] == (gaps ? "-T" : "A-");
}
ProteinsAnchorsSamplingSpace get_part_of_sampling_space(
    const ProteinsAnchorsSamplingSpace &prots_ss, const Strings &prot_names) {
  ProteinsAnchorsSamplingSpace ret(multifit::get_partial_proteomics_data(
      prots_ss.get_proteomics_data(), prot_names));
  ret.set_anchors(prots_ss.get_anchors());
  // add the paths
  for (Strings::const_iterator it = prot_names.begin(); it != prot_names.end();
       it++) {
    ret.set_paths_for_protein(*it, prots_ss.get_paths_for_protein(*it));
  }
  return ret;
}