示例#1
0
bool World::CalculatePath(Vector &start, Vector &finish, std::vector<Vector> &path)
{
    Tile *start_tile = GetTile(start);

    if(!start_tile)
    {
        return false;
    }

    Tile *finish_tile = GetTile(finish);

    if(!finish_tile)
    {
        return false;
    }

    bool result = TileMap::CalculatePath(start_tile, finish_tile);

    if(result)
    {
        for(Tile *tile = GetTile(finish); tile; tile = tile->GetParent())
        {
            path.emplace(path.begin(),
                (TileW * tile->GetX()) + (TileW / 2),
                (TileH * tile->GetY()) + (TileH / 2)
            );
        }

    }

    return result;
}
示例#2
0
/// <summary>
/// Generate assembly code for remote call.
/// </summary>
/// <param name="a">Underlying assembler object</param>
/// <param name="pfn">Remote function pointer</param>
/// <param name="args">Function arguments</param>
/// <param name="cc">Calling convention</param>
/// <param name="retType">Return type</param>
/// <returns>true on success</returns>
bool RemoteExec::PrepareCallAssembly( AsmHelperBase& a, 
                                      const void* pfn, 
                                      std::vector<AsmVariant>& args, 
                                      eCalligConvention cc, 
                                      eReturnType retType )
{
    size_t data_offset = ARGS_OFFSET;

    // Invalid calling convention
    if (cc < cc_cdecl || cc > cc_fastcall)
    {
        LastNtStatus( STATUS_INVALID_PARAMETER_3 );
        return false;
    }

    // Copy structures and strings
    for (auto& arg : args)
    {
        if (arg.type == AsmVariant::dataStruct || arg.type == AsmVariant::dataPtr)
        {
            _userData.Write( data_offset, arg.size, reinterpret_cast<const void*>(arg.imm_val) );
            arg.new_imm_val = _userData.ptr<size_t>() + data_offset;

            // Add some padding after data
            data_offset += arg.size + 0x10;
        }
    }

    // Insert hidden variable if return type is struct.
    // This variable contains address of buffer in which return value is copied
    if (retType == rt_struct)
    {
        args.emplace( args.begin(), AsmVariant( _userData.ptr<size_t>() + ARGS_OFFSET ) );
        args.front().new_imm_val = args.front().imm_val;
        args.front().type = AsmVariant::structRet;
    }
        
    a.GenPrologue();
    a.GenCall( pfn, args, cc );

    // Retrieve result from XMM0 or ST0
    if (retType == rt_float || retType == rt_double)
    {
        a->mov( asmjit::host::zax, _userData.ptr<size_t>() + RET_OFFSET );

#ifdef USE64
        if (retType == rt_double)
            a->movsd( asmjit::host::Mem( asmjit::host::zax, 0 ), asmjit::host::xmm0 );
        else
            a->movss( asmjit::host::Mem( asmjit::host::zax, 0 ), asmjit::host::xmm0 );
#else
        a->fstp( asmjit::host::Mem( asmjit::host::zax, 0, retType * sizeof(float) ) );
#endif
    }

    AddReturnWithEvent( a, mt_default, retType );
    a.GenEpilogue();

    return true;
}
示例#3
0
void CAddonDatabase::GetInstalled(std::vector<CAddonBuilder>& addons)
{
  try
  {
    if (NULL == m_pDB.get()) return;
    if (NULL == m_pDS.get()) return;

    m_pDS->query(PrepareSQL("SELECT * FROM installed"));
    while (!m_pDS->eof())
    {
      auto it = addons.emplace(addons.end());
      it->SetId(m_pDS->fv("addonID").get_asString());
      it->SetInstallDate(CDateTime::FromDBDateTime(m_pDS->fv("installDate").get_asString()));
      it->SetLastUpdated(CDateTime::FromDBDateTime(m_pDS->fv("lastUpdated").get_asString()));
      it->SetLastUsed(CDateTime::FromDBDateTime(m_pDS->fv("lastUsed").get_asString()));
      it->SetOrigin(m_pDS->fv("origin").get_asString());
      m_pDS->next();
    }
    m_pDS->close();
  }
  catch (...)
  {
    CLog::Log(LOGERROR, "%s failed", __FUNCTION__);
  }
}
示例#4
0
文件: main.cpp 项目: WhiZTiM/coliru
 void emplace(Args&&... args) {
     detail::is_component<T>();
     std::unique_ptr<Component> c{ new T(std::forward<Args>(args)...) };
     auto&& id = std::type_index(typeid(T));
     auto&& it = find(id);
     components.emplace(it, id, std::move(c));
 }
