Exemplo n.º 1
0
QList<PageItem*> InlineFrame::getGroupedItems()
{
	QList<PageItem*> result;
//	result.setAutoDelete(false);
	if (hasItem())
	{
		PageItem* dItem = d->item;
		ScribusDoc& doc(*dItem->doc());
		result.append(d->item);
		if (dItem->Groups.count() != 0)
		{
			for (int ga=0; ga < doc.FrameItems.count(); ++ga)
			{
				if (doc.FrameItems.at(ga)->Groups.count() != 0)
				{
					if (doc.FrameItems.at(ga)->Groups.top() == dItem->Groups.top())
					{
						if (doc.FrameItems.at(ga)->ItemNr != dItem->ItemNr)
						{
							if (!result.contains(doc.FrameItems.at(ga)))
								result.append(doc.FrameItems.at(ga));
						}
					}
				}
			}
		}
	}
	return result;
}
Exemplo n.º 2
0
void Inventory::reflow() {
	uint16 itemCount = 0;
	uint16 totalWidth = 0;

	for (uint i = 0; _availableItems[i].var; i++) {
		if (hasItem(_availableItems[i].var)) {
			totalWidth += _availableItems[i].textureWidth;
			itemCount++;
		}
	}

	if (itemCount >= 2)
		totalWidth += 9 * (itemCount - 1);

	uint16 left = (Renderer::kOriginalWidth - totalWidth) / 2;

	for (ItemList::iterator it = _inventory.begin(); it != _inventory.end(); it++) {
		const ItemData &item = getData(it->var);

		uint16 top = Renderer::kTopBorderHeight + Renderer::kFrameHeight
				+ (Renderer::kBottomBorderHeight - item.textureHeight) / 2;

		it->rect = Common::Rect(item.textureWidth,
				item.textureHeight);
		it->rect.translate(left, top);

		left += item.textureWidth;

		if (itemCount >= 2)
			left += 9;
	}
}
Exemplo n.º 3
0
returnValue LogRecord::addItem(	const Expression& _name,
								const char* const _label,
								const char* const _startString,
								const char* const _endString,
								uint _width,
								uint _precision,
								const char* const _colSeparator,
								const char* const _rowSeparator
								)
{
	// checks if item already exists
	if ( hasItem( _name ) == BT_TRUE )
		return SUCCESSFUL_RETURN;

	// create new item
	LogRecordItem* newItem = new LogRecordItem( _name,_label,_startString,_endString,
												_width,_precision,_colSeparator,_rowSeparator );

	if ( number == 0 )
	{
		first = newItem;
		last = newItem;
	}
	else
	{
		if ( last->setNext( newItem ) != SUCCESSFUL_RETURN )
			return ACADOERROR( RET_LOG_RECORD_CORRUPTED );
		last = newItem;
	}

	++number;

	return SUCCESSFUL_RETURN;
}
Exemplo n.º 4
0
		// This virtual method is automatically called byt map/layer, when update is called from main.cpp
		virtual void update(float deltaTime)
		{
			// Call update to base class
			CharacterController::update(deltaTime);

			// AutoAttackFlagCarryingBot
			if (m_gameObjectToShoot != 0)
			{
				float rotation = m_gameObjectToShoot->getRotation();
				slm::vec2 enemyForwardDir;
				enemyForwardDir.x = cosf(rotation);
				enemyForwardDir.y = sinf(rotation);
				autoUsePrimaryWeapon(m_gameObjectToShoot->getPosition() + m_predictionDistance*enemyForwardDir, m_aimTolerance);
			}

			// DirectMoverAI
			if (m_gameObjectToGo != 0)
			{
				// Move to position
				m_distanceToDestination = moveDirectToPosition(m_gameObjectToGo->getPosition(), m_reachTolerance);
			}

			// If has collided to home base, then drop bomb.
			if (m_collisionToHomeBase)
			{
				// Obly if I has flag
				if (hasItem())
				{
					dropItem1();
				}

				m_collisionToHomeBase = false;
			}
		}
