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;
}
Exemple #2
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]);
}
Exemple #3
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);
}
///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
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


}
Exemple #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));
}
Exemple #6
0
em2d::Images get_projections(const ParticlesTemp &ps,
                             const RegistrationResults &registration_values,
                             int rows, int cols,
                             const ProjectingOptions &options, Strings names) {
  IMP_LOG_VERBOSE("Generating projections from registration results"
                  << std::endl);

  if (options.save_images && (names.size() < registration_values.size())) {
    IMP_THROW("get_projections: Insufficient number of image names provided",
              IOException);
  }

  unsigned long n_projs = registration_values.size();
  em2d::Images projections(n_projs);
  // Precomputation of all the possible projection masks for the particles
  MasksManagerPtr masks(
      new MasksManager(options.resolution, options.pixel_size));
  masks->create_masks(ps);
  for (unsigned long i = 0; i < n_projs; ++i) {
    IMP_NEW(em2d::Image, img, ());
    img->set_size(rows, cols);
    img->set_was_used(true);
    String name = "";
    if (options.save_images) name = names[i];
    get_projection(img, ps, registration_values[i], options, masks, name);
    projections[i] = img;
  }
  return projections;
}
// Convert a vector of four strings to a Vec3. 
// The zeroth string is ignored. Strings 1, 2 & 3 are
//  asssumed to be floats.
Vec3f ToVec3(const Strings& strs)
{
    if (strs.size() != 4)
    {
        assert(0);
    }
    return Vec3f(ToFloat(strs[1]), ToFloat(strs[2]), ToFloat(strs[3]));
}
// Convert a vector of three strings to a Vec2. 
// The zeroth string is ignored. Strings 1 & 2 are
//  asssumed to be floats.
Vec2f ToVec2(const Strings& strs)
{
    if (strs.size() != 3)
    {
        //assert(0);
    }
    return Vec2f(ToFloat(strs[1]), ToFloat(strs[2]));
}
Exemple #9
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;
}
Exemple #10
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);
 }
