Example #1
0
ObjManager::ObjManager()
{
	ValueMap curmap;
	for(ENEMY eny:globalEnemyData)
	{
		curmap["category"]=eny.category;
		curmap["type"]=eny.type;
		curmap["name"]=eny.name;
		curmap["desc"]=eny.desc;
		curmap["life"]=eny.life;
		curmap["offense"]=eny.offense;
		curmap["defense"]=eny.defense;
		curmap["money"]=eny.money;
		curmap["selected"]=false;
		enemytemp[eny.type]=curmap;
		curmap.clear();
	}

	for(ITEM item:globalItemData)
	{
		curmap["category"]=item.category;
		curmap["type"]=item.type;
		curmap["name"]=item.name;
		curmap["desc"]=item.desc;
		curmap["selected"]=false;
		itemtemp[item.type]=curmap;
		curmap.clear();
	}
}
Example #2
0
ValueMap Configure::ReadConfig()
{
	ValueMap vals;
	vals.clear();

    std::ifstream ifs_(conf_path_.c_str(), std::ios::in);
    std::string line;

	while(std::getline(ifs_, line))
	{
        std::string name = line.substr(0, line.find_first_of(":"));
        if (name.empty() || name == line) continue;

		std::string buf(line.substr(line.find_first_of(":")+1));
		std::istringstream ss(buf.substr(buf.find_first_of("-0123456789")));

		double value;
		ss >> value;
        vals[name] = value;
	}

    ifs_.close();

	return vals;
}
void GameManager::initRes()
{
    std::string path = FileUtils::getInstance()->fullPathForFilename("load.xml");
    ValueMap vm = FileUtils::getInstance()->getValueMapFromFile(path);
    for (int i = 0; i < vm.size(); i++)
    {
        char buf[12];
        sprintf(buf, "%d", i+1);
        std::string s = vm.at(buf).asString();
        SpriteFrameCache::getInstance()->addSpriteFramesWithFile(s);
    }
    vm.clear();
}
Example #4
0
/// TestFuncs - Extract all blocks for the miscompiled functions except for the
/// specified blocks.  If the problem still exists, return true.
///
bool ReduceMiscompiledBlocks::TestFuncs(const std::vector<BasicBlock*> &BBs,
                                        std::string &Error) {
  // Test to see if the function is misoptimized if we ONLY run it on the
  // functions listed in Funcs.
  outs() << "Checking to see if the program is misoptimized when all ";
  if (!BBs.empty()) {
    outs() << "but these " << BBs.size() << " blocks are extracted: ";
    for (unsigned i = 0, e = BBs.size() < 10 ? BBs.size() : 10; i != e; ++i)
      outs() << BBs[i]->getName() << " ";
    if (BBs.size() > 10) outs() << "...";
  } else {
    outs() << "blocks are extracted.";
  }
  outs() << '\n';

  // Split the module into the two halves of the program we want.
  ValueMap<const Value*, Value*> VMap;
  Module *Clone = CloneModule(BD.getProgram(), VMap);
  Module *Orig = BD.swapProgramIn(Clone);
  std::vector<Function*> FuncsOnClone;
  std::vector<BasicBlock*> BBsOnClone;
  for (unsigned i = 0, e = FunctionsBeingTested.size(); i != e; ++i) {
    Function *F = cast<Function>(VMap[FunctionsBeingTested[i]]);
    FuncsOnClone.push_back(F);
  }
  for (unsigned i = 0, e = BBs.size(); i != e; ++i) {
    BasicBlock *BB = cast<BasicBlock>(VMap[BBs[i]]);
    BBsOnClone.push_back(BB);
  }
  VMap.clear();

  Module *ToNotOptimize = CloneModule(BD.getProgram(), VMap);
  Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize,
                                                 FuncsOnClone,
                                                 VMap);

  // Try the extraction.  If it doesn't work, then the block extractor crashed
  // or something, in which case bugpoint can't chase down this possibility.
  if (Module *New = BD.ExtractMappedBlocksFromModule(BBsOnClone, ToOptimize)) {
    delete ToOptimize;
    // Run the predicate,
    // note that the predicate will delete both input modules.
    bool Ret = TestFn(BD, New, ToNotOptimize, Error);
    delete BD.swapProgramIn(Orig);
    return Ret;
  }
  delete BD.swapProgramIn(Orig);
  delete ToOptimize;
  delete ToNotOptimize;
  return false;
}
Example #5
0
/// TestFuncs - split functions in a Module into two groups: those that are
/// under consideration for miscompilation vs. those that are not, and test
/// accordingly. Each group of functions becomes a separate Module.
///
bool ReduceMiscompilingFunctions::TestFuncs(const std::vector<Function*> &Funcs,
                                            std::string &Error) {
  // Test to see if the function is misoptimized if we ONLY run it on the
  // functions listed in Funcs.
  outs() << "Checking to see if the program is misoptimized when "
         << (Funcs.size()==1 ? "this function is" : "these functions are")
         << " run through the pass"
         << (BD.getPassesToRun().size() == 1 ? "" : "es") << ":";
  PrintFunctionList(Funcs);
  outs() << '\n';

  // Create a clone for two reasons:
  // * If the optimization passes delete any function, the deleted function
  //   will be in the clone and Funcs will still point to valid memory
  // * If the optimization passes use interprocedural information to break
  //   a function, we want to continue with the original function. Otherwise
  //   we can conclude that a function triggers the bug when in fact one
  //   needs a larger set of original functions to do so.
  ValueMap<const Value*, Value*> VMap;
  Module *Clone = CloneModule(BD.getProgram(), VMap);
  Module *Orig = BD.swapProgramIn(Clone);

  std::vector<Function*> FuncsOnClone;
  for (unsigned i = 0, e = Funcs.size(); i != e; ++i) {
    Function *F = cast<Function>(VMap[Funcs[i]]);
    FuncsOnClone.push_back(F);
  }

  // Split the module into the two halves of the program we want.
  VMap.clear();
  Module *ToNotOptimize = CloneModule(BD.getProgram(), VMap);
  Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize, FuncsOnClone,
                                                 VMap);

  // Run the predicate, note that the predicate will delete both input modules.
  bool Broken = TestFn(BD, ToOptimize, ToNotOptimize, Error);

  delete BD.swapProgramIn(Orig);

  return Broken;
}
Example #6
0
// ValueMap map<string, string>
bool Domain::Indices::Lookup(const ValueMap& specified, Data::RIDList& results) {
	if(!this->meta->OpenReader()) { return false; }	
	if(!this->meta->index->OpenReader()) { return false; }
	
	string name;
	ValueMap::const_iterator cell;
	map< string, set<string> > indices;
	for(cell = specified.begin(); cell != specified.end(); cell++) {
		if(this->meta->Index(cell->first, name)) {
			indices[name].insert(cell->first);
		} else {
			this->meta->Close(); return false;
		}
	}
	
	ValueMap partition;
	Data::RIDList records;
	map< string, set<string> >::iterator fragment;
	for(fragment = indices.begin(); fragment != indices.end(); fragment++) {
		partition.clear();
		this->Partition(specified, fragment->second, partition);
		if(!this->meta->index->Lookup(partition, records)) {
			this->meta->index->Close(); return false; 
		} else {
			if(records.size() == 0) {
				results.clear(); return true;
			} else {
				if(results.size() == 0) {
					results.assign(records.begin(), records.end());
				} else {
					results = results & records;
				}
			}
		}
	}
	this->meta->index->Close();
	this->meta->Close();
	return true;
}
Example #7
0
bool loadColProbs(const std::string &file_name, NameDict &term_dict, ValueMap &col_probs, double &default_col_prob){
	col_probs.clear();
	ifstream fin(file_name.c_str());
	if (! fin){
		ucair::getLogger().error("Failed to open " + file_name);
		return false;
	}
	try{
		string line;
		if (! getline(fin, line)){
			return false;
		}
		size_t pos = line.find('\t');
		if (pos == string::npos){
			return false;
		}
		trim_right(line);
		int unique_term_count = lexical_cast<int>(line.substr(0, pos));
		long long total_term_count = lexical_cast<long long>(line.substr(pos + 1));
		default_col_prob = 1.0 / (total_term_count + unique_term_count);
		while (getline(fin, line)){
			size_t pos = line.find('\t');
			if (pos == string::npos){
				return false;
			}
			trim_right(line);
			string term = line.substr(0, pos);
			long long term_count = lexical_cast<long long>(line.substr(pos + 1));
			int term_id = term_dict.getId(term, true);
			double col_prob = (term_count + 1.0) / (total_term_count + unique_term_count);
			col_probs.set(term_id, col_prob, false);
		}
	}
	catch (bad_lexical_cast &){
		return false;
	}
	return true;
}
Example #8
0
/*
 * this method saves the attribute together with the host string that
 * defines the type of object that this attribute is associated to (like
 * position or document) and the hosts database id.
 */