Exemplo n.º 5
0
void RecursiveCFGBuilder::visitStmt(ShPtr<Statement> stmt, bool visitSuccessors,
		bool visitNestedStmts) {
	if (!stmt) {
		return;
	}

	if (hasItem(accessedStmts, stmt)) {
		// The statement has been accessed.
		ShPtr<CFG::Node> stmtNode(firstStmtNodeMapping[stmt]);
		cfg->addEdge(currNode, stmtNode);
		return;
	}

	// When the statement is a goto target and there are some statements in the
	// current node, we have to emit the statement into a new node.
	if (stmt->isGotoTarget() && !currNode->stmts.empty()) {
		ShPtr<CFG::Node> prevNode(currNode);
		ShPtr<CFG::Node> stmtNode(addNode(stmt));
		cfg->addEdge(prevNode, stmtNode);
		return;
	}

	accessedStmts.insert(stmt);

	// The statement is not a goto target, so process it normally.
	stmt->accept(this);
}
Exemplo n.º 6
0
/**
* @brief Returns the variable named by @a varName.
*
* @param[in] varName Name of the requested variable.
*
* If @a varName is the name of an existing global variable, local variable
* (including function parameters), or a function, this variable is returned. If
* there is no variable named @a varName, this function creates a new one, adds
* it either to resModule as a global variable (when @c convertingGlobalVars is
* @c true), or into @c localVars (when @c convertingGlobalVars is @c false),
* and returns it.
*/
ShPtr<Variable> VarsHandler::getVariableByName(const std::string &varName) {
	// Try local variables (function parameters are included).
	if (!convertingGlobalVars && hasItem(localVars, varName)) {
		return localVars[varName];
	}

	// Try global variables (this should be done after checking local
	// variables).
	if (auto globVar = resModule->getGlobalVarByName(varName)) {
		return globVar;
	}

	// Try functions.
	if (auto func = resModule->getFuncByName(varName)) {
		return func->getAsVar();
	}

	// Create a new variable.
	// Create the variable of UnknownType. A proper type will be set later.
	auto var = Variable::create(varName, UnknownType::create());
	if (convertingGlobalVars) {
		resModule->addGlobalVar(var);
	} else {
		localVars[varName] = var;
	}
	return var;
}
Exemplo n.º 7
0
/* Returns the count of items which can be either 0 or 1. */
int QAspectRatioLayout::count() const {
        int returnValue = 0;
        if(hasItem()) {
                returnValue = 1;
        }
        return returnValue;
}
OrderedOfString OrderedOfString_selectUniqueItems (I, int sort) {
	iam (OrderedOfString);
	try {
		if (! sort) {
			autoOrderedOfString him = OrderedOfString_create ();
			for (long i = 1; i <= my size; i++) {
				SimpleString ss = (SimpleString) my item[i];
				if (! OrderedOfString_indexOfItem_c (him.peek(), ss -> string)) {
					autoSimpleString item = Data_copy (ss);
					Collection_addItem (him.peek(), item.transfer());
				}
			}
			Collection_shrinkToFit (him.peek());
			return him.transfer();
		}
		autoSortedSetOfString thee = SortedSetOfString_create ();
		/* Collection_to_SortedSet (I, int (*compare)(I, thou)) */
		for (long i = 1; i <= my size; i++) {
			if (! thy hasItem (my item[i])) {
				autoSimpleString item = Data_copy ( (SimpleString) my item[i]);
				Collection_addItem (thee.peek(), item.transfer());
			}
		}
		autoOrderedOfString him = OrderedOfString_create ();
		for (long i = 1; i <= thy size; i++) {
			autoSimpleString item = Data_copy ( (SimpleString) thy item[i]);
			Collection_addItem (him.peek(), item.transfer());
		}
		return him.transfer();
	} catch (MelderError) {
		Melder_throw (me, ": unique items not selected.");
	}
}
Exemplo n.º 9
0
returnValue LogRecord::addItem(	LogRecordItem& _item
								)
{
	// checks if item already exists
	if ( hasItem( _item.getName( ),_item.getType( ) ) == BT_TRUE )
		return SUCCESSFUL_RETURN;

	// create new item
	LogRecordItem* newItem = new LogRecordItem( _item );

	if ( number == 0 )
	{
		first = newItem;
		last = newItem;
	}
	else
	{
		if ( last->setNext( newItem ) != SUCCESSFUL_RETURN )
			return ACADOERROR( RET_LOG_RECORD_CORRUPTED );
		last = newItem;
	}

	++number;

	return SUCCESSFUL_RETURN;
}
/**
* @brief Precomputes @c funcInfo->isAlwaysModifiedBeforeRead for @c traversedFunc.
*/
void OptimFuncInfoCFGTraversal::precomputeAlwaysModifiedVarsBeforeRead() {
	// Initialization.
	funcInfo->varsAlwaysModifiedBeforeRead.clear();
	// Global variables which are read during the computation.
	VarSet readVars;

	// Currently, we only traverse the function's body up to the first compound
	// statement. Moreover, we only consider global variables as the computed
	// piece of information is useless for local variables.
	// TODO Use a CFG traversal for this to improve the analysis.
	ShPtr<Statement> stmt(traversedFunc->getBody());
	while (stmt) {
		if (stmt->isCompound()) {
			// As we are not using a CFG traversal, this is the end of the
			// computation.
			break;
		}

		ShPtr<ValueData> stmtData(va->getValueData(stmt));

		// Handle directly read variables.
		addToSet(stmtData->getDirReadVars(), readVars);

		// Handle function calls (indirectly accessed variables).
		for (auto i = stmtData->call_begin(), e = stmtData->call_end(); i != e; ++i) {
			ShPtr<CallInfo> callInfo(cio->computeCallInfo(*i, traversedFunc));
			for (const auto &var : globalVars) {
				if (callInfo->mayBeRead(var)) {
					readVars.insert(var);
				}
			}
		}

		// Handle directly written variables.
		for (auto i = stmtData->dir_written_begin(), e = stmtData->dir_written_end();
				i != e; ++i) {
			if (hasItem(globalVars, *i) && !hasItem(readVars, *i)) {
				// This global variable is modified before read.
				funcInfo->varsAlwaysModifiedBeforeRead.insert(*i);
			}
		}

		// TODO What about indirectly accessed variables?

		stmt = stmt->getSuccessor();
	}
}
Exemplo n.º 11
0
QString KStatusBar::itemText( int id ) const
{
    if ( !hasItem( id ) ) {
        return QString();
    }

    return d->items[id]->text();
}
Exemplo n.º 12
0
Item* Room::getItem() {
	if (!hasItem()) {
		return nullptr;
	}
	else {
		return item;
	}
}
Exemplo n.º 13
0
/**
 * Helper procedure that holds an Accessor for about 100 milliseconds.
 * @param envelope the envelope on which the thread should grasp an Accessor.
 * @param hasItem is true the procedure will periodically verify that 
 * the envelope still has an item; if false the procedure will periodically verify that 
 * the envelope still is empty.
 */