void CInPlaceList::UpdateText(const CString& text)
{
    Strings strings;
    SplitList(text, L"=", strings);

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

    SetWindowText(val);
}
Exemple #12
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;
}
Exemple #13
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 ());
}
Exemple #14
0
void ExternalAligner::align_seqs_impl(Strings& seqs) const {
    std::string input = tmp_file();
    ASSERT_FALSE(input.empty());
    std::string output = tmp_file();
    ASSERT_FALSE(output.empty());
    {
        boost::shared_ptr<std::ostream> file = name_to_ostream(input);
        std::ostream& out = *file;
        for (int i = 0; i < seqs.size(); i++) {
            write_fasta(out, TO_S(i), "", seqs[i], 60);
        }
    }
    align_file(input, output);
    Strings rows;
    read_alignment(rows, output);
    ASSERT_EQ(rows.size(), seqs.size());
    seqs.swap(rows);
    if (!go("NPGE_DEBUG").as<bool>()) {
        remove_file(input);
        remove_file(output);
    }
}
Exemple #15
0
void
QtSqlConnectionBackend::open(SqlDialect *dialect, const SqlSource &source)
{
    close();
    ScopedLock lock(drv_->conn_mux_);
    own_handle_ = true;
    conn_name_ = dialect->get_name() + _T("_") + source.db()
        + _T("_") + to_string(drv_->seq_);
    ++drv_->seq_;
    String driver = source.driver();
    bool eat_slash = false;
    if (driver == _T("QTSQL"))
    {
        if (dialect->get_name() == _T("MYSQL"))
            driver = _T("QMYSQL");
        else if (dialect->get_name() == _T("POSTGRES"))
            driver = _T("QPSQL");
        else if (dialect->get_name() == _T("ORACLE"))
            driver = _T("QOCI");
        else if (dialect->get_name() == _T("INTERBASE"))
            driver = _T("QIBASE");
        else if (dialect->get_name() == _T("SQLITE"))
            driver = _T("QSQLITE");
        if (dialect->native_driver_eats_slash()
                && !str_empty(source.db())
                && char_code(source.db()[0]) == '/')
            eat_slash = true;
    }
    conn_ = new QSqlDatabase(QSqlDatabase::addDatabase(driver, conn_name_));
    if (eat_slash)
        conn_->setDatabaseName(str_substr(source.db(), 1));
    else
        conn_->setDatabaseName(source.db());
    conn_->setUserName(source.user());
    conn_->setPassword(source.passwd());
    if (source.port() > 0)
        conn_->setPort(source.port());
    if (!str_empty(source.host()))
        conn_->setHostName(source.host());
    String options;
    Strings keys = source.options();
    for (size_t i = 0; i < keys.size(); ++i) {
        if (!str_empty(options))
            options += _T(";");
        options += keys[i] + _T("=") + source[keys[i]];
    }
    if (!str_empty(options))
        conn_->setConnectOptions(options);
    if (!conn_->open())
        throw DBError(conn_->lastError().text());
}
Exemple #16
0
Tokens Bytecode::lexer(const std::string& source) const {
    Strings lines;
    split(source, '\n', lines);
    Strings tokens_str;
    for (int i = 0; i < lines.size(); i++) {
        split(lines[i], ' ', tokens_str);
        tokens_str.push_back("\n");
    }
    Tokens result;
    for (int i = 0; i < tokens_str.size(); i++) {
        result.push_back(makeToken(tokens_str[i]));
    }
    return result;
}
Exemple #17
0
void PCoA::print(const std::string& filename, const Strings& labels)
{
	std::ofstream fout(filename.c_str());
	if(!fout.is_open())
	{
		std::cout << "[Error] Unable to create file: " << + filename.c_str() << std::endl;
		return;
	}

	// write projected data
	fout << "Projected data (each column is a point): " << std::endl;
	for(uint i = 0; i < labels.size(); ++i)
	{
		fout << labels.at(i);
		if(i < labels.size()-1)
			fout << '\t';
	}
	fout << std::endl;

	for(uint i = 0; i < m_projectedData.at(0).size(); ++i)
	{
		for(uint ptIndex = 0; ptIndex < m_projectedData.size(); ++ptIndex)
		{
			fout << m_projectedData.at(ptIndex).at(i);
			if(ptIndex < m_projectedData.size()-1)
				fout << '\t';
		}
		fout << std::endl;
	}

	// write captured variance
	fout << std::endl << "Captured variance for each dimension: " << std::endl;
	for(uint i = 0; i < m_variance.size(); ++i)
		fout << m_variance.at(i) << std::endl;

	fout.close();
}
Exemple #18
0
 void testFindAllTables()
 {
     ExpressionList expr(Expression(_T("A")),
             JoinExpr(JoinExpr(Expression(_T("B")),
                               Expression(_T("C")),
                               Expression(_T("X"))),
                      Expression(_T("D")),
                      Expression(_T("Y"))));
     Strings tables;
     find_all_tables(expr, tables);
     CPPUNIT_ASSERT_EQUAL((size_t)4, tables.size());
     CPPUNIT_ASSERT_EQUAL(string("A"), NARROW(tables[0]));
     CPPUNIT_ASSERT_EQUAL(string("B"), NARROW(tables[1]));
     CPPUNIT_ASSERT_EQUAL(string("C"), NARROW(tables[2]));
     CPPUNIT_ASSERT_EQUAL(string("D"), NARROW(tables[3]));
 }