示例#5
0
std::vector<std::vector<int>> minesweeper(std::vector<std::vector<bool>> matrix) {
    int x = matrix[0].size();
    int y = matrix.size();
    std::vector<bool> m_allFalse(x + 2);
    std::vector<std::vector<int>> r;
    for(int i = 0;i < matrix.size();i++){
        matrix[i].emplace(matrix[i].begin(), 0);
        matrix[i].push_back(0);
    }
    matrix.emplace(matrix.begin(), m_allFalse);
    matrix.push_back(m_allFalse);
    
    for(int i = 1; i < matrix.size() - 1;i++){
        std::vector<int> q(x);
        for(int j = 1; j < matrix[0].size();j++){
            for(int a = i - 1;a < i + 2;a++)
                for(int b = j - 1;b < j + 2;b++){
                    if(matrix[a][b]) q[j - 1]++;
                }
            if(matrix[i][j]) q[j - 1]--;
        }
        r.push_back(q);
    }
    
    return r;
}
示例#6
0
文件: main.cpp 项目: CCJY/coliru
void insertInitListProxy(std::vector<VecT> & Cnt, Iterator pos, std::initializer_list<LType> il)
{
    // pre-allocate space
    Cnt.reserve(Cnt.size() + il.size());
    // construct the items in-place
    for (auto it = il.begin(); it < il.end(); ++it)
    	pos = Cnt.emplace(pos, *it) + 1;
}
示例#7
0
            inline void taPushFront(const T& mX)
            {
                // Instant
                data.emplace(std::begin(data), mX);
                auto& ts(create<TextSquare>(ssvs::zeroVec2f));
                auto xStr(ssvu::toStr(mX));

                // Timed
                this->createTA() += [this, &ts](auto&, FT)
                {
                    tss.emplace(std::begin(tss), &ts);
                };
                this->createTA() += [this](auto&, FT)
                {
                    this->refreshPositions();
                };
                ts.taShow();
                ts = xStr;
            }
示例#8
0
文件: main.cpp 项目: CCJY/coliru
void insertInitListProxy(std::vector<VecT> & Cnt, Iterator pos, std::initializer_list<LType> il)
{
    // save iterator 'distance' from begin() in case a resize operation happens
    auto diff = pos - Cnt.begin();
    // pre-allocate space
    Cnt.reserve(Cnt.size() + il.size());
    // reset iterator based on any changes that occurred due to a resize
    // from here on out, we don't need to worry about resizes
    pos = Cnt.begin() + diff;
    // construct the items in-place
    for (auto it = il.begin(); it < il.end(); ++it)
    {
        pos = Cnt.emplace(pos, *it);
        ++pos;  // move to position *after* what was just inserted
    }
}
示例#9
0
 void itemCreated(const std::string& file)
 {
     auto it = std::lower_bound(m_dirEntries.begin(), m_dirEntries.end(), file, Cmp());
     it = m_dirEntries.emplace(it, file);
     
     std::string filePatch = m_dir.path();
     if (!endsWith(filePatch, '/'))
         filePatch.push_back('/');
     filePatch.append(file);
     if (stat64(filePatch.c_str(), &it->info) == -1) {
         m_dirEntries.erase(it);
         return;
     }
     
     q->itemInserted(it - m_dirEntries.begin());
 }
 CXIdxClientContainer updateClientContainer(const CXIdxEntityInfo* info, const CXIdxLoc l)
 {
     std::string container;
     if (info->name)
         container = info->name;
     else
         container = "<anonymous-tag>";
     //
     location loc = {l};
     auto result = std::string{loc.file().toLocalFile().toUtf8().constData()} + ":"
       + std::to_string(loc.line()) + ":"
       + std::to_string(loc.column()) + ": "
       + container
       ;
     auto& ptr = *m_containers.emplace(end(m_containers), new std::string(std::move(result)));
     return CXIdxClientContainer(ptr.get());
 }
