コード例 #1
0
void InfoFileReader::read(const std::string& text, StringToStringMap& res)
{
  res.clear();
  m_currentLineNumber = 1;
  std::string line;
  for(std::string::size_type i = 0;i < text.length();i++)
    {
      if (text[i] == '\r')
	continue;
      if (text[i] != '\n')
	{
	  line += text[i];
	  continue;
	}
      std::string name, value;
      parseLine(line, name, value);
      m_currentLineNumber++;
      line.erase();
      if (name.empty())
	continue;
      res.insert(StringToStringMap::value_type(name, value));
    }
  if (line.empty())
    return;
  std::string name, value;
  parseLine(line, name, value);
  if (name.empty())
    return;
  res.insert(StringToStringMap::value_type(name, value));
}
コード例 #2
0
/** Creates or updates the json file of a directories contents
* @param directoryPath The path to the directory to catalog
* @return A map of file names to sha1 values
**/
DownloadInstrument::StringToStringMap
DownloadInstrument::getFileShas(const std::string &directoryPath) {
  StringToStringMap filesToSha;
  try {
    using Poco::DirectoryIterator;
    DirectoryIterator end;
    for (DirectoryIterator it(directoryPath); it != end; ++it) {
      const auto &entryPath = Poco::Path(it->path());
      if (entryPath.getExtension() != "xml")
        continue;
      std::string sha1 = ChecksumHelper::gitSha1FromFile(entryPath.toString());
      // Track sha1
      filesToSha.insert(std::make_pair(entryPath.getFileName(), sha1));
    }
  } catch (Poco::Exception &ex) {
    g_log.error() << "DownloadInstrument: failed to parse the directory: "
                  << directoryPath << " : " << ex.className() << " : "
                  << ex.displayText() << std::endl;
    // silently ignore this exception.
  } catch (std::exception &ex) {
    std::stringstream ss;
    ss << "unknown exception while checking local file system. " << ex.what()
       << ". Input = " << directoryPath;
    throw std::runtime_error(ss.str());
  }

  return filesToSha;
}
コード例 #3
0
EStatusCode PreprocessorTest::RunTest(const string& inName, const string& inOriginalFile, const string& inOutputFile, const string& inComparisonFile)
{
	EStatusCode status = eSuccess;

	StringToStringMap preprocessorDefinitions;
	StringList includeFolders;

	includeFolders.push_back(scSamplesBasePath);
	preprocessorDefinitions.insert(StringToStringMap::value_type("PREDEFINED_SYMBOL","2"));

	InputFile sourceFile;
	sourceFile.OpenFile(inOriginalFile);

	OutputFile outputFile;
	outputFile.OpenFile(inOutputFile);
	mCurrentStream = outputFile.GetOutputStream();

	PreProcessor preProcessor;

	preProcessor.Setup(sourceFile.GetInputStream(),inOriginalFile,preprocessorDefinitions,includeFolders);

	preProcessor.AddListener(this);

	mStartRow = true;
	BoolAndString tokenizerResult = preProcessor.GetNextToken();
	while(tokenizerResult.first)
	{
		if(!mStartRow)
			mCurrentStream->Write((const Byte*)"  ",2); // 2 spaces, so we can clearly distinct tokens
		mCurrentStream->Write((const Byte*)tokenizerResult.second.c_str(),tokenizerResult.second.size());

		mStartRow = false;

		tokenizerResult = preProcessor.GetNextToken();
	}

	sourceFile.CloseFile();
	outputFile.CloseFile();

	mCurrentStream = NULL;
	
	SimpleFileComparer comparer;

	if(!comparer.Same(inOutputFile,inComparisonFile))
	{
		cout<<"TokenizerTest::Run, failed in test named "<<inName<<". see result in "<<inOutputFile<<" and compare with the required result in "<<inComparisonFile<<"\n";
		status = eFailure;
	}

	return status;	

}
コード例 #4
0
ファイル: RepoParams.cpp プロジェクト: marigostra/deepsolver
void RepoParams::writeInfoFile(const std::string& fileName) const
{
  logMsg(LOG_DEBUG, "Saving info file in \'%s\'", fileName.c_str());
  StringToStringMap params;
  switch(formatType)
    {
    case FormatTypeText:
      params.insert(StringToStringMap::value_type(INFO_FILE_FORMAT_TYPE, INFO_FILE_FORMAT_TYPE_TEXT));
      break;
    case FormatTypeBinary:
      params.insert(StringToStringMap::value_type(INFO_FILE_FORMAT_TYPE, INFO_FILE_FORMAT_TYPE_BINARY));
      break;
    default:
      assert(0);
    }; //switch(formatType);
  switch(compressionType)
    {
    case CompressionTypeNone:
      params.insert(StringToStringMap::value_type(INFO_FILE_COMPRESSION_TYPE, INFO_FILE_COMPRESSION_TYPE_NONE));
      break;
    case CompressionTypeGzip:
      params.insert(StringToStringMap::value_type(INFO_FILE_COMPRESSION_TYPE, INFO_FILE_COMPRESSION_TYPE_GZIP));
      break;
    default:
      assert(0);
    }; //switch(compressionType);
  params.insert(StringToStringMap::value_type(INFO_FILE_VERSION, version));
  params.insert(StringToStringMap::value_type(INFO_FILE_FILTER_PROVIDES_BY_DIRS, saveStringVector(filterProvidesByDirs)));
  params.insert(StringToStringMap::value_type(INFO_FILE_FILTER_PROVIDES_BY_DIRS, saveStringVector(filterProvidesByDirs)));
  params.insert(StringToStringMap::value_type(INFO_FILE_FILTER_PROVIDES_BY_REFS, booleanValue(filterProvidesByRefs)));
  params.insert(StringToStringMap::value_type(INFO_FILE_EXCLUDE_REQUIRES, saveStringVector(excludeRequiresRegExp)));
  params.insert(StringToStringMap::value_type(INFO_FILE_CHANGELOG_BINARY, booleanValue(changeLogBinary)));
  params.insert(StringToStringMap::value_type(INFO_FILE_CHANGELOG_SOURCES, booleanValue(changeLogSources)));
  params.insert(StringToStringMap::value_type(INFO_FILE_MD5SUM, REPO_INDEX_MD5SUM_FILE));
  for(StringToStringMap::const_iterator it = userParams.begin();it != userParams.end();it++)
    params.insert(*it);
  writeInfoFileParamsToDisk(fileName, params);
}