bool File::GetD3DXVECTOR2(D3DXVECTOR2* result)
{
	string str;
	if (!GetString(&str))
	{
		return false;
	}

	Strings s;
	s = Split(str, ',');
	assert(s.size() == 2);

	result->x = ToFloat(s[0]);
	result->y = ToFloat(s[1]);

	return true;
}
bool File::GetVectorI(std::vector<int>* result)
{
	std::string str;
	if (!GetString(&str))
	{
		return false;
	}

	Strings s;
	s = Split(str, ',');
	
	for (int i = 0;i != s.size(); i++)
	{
		result->push_back(ToInt(s[i]));
	}
	return true;
}
// Convert a vector of strings to a Face.
// The zeroth string is ignored. We only use the first 
//  three vertices.
void ToFace(const Strings& fstrs, Face* f)
{
    // strs[1] is "vertex[/UV[/normal]] vertex[/UV[/normal]] ..."
    // Where [ ] means optional. I.e. the data could just be the point index, or
    //  just the point index and UV index.
    // TODO We only handle triangles - handle other size polys ?
    if (fstrs.size() < 4)
    {
        assert(0);
    }

	if (fstrs.size() == 4){
		for (int i = 0; i < 3 /*strs.size()*/; i++)
		{
			Strings strs = Split(fstrs[i + 1], '/');
			//assert(strs.size() == 3);

			if (strs.size() > 0 && !strs[0].empty())
			{
				f->m_pointIndex[i] = ToInt(strs[0]) - 1;
			}
			if (strs.size() > 1 && !strs[1].empty())
			{
				f->m_uvIndex[i] = ToInt(strs[1]) - 1;
			}
			if (strs.size() > 2 && !strs[2].empty())
			{
				f->m_normalIndex[i] = ToInt(strs[2]) - 1;
			}
		}
	}
	else if (fstrs.size() == 5){
		//this is a quad, half it into 2 triangles
		Strings strs = Split(fstrs[1], '/');

		f[1].m_pointIndex[0] = ToInt(strs[0]) - 1;
		f[1].m_uvIndex[0] = ToInt(strs[1]) - 1;
		f[1].m_normalIndex[0] = ToInt(strs[2]) - 1;

		strs = Split(fstrs[3], '/');

		f[1].m_pointIndex[1] = ToInt(strs[0]) - 1;
		f[1].m_uvIndex[1] = ToInt(strs[1]) - 1;
		f[1].m_normalIndex[1] = ToInt(strs[2]) - 1;

		strs = Split(fstrs[4], '/');

		f[1].m_pointIndex[2] = ToInt(strs[0]) - 1;
		f[1].m_uvIndex[2] = ToInt(strs[1]) - 1;
		f[1].m_normalIndex[2] = ToInt(strs[2]) - 1;
	}
    
}
Exemple #22
0
bool Room::LoadGrid(int grid, File* f)
{
  std::string s;
  for (int y = 0; y < m_gridsize.y; y++)
  {
    if (!f->GetDataLine(&s))
    {
      f->ReportError("Expected grid line " + ToString(y));
      return false;
    }
    Strings strs = Split(s, ' ');
    if ((int)strs.size() != m_gridsize.x)
    {
      f->ReportError("Grid size does not match tile data.");
      return false;
    }
    for (int x = 0; x < m_gridsize.x; x++)
    {
      int t = ToInt(strs[x]);
      if (t == 0)
      {
        continue; // no tile here
      }

      if (t > (int)m_texNames.size())
      {
        f->ReportError("Tile number too big: " + strs[x] + " in grid pos (" + ToString(x) + ", " + ToString(y) + ")");
        return false;
      }
      std::string tex = m_texNames[t - 1];

      // Centre grid on origin
      Vec3f tilepos(
        ((float)x - (float)m_gridsize.x * 0.5f) * m_tilesize.x, 
        ((float)y - (float)m_gridsize.y * 0.5f) * m_tilesize.y, 
        (float)grid);

      bool blend = (grid > 0);

      Tile tile(tilepos, m_tilesize, Vec2i(x, y), tex, blend);
      m_tiles[grid].push_back(tile);
    }
  }
  return true;
}
Exemple #23
0
std::string get_example_path(std::string module, std::string file_name) {
  Strings prefixes = get_example_prefixes(module);
  for (unsigned int i = 0; i < prefixes.size(); ++i) {
    boost::filesystem::path path =
        boost::filesystem::path(prefixes[i]) / module / file_name;
    if (boost::filesystem::exists(path)) {
#if BOOST_FILESYSTEM_VERSION == 3
      return path.string();
#else
      return path.native_file_string();
#endif
    }
  }
  IMP_THROW("Unable to find example file "
                << file_name << " in " << prefixes
                << ". IMP is not installed or set up correctly.",
            IOException);
}
Exemple #24
0
	double ChemicalValidity::calcSplitProbability(const Strings& split) const
	{
		double result = 1.0;
		for (size_t u = 0; u < split.size(); u++)
		{
			const std::string& item = split[u];
			if (isProbable(item))
			{
				ChemicalValidity::Probabilities::const_iterator it = elements.probability.find(item);
				result *= it->second;				
			}
			else
			{
				result = 0.0;
				break;
			}
		}
		return result;
	}