void AttributeMap::save( dbID id )
{
    checkHost();

    QSqlQuery attribQuery;
    attribQuery.prepare( "SELECT id, valueIsList FROM attributes WHERE hostObject=:host AND hostId=:hostId AND name=:name" );

    attribQuery.bindValue( ":host", mHost );
    attribQuery.bindValue( ":hostId", id.toString() );

    Iterator it;
    for ( it = begin(); it != end(); ++it ) {
        Attribute att = it.value();
        kDebug() << ">> oo-  saving attribute with name " << it.key() << " for " << id.toString() << " att-name: " << att.name();

        attribQuery.bindValue( ":name", att.name() );
        attribQuery.exec();

        QString attribId;

        if ( attribQuery.next() ) {
            // the attrib exists. Check the values

            attribId = attribQuery.value(0).toString();  // the id
            if ( att.value().isNull() || att.mDelete ) {
                // the value is empty. the existing entry needs to be dropped
                dbDeleteAttribute( attribId );
                return;
            }
        } else {
            // the attrib does not yet exist. Create if att value is not null.
            if ( att.value().isNull() ) {
                kDebug() << "oo- skip writing of attribute, value is empty";
            } else {
                kDebug() << "oo- writing of attribute name " << att.name();
                QSqlQuery insQuery;
                insQuery.prepare( "INSERT INTO attributes (hostObject, hostId, name, valueIsList, relationTable, "
                                  "relationIDColumn, relationStringColumn) "
                                  "VALUES (:host, :hostId, :name, :valueIsList, :relTable, :relIDCol, :relStringCol )" );
                insQuery.bindValue( ":host", mHost );
                insQuery.bindValue( ":hostId", id.toString() );
                insQuery.bindValue( ":name", att.name() );
                insQuery.bindValue( ":valueIsList", att.listValue() );

                // Write the relation table info. These remain empty for non related attributes.
                insQuery.bindValue( ":relTable", att.mTable );
                insQuery.bindValue( ":relIDCol", att.mIdCol );
                insQuery.bindValue( ":relStringCol", att.mStringCol );

                insQuery.exec();
                dbID attId = KraftDB::self()->getLastInsertID();
                attribId = attId.toString();
            }
        }

        // store the id to be able to drop not longer existent values
        kDebug() << "adding attribute id " << attribId << " for attribute " << att.name();

        // now there is a valid entry in the attribute table. Check the values.
        QSqlQuery valueQuery( "SELECT id, value FROM attributeValues WHERE attributeId=" + attribId );

        typedef QMap<QString, QString> ValueMap;
        ValueMap valueMap;

        while ( valueQuery.next() ) {
            QString idStr = valueQuery.value( 0 ).toString(); // id
            QString valStr = valueQuery.value( 1 ).toString(); // value

            valueMap[valStr] = idStr;
        }

        // create a stringlist with the current values of the attribute
        if ( att.listValue() ) {
            QStringList newValues;
            newValues = att.mValue.toStringList();
            kDebug() << "new values are: " << newValues.join( ", " );

            if ( newValues.empty() ) {
                // delete the entire attribute.
                dbDeleteValue( attribId ); // deletes all values
                dbDeleteAttribute( attribId );
                valueMap.clear();
            } else {
                // we really have new values

                QSqlQuery insValue;
                insValue.prepare( "INSERT INTO attributeValues (attributeId, value) VALUES (:attribId, :val)" );
                insValue.bindValue( ":attribId", attribId );

                // loop over all existing new values of the attribute.
                for ( QStringList::Iterator valIt = newValues.begin(); valIt != newValues.end(); ++valIt ) {
                    QString curValue = *valIt;

                    if ( valueMap.contains( curValue ) ) {
                        // the valueMap is already saved. remove it from the valueMap string
                        kDebug() << "Value " << curValue << " is already present with id " << valueMap[curValue];
                        valueMap.remove( curValue );
                    } else {
                        // the value is not yet there, insert it.
                        insValue.bindValue( ":val", curValue );
                        insValue.exec();
                    }
                }
            }
        } else {
            // only a single entry for the attribte, update if needed.
            QString newValue = att.mValue.toString();  // access the attribute object directly to get the numeric
            kDebug() << "NEW value String: " << newValue;
            // value in case the attribute is bound to a relation table
            if ( newValue.isEmpty() ) {
                // delete the entire attribute
                dbDeleteValue( attribId ); // deletes all values
                dbDeleteAttribute( attribId );
                valueMap.clear();
            } else {
                if ( valueMap.empty() ) {
                    // there is no entry yet that could be updated.
                    QSqlQuery insertQuery;
                    insertQuery.prepare( "INSERT INTO attributeValues (attributeId, value ) VALUES (:id, :val)" );
                    insertQuery.bindValue( ":id", attribId );
                    insertQuery.bindValue( ":val", newValue );

                    insertQuery.exec();
                    kDebug() << "insert new attrib value for non list: " << newValue;

                } else {
                    QString oldValue = valueMap.begin().key();
                    QString id = valueMap.begin().value();

                    if ( newValue != oldValue ) {
                        kDebug() << "Updating " << id << " from " << oldValue << " to " << newValue;
                        QSqlQuery updateQuery;
                        updateQuery.prepare( "UPDATE attributeValues SET value=:val WHERE id=:id" );
                        updateQuery.bindValue( ":val", newValue );
                        updateQuery.bindValue( ":id",  id );
                        kDebug() << "do the update!";
                        updateQuery.exec();
                    }
                    valueMap.remove( oldValue );
                }
            }
        }

        // remove all still existing entries in the valueMap because they point to values which are
        // in the db but were deleted from the attribute
        if ( ! valueMap.isEmpty() ) {
            ValueMap::Iterator mapIt;
            for ( mapIt = valueMap.begin(); mapIt != valueMap.end(); ++mapIt ) {
                QString valId = mapIt.value();
                dbDeleteValue( attribId, valId );
            }
        }
    }
}