void accessAndHoldPointer(PtrEnvelope& envelope, bool hasItem) {
  auto accessor = envelope.makeAccessor();
  for (int i = 0; i < 33; i++) {
    CPPUNIT_ASSERT(envelope.getUseCount() > 0);
    CPPUNIT_ASSERT_EQUAL(accessor.hasItem(), hasItem);
    std::this_thread::sleep_for(std::chrono::milliseconds(3));
  }
}
Exemplo n.º 14
0
/**
* @brief Returns @c true if @a stmt defines @a var, @c false otherwise.
*
* @par Preconditions
*  - @a stmt and @a var are non-null
*/
bool isDefOfVar(ShPtr<Statement> stmt, ShPtr<Variable> var) {
	PRECONDITION_NON_NULL(stmt);
	PRECONDITION_NON_NULL(var);

	auto writtenVars = UsedVarsVisitor::getUsedVars(stmt, false,
		false)->getWrittenVars();
	return hasItem(writtenVars, var);
}
Exemplo n.º 15
0
/* Returns the item pointer. */
QLayoutItem* QAspectRatioLayout::itemAt(int index) const {
        if(index != 0) {
                return 0;
        }
        if(hasItem()) {
                return this->item;
        }
        return 0;
}
Exemplo n.º 16
0
QLayoutItem* LayoutSquare::itemAt( int index ) const
{
	if ( index == 0 )
	{
		if ( hasItem() ) return m_item;
	}

	return 0;
}
Exemplo n.º 17
0
/**
* @brief Returns @c true if @a func calls just functions from @a computedFuncs,
*        @c false otherwise.
*/
bool CallInfoObtainer::callsJustComputedFuncs(ShPtr<Function> func,
		const FuncSet &computedFuncs) const {
	ShPtr<CG::CalledFuncs> calledFuncs(cg->getCalledFuncs(func));
	for (const auto &callee : calledFuncs->callees) {
		if (!hasItem(computedFuncs, callee)) {
			return false;
		}
	}
	return true;
}
/**
* @brief Updates @c funcInfo by the information obtained from the given
*        statement.
*/
void OptimFuncInfoCFGTraversal::updateFuncInfo(ShPtr<Statement> stmt) {
	// Update the set of variables that are read and modified in the function.
	// Currently, we put also must-be-{read,modified} variables into
	// funcInfo->mayBe{Read,Modified}Vars. The reason is that we do not perform
	// any kind of analysis which variables are truly always accessed. For
	// example, if there is an if statement in the function, its body may never
	// be entered etc.
	ShPtr<ValueData> stmtData(va->getValueData(stmt));
	addToSet(stmtData->getDirReadVars(), funcInfo->mayBeReadVars);
	addToSet(stmtData->getMayBeReadVars(), funcInfo->mayBeReadVars);
	addToSet(stmtData->getMustBeReadVars(), funcInfo->mayBeReadVars);
	addToSet(stmtData->getDirWrittenVars(), funcInfo->mayBeModifiedVars);
	addToSet(stmtData->getMayBeWrittenVars(), funcInfo->mayBeModifiedVars);
	addToSet(stmtData->getMustBeWrittenVars(), funcInfo->mayBeModifiedVars);

	// Update storedGlobalVars. If the statement writes into a variable in
	// storedGlobalVars, we have to remove it from storedGlobalVars. Indeed, we
	// require that no local variable storing a global variable is written-into,
	// just read.
	const VarSet &dirWrittenVars(stmtData->getDirWrittenVars());
	const VarSet &mayBeWrittenVars(stmtData->getMayBeWrittenVars());
	const VarSet &mustBeWrittenVars(stmtData->getMustBeWrittenVars());
	for (auto i = storedGlobalVars.begin(), e = storedGlobalVars.end();
			i != e; ++i) {
		if (hasItem(dirWrittenVars, i->second) ||
				hasItem(mayBeWrittenVars, i->second) ||
				hasItem(mustBeWrittenVars, i->second)) {
			storedGlobalVars.erase(i);
			break;
		}
	}

	// Handle function calls.
	// TODO What if a call modifies a local variable from storedGlobalVars?
	for (const auto &call : stmtData->getCalls()) {
		ShPtr<OptimCallInfo> callInfo(cast<OptimCallInfo>(
			cio->computeCallInfo(call, traversedFunc)
		));

		addToSet(callInfo->mayBeReadVars, funcInfo->mayBeReadVars);
		addToSet(callInfo->mayBeModifiedVars, funcInfo->mayBeModifiedVars);
	}
}
    inline int itemIndex( const std::string& _fullPath ) const
    {
        if ( hasItem( _fullPath ) ) {
#if defined( _MSC_VER ) && ( _MSC_VER <= 1600 )
            return indexMap_.find( _fullPath )->second;
#else
            return indexMap_.at( _fullPath );
#endif
        }
        return -1;
    }
