コード例 #1
0
ファイル: local_storage.cpp プロジェクト: pombredanne/jubatus
void local_storage::inp(const common::sfv_t& sfv, map_feature_val1_t& ret)
    const {
  ret.clear();

  std::vector<float> ret_id(class2id_.size());
  for (common::sfv_t::const_iterator it = sfv.begin(); it != sfv.end(); ++it) {
    const string& feature = it->first;
    const float val = it->second;
    id_features3_t::const_iterator it2 = tbl_.find(feature);
    if (it2 == tbl_.end()) {
      continue;
    }
    const id_feature_val3_t& m = it2->second;
    for (id_feature_val3_t::const_iterator it3 = m.begin(); it3 != m.end();
        ++it3) {
      ret_id[it3->first] += it3->second.v1 * val;
    }
  }

  for (size_t i = 0; i < ret_id.size(); ++i) {
    if (ret_id[i] == 0.f) {
      continue;
    }
    ret[class2id_.get_key(i)] = ret_id[i];
  }
}
コード例 #2
0
ファイル: Movable.cpp プロジェクト: Chemrat/karya-valya
unsigned int ForceManager::Hash()
{
    unsigned int hash = 0;
    int i = 1;
    for (auto movable = under_force_.begin(); movable != under_force_.end(); ++movable)
    {
        hash += movable->ret_id() * i;
        ++i;
    }
    return hash;
}
コード例 #3
0
ファイル: Closet.cpp プロジェクト: Chemrat/karya-valya
bool Closet::Contains(id_ptr_on<IOnMapBase> item) const
{
    for (auto it = content_.begin(); it != content_.end(); ++it)
    {
        if (it->ret_id() == item.ret_id())
        {
            return true;
        }
    }
    return false;
}
コード例 #4
0
ファイル: Ghost.cpp プロジェクト: Chemrat/karya-valya
void Ghost::Process()
{
    --seconds_until_respawn_;
    if (seconds_until_respawn_ < 0)
    {
        size_t net_id = GetGame().GetFactory().GetNetId(GetId());
        if (net_id)
        {
            auto login_mob = Create<IMob>(LoginMob::T_ITEM_S(), 0);

            GetGame().GetFactory().SetPlayerId(net_id, login_mob.ret_id());
            if (GetId() == GetGame().GetMob().ret_id())
            {
                GetGame().ChangeMob(login_mob);
            }
            Delete();
            //qDebug() << "Ghost deleted: net_id: " << net_id;
        }
    }
}
コード例 #5
0
c_galaxysrv_peers::t_peering_reference_parse c_galaxysrv_peers::parse_peer_reference(const string & simple) const{
	// @TODO not using std::regex since it had compatibility problems. Consider using when possible (bug#J446).
	const char separator='@', group_open='(', group_close=')';
	const string literal_anyone = "anyone";
	reasonable_size(simple);

	_note("Parsing: "<<simple);
	_check_input(simple.size()>=3); // some reasonable sized not-empty string

	size_t pos1 = simple.find(separator); // was there any "@"

	if (pos1 == string::npos) { // must be one-part format "VIRTUAL" (only contains the ID/ipv6, no cables)
		vector<string> ret_id( { simple } ); // e.g. "fd42:f6c4:9d19:f128:30df:b289:aef0:25f5,score=-300"
		vector<string> ret_cable{ };
		// make sure this part does not contain ( or ) etc
		_check_input( string::npos == simple.find(group_open) );
		_check_input( string::npos == simple.find(group_close) );
		_check_input( simple.size()>0 );
		return std::make_pair(std::move(ret_id), std::move(ret_cable));
	}
	else { // format "VIRTUAL@(CABLE)" possibly with more "@(CABLE)"
		string part1 = simple.substr(0,pos1); // the VIRTUAL
		// make sure this part does not contain ( or )
		_check_input( string::npos == part1.find(group_open) );
		_check_input( string::npos == part1.find(group_close) );
		_check_input( part1.size()>0 );
		vector<string> ret_id;
		if (part1 != literal_anyone) {
			ret_id.push_back( part1 ); // e.g. "fd42:f6c4:9d19:f128:30df:b289:aef0:25f5,score=-300"
		} // else, it is 'anyone' VIRTUAL - so it is reported by empty string

		// fd42::25f5@(udp:p.meshnet.pl:9042,cost=500)@(shm:test)@(tcp:[fe80::d44e]:9042)
		//             B
		//             B.............................X
		//                                           X@(B
		//                                              B.......X@
		//                                                      X@(B
		//                                                         B.....................end

		vector<string> ret_cable;
		// will parse additional groups "@(....)" selecting their index posB...posX
		const size_t size = simple.size(), size_before=size-1; _check(size_before < size);
		_check_input(pos1+2 < size);
		_check_input(simple.at(pos1+0)==separator);  // theck the '@' out of "@(" that we just found
		_check_input(simple.at(pos1+1)==group_open); // theck the '(' out of "@(" that we just found
		size_t posB = pos1+2; // begin, poiting after "@("
		_info(join_string_sep(posB," < ",size));
		while (posB < size_before) {
			auto posX = simple.find(group_close,posB); // find ")"
			_dbg3("posX=" << posX << " posB="<<posB);
			if (posX == string::npos) {
				_info("Hit end because posX="<<posX);
				posX = size_before;
			}
			string partX = simple.substr(posB, posX-posB);
			_dbg3("posX=" << posX << " posB="<<posB<<" given " <<partX);
			// make sure this part does not contain ( or ), e.g. "CABLE(" as result of parsing "VIRTUAL@(CABLE(CABLE)"
			_check_input( string::npos == partX.find(group_open) );
			_check_input( string::npos == partX.find(group_close) );
			_check_input( partX.size()>0 );

			ret_cable.push_back( std::move(partX) );
			posB=posX;
			_check_input(simple.at(posB)==group_close); // ")"
			++posB;
			if (!(posB<size)) break; // end is possible after last "....@(...)"
			// otherwise we open new group:
			_check_input(simple.at(posB)==separator); // ")@"
			++posB;
			_check_input(simple.at(posB)==group_open); // ")@(" after this
			++posB;
		}
		return std::make_pair(std::move(ret_id), std::move(ret_cable));
	} // other format
}