本文整理汇总了C++中Blocks类的典型用法代码示例。如果您正苦于以下问题:C++ Blocks类的具体用法?C++ Blocks怎么用?C++ Blocks使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Blocks类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: simplifyPFBlock
void simplifyPFBlock(const Edges& toUnlink, const PFBlock& block, Blocks& simplifiedBlocks, Nodes& history) {
// take a block, unlink some of the edges and
// create smaller blocks or a simplified blocks
// or if nothing has changed take a copy of the original block
if (toUnlink.size() == 0) {
// no change needed, just make a copy of block
PFBlock newblock(block.elementIds(), block.edges(), simplifiedBlocks.size(), 's'); // will copy edges and ids
PDebug::write("Made {}", newblock);
auto id = newblock.id();
simplifiedBlocks.emplace(id, std::move(newblock));
// update history
makeHistoryLinks(block.elementIds(), {id}, history);
} else {
Edges modifiedEdges;
for (auto edge : block.edges()) { // copying edges
Edge e = edge.second;
if (toUnlink.find(edge.first) != toUnlink.end()) {
e.setLinked(false);
}
modifiedEdges.emplace(e.key(), e);
}
// create new blocks and add into simplifiedBlocks
buildPFBlocks(block.elementIds(), modifiedEdges, 's', simplifiedBlocks, history);
}
}
示例2: addBranchBlock
static bool addBranchBlock(Blocks &blocks, Block &block,
const Instruction &branchDestination,
Block *&branchBlock, BlockEdgeType type) {
/* Prepare to follow one branch of the path.
Returns true if this is a completely new path we haven't handled yet.
branchBlock will be filled with the block for the branch. */
bool needAdd = false;
// See if we have already handled this branch. If not, create a new block for it.
branchBlock = const_cast<Block *>(branchDestination.block);
if (!branchBlock) {
blocks.push_back(Block(branchDestination.address));
branchBlock = &blocks.back();
needAdd = true;
}
// Link the branch with its parent
branchBlock->parents.push_back(&block);
block.children.push_back(branchBlock);
block.childrenTypes.push_back(type);
return needAdd;
}
示例3: puzzle_i
void puzzle_i()
{
Blocks bs;
Board board(5, 6);
bs.push_back(&(*(new Block()))("***"));
bs.push_back(&(*(new Block()))("***| *| *"));
bs.push_back(&(*(new Block()))("**|**"));
bs.push_back(&(*(new Block()))("*|**"));
bs.push_back(&(*(new Block()))(" **| *|**"));
bs.push_back(&(*(new Block()))("*|*"));
bs.push_back(&(*(new Block()))("***| *"));
bs.push_back(&(*(new Block()))("*|**| *"));
cout << "---------- Puzzle I ----------" << endl;
if (!board.Unblock(bs))
{
cout << "No solution!" << endl;
}
for (auto i = bs.cbegin(); i != bs.cend(); i++)
{
delete (*i);
}
}
示例4: Unblock
// Start solving the problem.
bool Board::Unblock(Blocks bs)
{
count_setblock = 0;
count_checkblock = 0;
count_setcell = 0;
count_checkcell = 0;
// Sort Blocks by block weight
sort(bs.begin(), bs.end(), [](Block *a, Block *b)
{
return (a->weight > b->weight);
});
for (auto i = bs.cbegin(); i != bs.cend(); i++)
{
(*i)->Print("Block " + to_string(i - bs.cbegin()));
}
// Find solution
bool result = RecursiveSetBlock(bs, 0);
cout << "count_setblock = " << count_setblock << endl
<< "count_checkblock = " << count_checkblock << endl
<< "count_setcell = " << count_setcell << endl
<< "count_checkcell = " << count_checkcell << endl;
return result;
}
示例5:
~CFGCalculator() {
for(Blocks::iterator i = blocks_.begin();
i != blocks_.end();
i++) {
delete i->second;
}
}
示例6: getBlocks
void PatchMgr::getBlockCandidates(Scope &scope, Point::Type types, Candidates &ret) {
Blocks blocks;
getBlocks(scope, blocks);
for (Blocks::iterator iter = blocks.begin(); iter != blocks.end(); ++iter) {
if (types & Point::BlockEntry) ret.push_back(Candidate(Location::Block(*iter), Point::BlockEntry));
if (types & Point::BlockDuring) ret.push_back(Candidate(Location::Block(*iter), Point::BlockDuring));
if (types & Point::BlockExit) ret.push_back(Candidate(Location::Block(*iter), Point::BlockExit));
}
}
示例7: constructBlocks
void constructBlocks(Blocks &blocks, Instructions &instructions) {
/* Create the first block containing the very first instruction in this script.
* Then follow the complete code flow from this instruction onwards. */
assert(blocks.empty());
if (instructions.empty())
return;
blocks.push_back(Block(instructions.front().address));
constructBlocks(blocks, blocks.back(), instructions.front());
}
示例8: PFBlockBuilder
void PFReconstructor::reconstruct() {
// TODO sort m_blocks
// simplify the blocks by editing the links
// each track will end up linked to at most one hcal
// sort the blocks by id to ensure match with python
std::vector<IdType> blockids;
std::vector<IdType> newblockids;
Ids ids = m_pfEvent.mergedElementIds();
// create the blocks of linked ids
auto bBuilder = PFBlockBuilder(ids, m_pfEvent);
m_blocks = bBuilder.blocks();
for (const auto& b : m_blocks) {
blockids.push_back(b.first);
}
#if WITHSORT
std::sort(blockids.begin(), blockids.end());
#endif
// go through each block and see if it can be simplified
// in some cases it will end up being split into smaller blocks
// Note that the old block will be marked as disactivated
for (auto bid : blockids) {
// std::cout<<Id::pretty(bid)<< ":" << bid <<std::endl;
Blocks newBlocks = simplifyBlock(bid);
if (newBlocks.size() > 0) {
for (auto& b : newBlocks) {
IdType id = b.first;
m_blocks.emplace(id, std::move(b.second));
newblockids.push_back(b.first);
}
}
}
blockids.insert(std::end(blockids), std::begin(newblockids), std::end(newblockids));
for (auto bid : blockids) {
PFBlock& block = m_blocks.at(bid);
if (block.isActive()) { // when blocks are split the original gets deactivated
PDebug::write("Processing {}", block);
reconstructBlock(block);
}
}
if (m_unused.size() > 0) {
PDebug::write("unused elements ");
for (auto u : m_unused)
PDebug::write("{},", u);
// TODO warning message
}
}
示例9: compute
template<int BlockSize> void compute(Blocks<BlockSize>& blocks)
{
for(size_t i = 0 ; i < blocks.r.size(); ++i)
{
blocks.eval(i);
}
}
示例10: findDeadBlockEdges
void findDeadBlockEdges(Blocks &blocks) {
/* Run through all blocks and find edges that are logically dead and will
* never be taken.
*
* Currently, this is limited to one special case that occurs in scripts
* compiled by the original BioWare NWScript compiler (at least in NWN and
* KotOR): short-circuiting in if (x || y) conditionals. The original BioWare
* compiler has a bug where it generates a JZ instead of a JMP, creating a
* true branch that will never be taken and effectively disabling short-
* circuiting. I.e. both x and y will always be evaluated; when x is true,
* y will still be evaluated afterwards.
*
* We use very simple pattern-matching here. This is enough to find most
* occurances of this case, but not all. */
for (Blocks::iterator b = blocks.begin(); b != blocks.end(); ++b) {
if (!isTopStackJumper(*b) || (b->instructions.size() != 2) || b->parents.empty())
continue;
/* Look through all parents of this block and make sure they fit the
* pattern as well. They also all need to jump to this block with the
* same branch edge (true or false). */
size_t parentEdge = SIZE_MAX;
for (std::vector<const Block *>::const_iterator p = b->parents.begin(); p != b->parents.end(); ++p) {
if (!isTopStackJumper(**p, &*b, &parentEdge)) {
parentEdge = SIZE_MAX;
break;
}
}
if (parentEdge == SIZE_MAX)
continue;
assert(parentEdge < 2);
/* We have now established that
* 1) This block checks whether the top of the stack is == 0
* 2) All parent blocks check whether the top of the stack is == 0
* 3) All parent blocks jump with the same branch edge into this block
*
* Therefore, this block must also always follow the exact same edge.
* This means the other edge is logically dead. */
b->childrenTypes[1 - parentEdge] = kBlockEdgeTypeDead;
}
}
示例11: MarkBlockUsed
void MarkBlockUsed( const SBlock& p_Block, unsigned int p_unWidth, unsigned int p_unHeight )
{
m_unFirstX += p_unWidth;
if( m_unFirstX + p_unWidth >= m_unWidth )
{
m_unFirstX = 0;
m_unFirstY += p_unHeight;
}
m_vecBlocks.push_back( p_Block );
}
示例12: IsBlockFree
bool IsBlockFree( const SBlock& p_Block )const
{
unsigned int unRight = p_Block.m_unLeft + p_Block.m_unWidth;
unsigned int unBottom = p_Block.m_unTop + p_Block.m_unHeight;
if( unRight > m_unWidth || unBottom > m_unHeight )
{
return false;
}
Blocks::const_iterator IteEnd = m_vecBlocks.end();
for( Blocks::const_iterator Ite = m_vecBlocks.begin();
Ite != IteEnd; ++Ite )
{
if( Ite->m_unLeft < unRight && p_Block.m_unLeft < Ite->m_unLeft + Ite->m_unWidth
&& Ite->m_unTop < unBottom && p_Block.m_unTop < Ite->m_unTop + Ite->m_unHeight )
{
return false;
}
}
return true;
}
示例13: solve
void solve() {
int w = 0;
int h = 0;
int nBlocks = 0;
cin >> w >> h >> nBlocks;
Blocks blocks;
blocks.resize(h + 1);
for (int y = 0; y <= h; ++y) {
blocks[y].resize(w + 1);
}
for (int i = 0; i < nBlocks; ++i) {
int x = 0;
int y = 0;
cin >> x >> y;
blocks[y][x] = true;
}
int nSolution = 0;
uint nMinSolutionLength = numeric_limits<unsigned long long>::max();
travelse(0, 0, w, h, blocks, nSolution, 1, nMinSolutionLength);
solutions.push_back(nSolution);
}
示例14: isColl
void isColl(Blocks& _block) {
if (getBoundingBox().intersects(_block.getBoundingBox())) {
cout << "col" << endl;
_block.setColor(sf::Color::Red);
if (_spriteG.getPosition().y <= _block.getBoundingBoxTop()) {//up
canMoveUp = false;
MarioJumping = false;
if (_spriteG.getPosition().x - 2 < _block.getBoundingBoxLeft() - 12) {
MarioJumping = true;
canMoveRight = false;
}
else if (_spriteG.getPosition().x > _block.getBoundingBoxLeft() + 23) {
MarioJumping = true;
canMoveLeft = false;
}
}
else if (_spriteG.getPosition().y > _block.getBoundingBoxTop() - _block.getBoundingBoxHeight()) {
_velocity.y = 5;
MarioJumping = true;
}
else {
if (_spriteG.getPosition().x < _block.getBoundingBoxLeft() - 12) {//Left
canMoveLeft = false;
}
else if (_spriteG.getPosition().x > _block.getBoundingBoxLeft() + 23) {//right
canMoveRight = false;
}
}
}
else {
canMoveRight = true;
canMoveLeft = true;
canMoveUp = true;
if (canMoveUp == true)
_velocity.y += gravity;
}
}
示例15: RecursiveSetBlock
// This is the core solution
bool Board::RecursiveSetBlock(Blocks &bs, size_t block_index)
{
Block* block = bs[block_index];
size_t xmax = width - block->width;
size_t ymax = height - block->height;
for (size_t x = 0; x <= xmax; x++)
{
for (size_t y = 0; y <= ymax; y++)
{
// if there is a place for block, process.
if (SetBlock(block, x, y))
{
// If the block is the last one, solution found.
if (block_index == bs.size() - 1)
{
cout << "Step: Put block " << block_index << " at [" << x << ", " << y << "]" << endl;
block->Print(width, height, x, y, "Block " + to_string(block_index));
return true;
}
// If not the last one, process other blocks.
if (RecursiveSetBlock(bs, block_index + 1))
{
// If all other blocks are positioned correctly, solution found.
cout << "Step: Put block " << block_index << " at [" << x << ", " << y << "]" << endl;
block->Print(width, height, x, y, "Block " + to_string(block_index));
return true;
}
else
{
// If not able to found a solution for other blocks, rollback current block,
// and continually find next available position for current block.
ClearBlock(block, x, y);
continue;
}
}
}
}
return false;
}