Exemplo n.º 20
0
QLayoutItem* LayoutSquare::take()
{
	QLayoutItem *tempItem = 0;

	if ( hasItem() )
	{
		tempItem = m_item;
		m_item = 0;
	}

	return tempItem;
}
Exemplo n.º 21
0
QLayoutItem* LayoutSquare::replaceItem( QLayoutItem *item )
{
	QLayoutItem *tempItem = 0;

	if ( hasItem() ) tempItem = m_item;

	m_item = item;

	setGeometry( *m_geometry );

	return tempItem;
}
Exemplo n.º 22
0
int StdGridLayoutImpl2::nextRowWithItem(int row, int c) const
{
  for (row += grid_.items_[row][c].rowSpan_; row < (int)grid_.rows_.size();
       ++row) {
    for (unsigned col = 0; col < grid_.columns_.size();
	 col += grid_.items_[row][col].colSpan_) {
      if (hasItem(row, col))
	return row;
    }
  }

  return grid_.rows_.size();
}
Exemplo n.º 23
0
int StdGridLayoutImpl2::nextColumnWithItem(int row, int col) const
{
  for (;;) {
    col = col + grid_.items_[row][col].colSpan_;

    if (col < (int)grid_.columns_.size()) {
      for (unsigned i = 0; i < grid_.rows_.size(); ++i)
	if (hasItem(i, col))
	  return col;
    } else
      return grid_.columns_.size();
  }
}
Exemplo n.º 24
0
	const std::string& ConfigService::getEmberMediaDirectory() const
	{
		static std::string path;
		//look for a media channel key in the config, and if found use that, else use the version of ember as a standard path
		if ( hasItem ( "wfut", "channel" ) )
		{
			path = getEmberDataDirectory() + "/" + static_cast<std::string> ( getValue ( "wfut", "channel" ) ) + "/";
		}
		else
		{
			path = getEmberDataDirectory() + "/ember-media-" + std::string ( VERSION ) + "/";
		}
		return path;
	}