示例#11
0
 inline static void run(std::vector<T> &c, std::size_t size) {
     for(std::size_t i=0; i<size; ++i) {
         c.emplace(begin(c));
     }
 }
void bad_emplace_vector1(std::vector<int> &V, int n) {
  auto i1 = V.cbegin(), i0 = i1++;
  V.emplace(i1, n);
  *i1; // expected-warning{{Invalidated iterator accessed}}
}
	void addAt(T value, size_t loc = 0) {
		m->emplace(m.begin() + loc, value);
	}
void good_emplace_vector1(std::vector<int> &V, int n) {
  auto i1 = V.cbegin(), i0 = i1++;
  V.emplace(i1, n);
  *i0; // no-warning
}
示例#15
0
void greedy_path()
{
	//cout << "Inside funciton ";
	std::unordered_set<int> s;
	while (s.size() < 3)
	{ 
		//cout << "In while";
		srand(time(NULL));
		s.insert(rand()%count);///or count-1?????
	}
	
	//int path[num_cities+2]; 
	int k=0;
	
	//std::vector<int>::iterator k;
	//k = path.begin();
	std::unordered_set<int>::iterator it;
	for(it=s.begin();it!=s.end();++it)
	{
		//path[k]=*it;
		//cout << *it << " ";
		path.push_back(*it);
		k++;
		//path.emplace(k,*it);
		//k++;
	}

	
	it=s.begin(); double d1,d2,d3; int m;double cost,minCost;
	path.push_back(*it);
	k++;

	//auto iit=path.begin();
	//while(iit != path.end())
	//{
	//	cout << *iit << " ";
	//	++iit;

	//}
	//cout << endl;

//	cout << "HI" << endl;

	//path.emplace(k++,*it);  /*from here!!
	
	for(int i=1;i<count;i++)
	{
		//cout << "Inside loop" << " ";
		bool found = false;
		for(auto k1=path.begin();k1!=path.end();k1++)
		{
			if(*k1 == i)
			{
				found = true;
				break;
			}
		}
		if(found == false)
		{
		//	cout << "Inside false if ";
			m=0;
			d1=distances[path[m]][i];
			d2=distances[path[m+1]][i];
			d3=distances[path[m]][path[m+1]];
			minCost = ( d1 + d2 ) - d3;
			for(int l=1;l<k-1;l++)
			{
				d1=distances[path[l]][i];
				d2=distances[path[l+1]][i];
				d3=distances[path[l]][path[l+1]];
				cost=(d1+d2)-d3;
				if(cost<minCost)
				{
					minCost=cost;
					m=l;
				}

			}
			std::vector<int>::iterator myit = path.begin();
			myit+=(m+1);
			//if(m == 0)
			//{
			//	cout << "\nWHOA!\n";
			//}
			path.emplace(myit,i);
			k++;
		}

	}
	

	//for(int x=0;x<k;x++)
	//	cout << path[x] << " ";
	//cout << endl;

	fwd.push_back(0);
	bkd.push_back(0);
	
	std::vector<int>::iterator i1,i2;
	for(int i=1;i<count;i++)
	{
		//cout << "Inside for";
		//fwd[i]=0;
		//bkd[i]=0;
		/*std::vector<int>::iterator i3,i4;
		
		i3 = fwd.emplace(i3,0);
		i4 = bkd.emplace(i4,0);*/
		fwd.push_back(0);
		bkd.push_back(0);
	}
	i1 = fwd.begin();
	i2 = bkd.begin();
	for(int i=1;i<count;i++)
	{
		
		fwd[path[i]] = path[i-1];         //////i-1 doesnot exist for 0
		bkd[path[i-1]] = path[i];
	}

}
void good_emplace(std::vector<int> &v, int n) {
  v.emplace(v.cbegin(), n); // no-warning
}
void bad_emplace(std::vector<int> &v1, std::vector<int> &v2, int n) {
  v2.emplace(v1.cbegin(), n); // expected-warning{{Container accessed using foreign iterator argument}}
}