Exemple #25
0
		bool Required(const Group & group) const
		{
            if (mode == Auto && group.autoTest == NULL)
                return false;
            if ((mode == Create || mode == Verify) && group.dataTest == NULL)
                return false;
			if (mode == Special && group.specialTest == NULL)
                return false;
            if (filters.empty())
                return true;
            bool required = false;
            for (size_t i = 0; i < filters.size(); ++i)
            {
                if (group.name.find(filters[i]) != std::string::npos)
                {
                    required = true;
                    break;
                }
            }
            return required;
		}
///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
bool FindAllFilesOfTypeRecursive( const std::string& directory, const std::string& searchPattern, Strings& out_filesFound )
{
#ifdef WIN32

    _finddata_t fd;

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

    if (searchHandle != -1)
    {
        do
        {
            if (fd.attrib & _A_SUBDIR && strcmp( fd.name, ".." ) != 0 /*&& strcmp( fd.name, "." )*/ )
            {
                if (strcmp( fd.name, "." ) == 0 )
                {
                    FindAllFilesOfType( directory, searchPattern, out_filesFound );
                }
                else
                {
                    FindAllFilesOfTypeRecursive( directory + fd.name + "/", searchPattern, out_filesFound );
//                     ConsolePrintf( "Recursive: %s\n", 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

}
Exemple #27
0
void stringPairToFst(Strings const& inputTokens, std::vector<std::string> const& outputTokens,
                     IMutableHypergraph<Arc>* pHgResult,
                     StringToHypergraphOptions const& opts = StringToHypergraphOptions()) {
  if (inputTokens.size() != outputTokens.size()) {
    SDL_THROW_LOG(Hypergraph.stringPairToFst, IndexException,
                  "The two strings must have same number of words");
  }

  // 1. Create simple FSA from input tokens:
  stringToHypergraph(inputTokens, pHgResult, opts);

  // 2. Insert output tokens:
  IVocabularyPtr pVoc = pHgResult->getVocabulary();
  std::vector<std::string>::const_iterator it = outputTokens.begin();
  StateId stateId = pHgResult->start();
  const StateId finalId = pHgResult->final();
  while (stateId != finalId) {
    Arc* arc = pHgResult->outArc(stateId, 0);
    const Sym sym = opts.terminalMaybeUnk(pVoc.get(), *it);
    setFsmOutputLabel(pHgResult, *arc, sym);
    ++it;
    stateId = arc->head();
  }
}
Exemple #28
0
bool ObjectUpdater::Load()
{
#ifdef YES_USE_CACHE

#ifdef OU_DEBUG
std::cout << "Loading " << CACHE_FILENAME << "...\n";
#endif

  File f;
  if (!f.OpenRead(CACHE_FILENAME))
  {
    return false;
  }
  if (!m_timestampPos.Load(&f))
  {
    f.ReportError("Object state cache: Expected pos timestamp");
    return false;
  }

  if (!m_timestampUpdate.Load(&f))
  {
    f.ReportError("Object state cache: Expected update timestamp");
    return false;
  }

  int num = 0;

  // Load key/val pairs
  if (!f.GetInteger(&num))
  {
    f.ReportError("Object state cache: Expected num items");
    return false;
  }
  for (int i = 0; i < num; i++)
  {
    std::string s;
    if (!f.GetDataLine(&s))
    {
      f.ReportError("Object state cache: Expected item");
      return false;
    }
    // Format is id, key, val
    Strings strs = Split(s, ',');
    if (strs.size() != 3)
    {
      // Delimiter in key or val ??
      f.ReportError("Object state cache: bad item line: " + s);
      continue; // try to keep going
    }   
    int id = ToInt(strs[0]);
    QueueUpdate(id, strs[1], strs[2]);
  }

#ifdef OU_DEBUG
std::cout << "...Loaded " << num << " update items...\n";
#endif

  // Load positions
  if (!f.GetInteger(&num))
  {
    f.ReportError("Object state cache: Expected num positions");
    return false;
  }
  for (int i = 0; i < num; i++)
  {
    std::string s;
    if (!f.GetDataLine(&s))
    {
      f.ReportError("Object state cache: Expected position");
      return false;
    }
    // Format is id,x, y, z
    Strings strs = Split(s, ',');
    if (strs.size() != 5)
    {
      f.ReportError("Object state cache: bad position: " + s);
      continue;
    } 
    int id = ToInt(strs[0]);
    float x = ToFloat(strs[1]);
    float y = ToFloat(strs[2]);
    float z = ToFloat(strs[3]);
    int location = ToInt(strs[4]);

    QueueUpdatePos(id, Vec3f(x, y, z), location);
  }

#ifdef OU_DEBUG
std::cout << "...Loaded " << num << " positions, OK, done!\n";
#endif
  
#endif // YES_USE_CACHE

  return true;
}
JNIEXPORT jobjectArray JNICALL Java_net_kervala_comicsreader_RarFile_nativeGetEntries(JNIEnv *env, jclass, jstring jFilename)
{
	jobjectArray ret = NULL;

	const char *filename = env->GetStringUTFChars(jFilename, NULL);

	RAROpenArchiveData data;
	memset(&data, 0, sizeof(RAROpenArchiveData));

	data.ArcName = (char*)filename;
	data.OpenMode = RAR_OM_LIST;

	HANDLE handle = RAROpenArchive(&data);

	if (handle && !data.OpenResult)
	{
		RARHeaderData header;
		memset(&header, 0, sizeof(RARHeaderData));
		
		Strings list;

		// read all entries
		while (RARReadHeader(handle, &header) == 0)
		{
			// add file to list only if not a directory
			if ((header.Flags & LHD_DIRECTORY) != LHD_DIRECTORY) list.addString(header.FileName);

			// skip entry content
			int result = RARProcessFile(handle, RAR_SKIP, NULL, NULL);

			if (result)
			{
				LOGE("Unable to process %s, error: %d", header.FileName, result);
			}
		}

		RARCloseArchive(handle);

		size_t count = list.size();

		if (count > 0)
		{
			ret = (jobjectArray)env->NewObjectArray(count, env->FindClass("java/lang/String"), NULL);

			Strings *tmp = &list;
		
			int i = 0;
		
			while(tmp)
			{
				env->SetObjectArrayElement(ret, i++, env->NewStringUTF(tmp->getString()));

				tmp = tmp->getNext();
			}
		}
	}
	else
	{
		displayError(data.OpenResult, filename);
	}

	env->ReleaseStringUTFChars(jFilename, filename);
	
	return ret;
}
Exemple #30
0
Vec3f ToVec3(const std::string& s)
{
  Strings strs = Split(s, ',');
  Assert(strs.size() == 3);
  return Vec3f(ToFloat(strs[0]), ToFloat(strs[1]), ToFloat(strs[2]));
}