/**
* @brief Tries to perform the case (2) optimization from the class description
*        on the given statement.
*
* For the preconditions, see tryOptimization(), which is the place from where
* this function should be called.
*/
void SimpleCopyPropagationOptimizer::tryOptimizationCase2(
		ShPtr<Statement> stmt, ShPtr<Variable> lhsVar, ShPtr<Expression> rhs) {
	// TODO Currently, we optimize (2) only if `expr` is a variable. Otherwise,
	//      in some cases, the result of the optimization is less readable than
	//      the original code.
	// TODO When optimizing also non-variable expressions, we have to use
	//      clone() when replacing the expression. Otherwise, there may be
	//      several expressions with the same address.
	if (!isa<Variable>(rhs)) {
		return;
	}

	// First, check whether the optimization can be done.
	StmtSet lhsUses(LhsRhsUsesCFGTraversal::getUses(stmt, currCFG, va, cio));
	if (lhsUses.empty()) {
		return;
	}

	// Check the correspondence between allLhsUses and lhsUses. In a greater
	// detail, allLhsUses has to contain all the statements in lhsUses + stmt
	// and possibly a variable-defining statement defining lhsVar without an
	// initializer.
	// TODO Can this restriction (empty initializer) be relaxed a bit?
	ShPtr<VarDefStmt> lhsDefStmt;
	ShPtr<VarUses> allLhsUses(vuv->getUses(lhsVar, currFunc));
	for (const auto &dirUse : allLhsUses->dirUses) {
		if (hasItem(lhsUses, dirUse) || stmt == dirUse) {
			continue;
		}

		lhsDefStmt = cast<VarDefStmt>(dirUse);
		if (!lhsDefStmt || lhsDefStmt->getVar() != lhsVar ||
				lhsDefStmt->getInitializer()) {
			return;
		}
	}

	// Do the optimization.
	for (const auto &lhsUse : lhsUses) {
		replaceVarWithExprInStmt(lhsVar, getRhs(stmt), lhsUse);
		va->removeFromCache(lhsUse);
	}
	removeVarDefOrAssignStatement(stmt);
	currCFG->removeStmt(stmt);
	if (lhsDefStmt) {
		removeVarDefOrAssignStatement(lhsDefStmt, currFunc);
		currCFG->removeStmt(lhsDefStmt);
	}
}
Exemplo n.º 26
0
/**
* @brief Visits the given node in the call graph.
*
* @param[in] calledFunc The given node.
* @param[in,out] calledFuncInfo Information about @a calledFunc.
*
* Corresponds to the strongconnect(v) function from
* http://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm
*/
void CallInfoObtainer::SCCComputer::visit(ShPtr<CG::CalledFuncs> calledFunc,
		CalledFuncInfo &calledFuncInfo) {
	// Set the depth index for calledFunc to the smallest unused index.
	calledFuncInfo.index = calledFuncInfo.lowlink = index;
	index++;

	// Push calledFunc onto the stack.
	stack.push(calledFunc);
	calledFuncInfo.onStack = true;

	// Consider the successors of calledFunc.
	for (const auto &callee : calledFunc->callees) {
		ShPtr<CG::CalledFuncs> succ(cg->getCalledFuncs(callee));
		CalledFuncInfo &succInfo(calledFuncInfoMap[succ]);
		if (succInfo.index < 0) { // '< 0' means 'undefined'
			// The successor has not yet been visited; recurse on it.
			visit(succ, succInfo);
			calledFuncInfo.lowlink = std::min(calledFuncInfo.lowlink,
				succInfo.lowlink);
		} else if (succInfo.onStack) {
			// The successor is on the stack and hence in the current SCC.
			calledFuncInfo.lowlink = std::min(calledFuncInfo.lowlink,
				succInfo.index);
		}
	}

	// If calledFunc is a root node, pop the stack and generate an SCC.
	if (calledFuncInfo.lowlink == calledFuncInfo.index) {
		// Generate a new SCC.
		FuncSet scc;
		ShPtr<CG::CalledFuncs> poppedCalledFunc;
		do {
			poppedCalledFunc = stack.top();
			stack.pop();
			calledFuncInfoMap[cg->getCalledFuncs(
				poppedCalledFunc->caller)].onStack = false;

			scc.insert(poppedCalledFunc->caller);
		} while (calledFunc != poppedCalledFunc);

		// Store the generated SCC. However, if the SCC contains just a single
		// function, do this only if it calls itself (see the description of
		// computeSCCs()).
		if (scc.size() != 1 || hasItem(calledFunc->callees, calledFunc->caller)) {
			sccs.insert(scc);
		}
	}
}
Exemplo n.º 27
0
	void ConfigService::runCommand ( const std::string &command, const std::string &args )
	{
		if ( command == SETVALUE )
		{
			Tokeniser tokeniser;
			tokeniser.initTokens ( args );
			std::string section ( tokeniser.nextToken() );
			std::string key ( tokeniser.nextToken() );
			std::string value ( tokeniser.remainingTokens() );

			if ( section == "" || key == "" || value == "" )
			{
				ConsoleBackend::getSingleton().pushMessage ( "Usage: set_value <section> <key> <value>", "help" );
			}
			else
			{
				setValue ( section, key, value );
				ConsoleBackend::getSingleton().pushMessage ( "New value set, section: " +  section + " key: " + key + " value: " + value, "info" );
			}

		}
		else if ( command == GETVALUE )
		{
			Tokeniser tokeniser;
			tokeniser.initTokens ( args );
			std::string section ( tokeniser.nextToken() );
			std::string key ( tokeniser.nextToken() );

			if ( section == "" || key == "" )
			{
				ConsoleBackend::getSingleton().pushMessage ( "Usage: get_value <section> <key>", "help" );
			}
			else
			{
				if ( !hasItem ( section, key ) )
				{
					ConsoleBackend::getSingleton().pushMessage ( "No such value.", "error" );
				}
				else
				{
					varconf::Variable value = getValue ( section, key );
					ConsoleBackend::getSingleton().pushMessage ( std::string ( "Value: " ) + static_cast<std::string> ( value ), "info" );
				}
			}
		}
	}
Exemplo n.º 28
0
void Inventory::addItem(uint16 var, bool atEnd) {
	// Only add objects once to the inventory
	if (!hasItem(var)) {
		_vm->_state->setVar(var, 1);

		InventoryItem i;
		i.var = var;

		if (atEnd) {
			_inventory.push_back(i);
		} else {
			_inventory.push_front(i);
		}

		reflow();
		updateState();
	}
}
Exemplo n.º 29
0
	bool Inventory::addItem(Item *item, int x, int y)
	{
		if (item == NULL)
		{
			return false;
		}
		if (hasItem(item))
		{
			return true;
		}
		if (hasSpaceFor(item, x, y))
		{
			placeItem(item, x, y);

			return true;
		}
		return false;
	}
Exemplo n.º 30
0
	const std::string& ConfigService::getSharedDataDirectory() const
	{
		if ( hasItem ( "paths", "sharedir" ) )
		{
			static std::string path ( static_cast<std::string> ( getValue ( "paths", "sharedir" ) ) + "/" );
			return path;
		}
		else
		{
#ifdef __APPLE__
			static std::string path ( getBundleResourceDirPath() );
			return path;
#else
			return mSharedDataDir;
#endif
		}

	}