Properties* PropertyReader::load() {
    logger->trace("Opening file: " + filePath);
    if(ifstream.is_open()) {
        logger->info("File already open: " + filePath);
        ifstream.close();
        logger->trace("File closed: " + filePath);
    }

    ifstream.open(filePath);

    // If we couldn't open the input file stream for reading
    if (!ifstream) {
        // Error occured opening file exit
        logger->error("File could not be opened: " + filePath);
        return nullptr;
    } else {
        logger->info("File opened: " + filePath);
    }

    // Iterate through the file to find all properties
    logger->info("Loading properties file...");
    std::map<std::string, std::string> loadedValues;
    while (ifstream) {
        std::string inputLine;
        getline(ifstream, inputLine);
        std::pair<std::string, std::string> loadedPair = loadLine(inputLine);
        if (loadedPair.first == "EMPTY") {
            continue;
        }
        loadedValues.insert(loadedPair);
    }
    logger->debug("Loaded " + std::to_string(loadedValues.size()) + " properties successfully");
    return new Properties(loadedValues);
}
示例#2
0
/**
 * @brief Get line number information from compilation unit DIE.
 * @param cu_die Compilation unit DIE.
 * @param lvl    Level (depth) of this die.
 * @return Loaded line element pointer or nullptr if some problem.
 */
DwarfLine *DwarfLineContainer::loadAndGetDie(Dwarf_Die cu_die, unsigned)
{
	// Get all lines to buffer.
	Dwarf_Signed lineCnt = 0;
	Dwarf_Line *lineBuf = nullptr;

	m_res = dwarf_srclines(cu_die, &lineBuf, &lineCnt, &m_error);

	if (m_res == DW_DLV_NO_ENTRY)
	{
		return nullptr;
	}
	else if (m_res != DW_DLV_OK)
	{
		DWARF_ERROR(getDwarfError(m_error));
		return nullptr;
	}

	// Iterate through lines and load each one of them.
	for (int i=0; i<lineCnt; i++)
	{
		loadLine(lineBuf[i]);
	}

	dwarf_srclines_dealloc(m_parentFile->m_dbg, lineBuf, lineCnt);
	return nullptr;
}
示例#3
0
KoskoNetwork::KoskoNetwork(const QString &filename
						   , const int &width
						   , const int &xCentreMassPos
						   , const int &yCentreMassPos)
	: mWidth(width), mXCMPos(xCentreMassPos), mYCMPos(yCentreMassPos)
{
	QDomDocument kn;
	QFile knIn(filename);
	if (knIn.open(QIODevice::ReadOnly)) {
		if (kn.setContent(&knIn)) {
			QDomElement network = kn.documentElement();
			mCountOfANeurons = network.attribute("neuronsInALayer").toInt();
			mCountOfBNeurons = network.attribute("neuronsInBLayer").toInt();
			mCountOfEpochs = network.attribute("epochsNumber").toInt();
			mWeights.resize(mCountOfANeurons * mCountOfBNeurons * mCountOfEpochs);
			QDomElement epoch = network.firstChildElement("epoch");
			QDomElement line;
			int e, i;
			for (e = 0; e < mCountOfEpochs; e++) {
				line = epoch.firstChildElement("line");
				for (i = 0; i < mCountOfBNeurons; i++) {
					loadLine(line, e, i);
					line = line.nextSiblingElement("line");
				}
				epoch = epoch.nextSiblingElement("epoch");
			}
		}
	}
	mHeight = mCountOfANeurons / mWidth;
	mANeuronLayer.fill(0, mCountOfANeurons);
	mBNeuronLayer.resize(mCountOfBNeurons);
	knIn.close();
}
示例#4
0
void LevelLoader::loadLevel(QList< Brick* >& bricks)
{   
    // Selecting the correct level
    m_level++;
    
    if( m_levelset == 0 ){
        qDebug() << "Error: No levelset specified" << endl;
        return;
    }
    
    QDomElement levels = m_levelset->documentElement();
    QDomNode node = levels.firstChild();
    for( int i = 1; i < m_level; i++ ){
        node = node.nextSibling();
    }
    // --
    
    // Load level information
    if( node.isNull() || node.toElement().tagName() != "Level" ){
        // Level not found or no more levels
        return;
    }
    
    QDomAttr attribute;
    QDomElement level = node.toElement();
    if( level.isNull() ){
        qDebug() << "Invalid Levelset " << m_levelname << ": Can't read level information";
    }
    attribute = level.attributeNode("Name");
    QString levelName;
    if( !attribute.isNull() ){
        levelName = level.attributeNode("Name").value();
    }
    node = node.firstChild();
    // --
    
    // Load bricks and gifts
    m_lineNumber = 0;
    while( !node.isNull() ){
        QDomElement info = node.toElement();
        if( info.isNull() ){ qDebug() << "Invalid levelset " << m_levelname << ": Can't read level information."; }
            
        if( info.tagName() == "Line" ){
            // Load one line of bricks
            loadLine( info, bricks );
        } else if( info.tagName() == "Gift" ){
            // Load one gift type
            loadGift( info, bricks );
        } else {
            qDebug() << "Invalid tag name " << info.tagName() << " has occured in level "
                     << levelName << " in levelset " << m_levelname << endl;
        }
        
        node = node.nextSibling();
    }
}
示例#5
0
void Config::loadConfig(const Path &configFile) {
	std::ifstream input;
	input.exceptions(std::ios::badbit | std::ios::failbit);
	input.open(configFile.c_str(), std::ios::in);
	std::string line;
	input.exceptions(std::ios::iostate(0));
	while(!!(std::getline(input, line))) {
		loadLine(line);
	}
}
示例#6
0
void TermsList::loadTerms( string filename ) {
  // local variables
  string lineT;
  string lineD;
  bool   incomplete = true;
  int    current    = 1;
  Term   curTerm;
  // while EOF not reached
  while ( incomplete ) {
    if ( loadLine( filename, current, &lineT ) ) {
      ++current;
      if ( loadLine( filename, current, &lineD ) ) {
        curTerm.term       = lineT;
        curTerm.definition = lineD;
        terms.push_back( curTerm );
        current += 2;
      } else
        incomplete = false;
    } else
      incomplete = false;
  }
}