Ejemplo n.º 1
0
struct Node * getParentNode(struct Node* root, int key)
{
    if (root == NULL) return NULL;
    
    struct Node* current = root;
    if (current->key == key) return NULL;
    if (key < current->key) 
    { 
        if (key == current->left->key) 
        {
            return current;
        } else {
            current = current->left;
            return getParentNode(current,key);
        }
    } else {
        if (key == current->right->key) 
        {
            return current;
        } else {
            current = current->right;
            return getParentNode(current,key);
        }
    }
}
Ejemplo n.º 2
0
DOM_Node TreeWalkerImpl::nextNode () {
	
	DOM_Node result;

    if (fCurrentNode.isNull()) return result;

    result = getFirstChild(fCurrentNode);

    if (! result.isNull()) {
        fCurrentNode = result;
        return result;
    }

    result = getNextSibling(fCurrentNode);

    if (! result.isNull()) {
        fCurrentNode = result;
        return result;
    }

    // return parent's 1st sibling.
    DOM_Node parent = getParentNode(fCurrentNode);
    while (! parent.isNull()) {
        result = getNextSibling(parent);
        if (! result.isNull()) {
            fCurrentNode = result;
            return result;
        } else {
            parent = getParentNode(parent);
        }
    }

    // end , return null
    return result;
}
Ejemplo n.º 3
0
DOMNode* DOMTreeWalkerImpl::nextNode () {
	
    if (!fCurrentNode) return 0;

    DOMNode* node = getFirstChild(fCurrentNode);

    if (node != 0) {
        fCurrentNode = node;
        return node;
    }
    else {

        node = getNextSibling(fCurrentNode);

        if (node != 0) {
            fCurrentNode = node;
            return node;
        }
        else {

            // return parent's 1st sibling.
            DOMNode* parent = getParentNode(fCurrentNode);
            while ( parent != 0) {
                node = getNextSibling(parent);
                if (node != 0) {
                    fCurrentNode = node;
                    return node;
                } else {
                    parent = getParentNode(parent);
                }
            }
            return node;
        }
    }
}
Ejemplo n.º 4
0
DOMNode* DOMTreeWalkerImpl::previousNode () {
	
    if (!fCurrentNode) return 0;

    // get sibling
    DOMNode* node = getPreviousSibling(fCurrentNode);
    if (node == 0) {
        node = getParentNode(fCurrentNode);
        if ( node != 0) {
            fCurrentNode = node;
        }
        return node;
    }
    else {

        // get the lastChild of result.
        DOMNode* lastChild  = getLastChild(node);

        // if there is a lastChild which passes filters return it.
        if (lastChild != 0) {
            fCurrentNode = lastChild;
        }
        else {
            fCurrentNode = node;
        }
        return fCurrentNode;
    }
}
Ejemplo n.º 5
0
DOM_Node TreeWalkerImpl::previousNode () {
	
    DOM_Node result;

    if (fCurrentNode.isNull()) return result;

    // get sibling
    result = getPreviousSibling(fCurrentNode);
    if (result.isNull()) {
        result = getParentNode(fCurrentNode);
        if (! result.isNull()) {
            fCurrentNode = result;
            return fCurrentNode;
        }
        return result;
    }

    // get the lastChild of result.
    DOM_Node lastChild  = getLastChild(result);

    // if there is a lastChild which passes filters return it.
    if (! lastChild.isNull()) {
        fCurrentNode = lastChild;
        return fCurrentNode;
    }

    // otherwise return the previous sibling.
    if (! result.isNull()) {
        fCurrentNode = result;
        return fCurrentNode;
    }

    // otherwise return null.
    return result;
}
Ejemplo n.º 6
0
bool EmulatePrecision::visitAggregate(Visit visit, TIntermAggregate *node)
{
    if (visit != PreVisit)
        return true;
    switch (node->getOp())
    {
        case EOpCallInternalRawFunction:
        case EOpCallFunctionInAST:
            // User-defined function return values are not rounded. The calculations that produced
            // the value inside the function definition should have been rounded.
            break;
        case EOpConstruct:
            if (node->getBasicType() == EbtStruct)
            {
                break;
            }
        default:
            TIntermNode *parent = getParentNode();
            if (canRoundFloat(node->getType()) && ParentUsesResult(parent, node) &&
                !ParentConstructorTakesCareOfRounding(parent, node))
            {
                TIntermNode *replacement = createRoundingFunctionCallNode(node);
                queueReplacement(replacement, OriginalNode::BECOMES_CHILD);
            }
            break;
    }
    return true;
}
Ejemplo n.º 7
0
/**
 * Release this node and resources associated with it, and also its children.
 */ 
void NCDElementImpl::release()
{
	if (NULL != getParentNode())
	{
		throw new NCDException(NCDException::INVALID_ACCESS_ERR);
	}

	try
	{
		// release children
		while (hasChildNodes())
		{
			NCDNode* childNode = getFirstChild();
			removeChild(childNode);
			childNode->release();
		}
		
		// dispose this node.
		static_cast<NCDDocumentImpl*>(document)->disposeNode(this);
	}
	catch (NCDException* ex)
	{
		ASSERT(FALSE);
	
		// ignore
		ex->Delete();
	}
}
Ejemplo n.º 8
0
bool EmulatePrecision::visitUnary(Visit visit, TIntermUnary *node)
{
    switch (node->getOp())
    {
      case EOpNegative:
      case EOpVectorLogicalNot:
      case EOpLogicalNot:
        break;
      case EOpPostIncrement:
      case EOpPostDecrement:
      case EOpPreIncrement:
      case EOpPreDecrement:
        if (visit == PreVisit)
            mInLValue = true;
        else if (visit == PostVisit)
            mInLValue = false;
        break;
      default:
        if (canRoundFloat(node->getType()) && visit == PreVisit)
        {
            TIntermNode *parent = getParentNode();
            TIntermNode *replacement = createRoundingFunctionCallNode(node);
            mReplacements.push_back(NodeUpdateEntry(parent, node, replacement, true));
        }
        break;
    }

    return true;
}
Ejemplo n.º 9
0
//
//  splitText.   revist - factor into a common function for use
//                             here and in DOMTextImpl
//
DOMText *DOMCDATASectionImpl::splitText(XMLSize_t offset)
{
    if (fNode.isReadOnly())
    {
        throw DOMException(DOMException::NO_MODIFICATION_ALLOWED_ERR, 0, GetDOMNodeMemoryManager);
    }
    XMLSize_t len = fCharacterData.fDataBuf->getLen();
    if (offset > len)
        throw DOMException(DOMException::INDEX_SIZE_ERR, 0, GetDOMNodeMemoryManager);

    DOMText *newText =
                getOwnerDocument()->createCDATASection(
                        this->substringData(offset, len - offset));

    DOMNode *parent = getParentNode();
    if (parent != 0)
        parent->insertBefore(newText, getNextSibling());

    fCharacterData.fDataBuf->chop(offset);

    if (this->getOwnerDocument() != 0) {
        Ranges* ranges = ((DOMDocumentImpl *)this->getOwnerDocument())->getRanges();
        if (ranges != 0) {
            XMLSize_t sz = ranges->size();
            if (sz != 0) {
                for (XMLSize_t i =0; i<sz; i++) {
                    ranges->elementAt(i)->updateSplitInfo( this, newText, offset);
                }
            }
        }
    }

    return newText;
}
	//-----------------------------------------------------------------------
	void VortexExtern::_preProcessParticles(ParticleTechnique* particleTechnique, Real timeElapsed)
	{
		if (isAttached())
		{
			position = getParentNode()->_getDerivedPosition();
			mDerivedPosition = position;
		}
	}
Ejemplo n.º 11
0
bool Node::isAncestorNode(Node *node) 
{
	for (Node *parentNode = getParentNode(); parentNode; parentNode = parentNode->getParentNode()) {
		if (node == parentNode)
				return true;
	}
	return false;
}
void
ColladaGeometry::ColladaGeometryInstInfo::process(void)
{
    Node *geoInstN = dynamic_cast<Node *>(
        getColInst()->getTargetElem()->createInstance(this));

    getParentNode()->addChild(geoInstN);
}
Ejemplo n.º 13
0
bool ThemeParser::parserCallback_widget(ParserNode *node) {
	Common::String var;

	if (getParentNode(node)->name == "globals") {

		if (resolutionCheck(node->values["resolution"]) == false) {
			node->ignore = true;
			return true;
		}

		var = "Globals." + node->values["name"] + ".";
		if (!parseCommonLayoutProps(node, var))
			return parserError("Error parsing Layout properties of '%s'.", var.c_str());

	} else {
		// FIXME: Shouldn't we distinguish the name/id and the label of a widget?
		var = node->values["name"];
		int width = -1;
		int height = -1;
		bool enabled = true;

		if (node->values.contains("enabled")) {
			if (node->values["enabled"] == "false")
				enabled = false;
			else if (node->values["enabled"] != "true")
				return parserError("Invalid value for Widget enabling (expecting true/false)");
		}

		if (node->values.contains("width")) {
			if (_theme->getEvaluator()->hasVar(node->values["width"]) == true)
				width = _theme->getEvaluator()->getVar(node->values["width"]);

			else if (!parseIntegerKey(node->values["width"].c_str(), 1, &width))
				return parserError("Corrupted width value in key for %s", var.c_str());
		}

		if (node->values.contains("height")) {
			if (_theme->getEvaluator()->hasVar(node->values["height"]) == true)
				height = _theme->getEvaluator()->getVar(node->values["height"]);

			else if (!parseIntegerKey(node->values["height"].c_str(), 1, &height))
				return parserError("Corrupted height value in key for %s", var.c_str());
		}

		Graphics::TextAlign alignH = Graphics::kTextAlignLeft;

		if (node->values.contains("textalign")) {
			if((alignH = parseTextHAlign(node->values["textalign"])) == Graphics::kTextAlignInvalid)
				return parserError("Invalid value for text alignment.");
		}

		_theme->getEvaluator()->addWidget(var, width, height, node->values["type"], enabled, alignH);
	}

	return true;
}
Ejemplo n.º 14
0
/**-------------------------------------------------------------------------------
    update

    @brief
    @return void
---------------------------------------------------------------------------------*/
void SensorDecoratorVector::update()
{
	mSensor->update();

	if (getDataValid())
	{
		std::vector<Ogre::Vector3> out;
		getValue(out);
		Ogre::Vector3 pos(out[0].x, out[0].y, out[0].z);
		Ogre::Vector3 force(out[1].x, out[1].y, out[1].z);

		getParentNode()->setPosition(pos);
		setVisible(true);

		Ogre::Vector3 posA(0, 0, 0);
		Ogre::Vector3 posB = force  / force.length() * 5;

		Ogre::Vector3 t0 = posB - posA;
		NxVec3 tan1, tan2;
		NxVec3 v3 = NxOgre::NxConvert<NxVec3, Ogre::Vector3>(t0);
		NxNormalToTangents(v3, tan1, tan2);

		t0.normalise();
		Ogre::Vector3 t1 = NxOgre::NxConvert<Ogre::Vector3, NxVec3>(tan1);
		Ogre::Vector3 t2 = NxOgre::NxConvert<Ogre::Vector3, NxVec3>(tan2);

		Ogre::Vector3 lobe1  = posB - t0 * ARROW_H + t1 * ARROW_H;
		Ogre::Vector3 lobe2  = posB - t0 * ARROW_H - t1 * ARROW_H;
		Ogre::Vector3 lobe3  = posB - t0 * ARROW_H + t2 * ARROW_H;
		Ogre::Vector3 lobe4  = posB - t0 * ARROW_H - t2 * ARROW_H;

		beginUpdate(0);
		position(posA);
		position(posB);
		position(posB);
		position(lobe1);
		position(posB);
		position(lobe2);
		position(posB);
		position(lobe3);
		position(posB);
		position(lobe4);
		end();
	}
	else
	{
		setVisible(false);
	}

	// if drawing is not persistent remove it after one draw
	if (getVisible() && !mPersistent && getDataValid())
	{
		setDataValid(false);
	}

}
Ejemplo n.º 15
0
void BuddyListNode::update()
{
  // cache the last_activity time
  last_activity = purple_blist_node_get_int(blist_node, "last_activity");

  BuddyListNode *parent_node = getParentNode();
  // the parent could have changed, so re-parent the node
  if (parent_node)
    treeview->setNodeParent(ref, parent_node->getRefNode());
}
Ejemplo n.º 16
0
bool Node::isInlineChildNode() 
{
	Node *parentNode = getParentNode();
	while (parentNode != NULL) {
		if (parentNode->isInlineNode() == true)
			return true;
		parentNode = parentNode->getParentNode();
	}
	return false;
}
//-----------------------------------------------------------------------
void SphereColliderExtern::_preProcessParticles(ParticleTechnique* particleTechnique, Real timeElapsed)
{
    if (isAttached())
    {
        // Use the position of the parent node in this case.
        position = getParentNode()->_getDerivedPosition();
        mDerivedPosition = position;
        mSphere.setCenter(mDerivedPosition);
    }
}
Ejemplo n.º 18
0
void EmulatePrecision::visitSymbol(TIntermSymbol *node)
{
    if (canRoundFloat(node->getType()) &&
        !mDeclaringVariables && !mInLValue && !mInFunctionCallOutParameter)
    {
        TIntermNode *parent = getParentNode();
        TIntermNode *replacement = createRoundingFunctionCallNode(node);
        mReplacements.push_back(NodeUpdateEntry(parent, node, replacement, true));
    }
}
void
TerrainTileEditable::_notifyHeightModified(int xstart, int zstart, int xend, int zend)
{
	assert(0 <= xstart && xstart < xend && xend <= mXSize+1);
	assert(0 <= zstart && zstart < zend && zend <= mZSize+1);

    if (mVertexDatas.empty())
    {
        // Nothing todo when buffer never initialised
        return;
    }

	// TODO: (optimization) some grid may be need to recompute normal only

	TerrainData* data = mOwner->getData();
	Ogre::HardwareVertexBufferSharedPtr posNormBuffer = mVertexDatas.front()->vertexBufferBinding->getBuffer(0);
	float* pPosNormBuffer = static_cast<float*>(posNormBuffer->lock(Ogre::HardwareBuffer::HBL_NORMAL));
    float buffer[6];
	int xsize = mXSize;
    int zsize = mZSize;
	int xbase = mXBase;
	int zbase = mZBase;
	for (int z = zstart; z < zend; ++z)
	{
		for (int x = xstart; x < xend; ++x)
		{
			Ogre::Vector3 v;
            v = data->_getPosition(x+xbase, z+zbase);
            buffer[0] = v.x; buffer[1] = v.y; buffer[2] = v.z;
			v = data->_getNormal(x+xbase, z+zbase);
            buffer[3] = v.x; buffer[4] = v.y; buffer[5] = v.z;
            if (0 < z)
            {
                if (0 < x)
                    memcpy(pPosNormBuffer + (((z-1) * xsize + (x-1)) * 4 + 3) * 6, buffer, 6*sizeof(float));
                if (x < xsize)
                    memcpy(pPosNormBuffer + (((z-1) * xsize + (x-0)) * 4 + 2) * 6, buffer, 6*sizeof(float));
            }
            if (z < zsize)
            {
                if (0 < x)
                    memcpy(pPosNormBuffer + (((z-0) * xsize + (x-1)) * 4 + 1) * 6, buffer, 6*sizeof(float));
                if (x < xsize)
                    memcpy(pPosNormBuffer + (((z-0) * xsize + (x-0)) * 4 + 0) * 6, buffer, 6*sizeof(float));
            }
		}
	}
	posNormBuffer->unlock();

	// re-compue bounding box
	data->_computeTileBoundingBox(mBounds, xbase, zbase, xsize, zsize);

    // trigger update of bounding box
    getParentNode()->needUpdate();
}
Ejemplo n.º 20
0
bool XMLParser::parseActiveKey(bool closed) {
	bool ignore = false;
	assert(_activeKey.empty() == false);

	ParserNode *key = _activeKey.top();

	if (key->name == "xml" && key->header == true) {
		assert(closed);
		return parseXMLHeader(key) && closeKey();
	}

	XMLKeyLayout *layout = (_activeKey.size() == 1) ? _XMLkeys : getParentNode(key)->layout;

	if (layout->children.contains(key->name)) {
		key->layout = layout->children[key->name];

		Common::StringMap localMap = key->values;
		int keyCount = localMap.size();

		for (Common::List<XMLKeyLayout::XMLKeyProperty>::const_iterator i = key->layout->properties.begin(); i != key->layout->properties.end(); ++i) {
			if (i->required && !localMap.contains(i->name))
				return parserError("Missing required property '%s' inside key '%s'", i->name.c_str(), key->name.c_str());
			else if (localMap.contains(i->name))
				keyCount--;
		}

		if (keyCount > 0)
			return parserError("Unhandled property inside key '%s'.", key->name.c_str());

	} else {
		return parserError("Unexpected key in the active scope ('%s').", key->name.c_str());
	}

	// check if any of the parents must be ignored.
	// if a parent is ignored, all children are too.
	for (int i = _activeKey.size() - 1; i >= 0; --i) {
		if (_activeKey[i]->ignore)
			ignore = true;
	}

	if (ignore == false && keyCallback(key) == false) {
		// HACK:  People may be stupid and overlook the fact that
		// when keyCallback() fails, a parserError() must be set.
		// We set it manually in that case.
		if (_state != kParserError)
			parserError("Unhandled exception when parsing '%s' key.", key->name.c_str());

		return false;
	}

	if (closed)
		return closeKey();

	return true;
}
Ejemplo n.º 21
0
/** Return the parent Node from the current node,
 *  after applying filter, whatToshow.
 *  If result is not null, set the current Node.
 */
DOMNode* DOMTreeWalkerImpl::parentNode () {

    if (!fCurrentNode) return 0;

    DOMNode* node = getParentNode(fCurrentNode);
    if (node != 0) {
        fCurrentNode = node;
    }
    return node;

}
Ejemplo n.º 22
0
	//-------------------------------------------------------------------------
	void Sound::_notifyMoved()
	{
		MovableObject::_notifyMoved();
		SoundSystem::getSingleton().updateBstCenter(this);
		if(mSoundPlayInfo && !mSoundPlayInfo->playContext.isNull()
			&& m3D)
		{
			mSoundPlayInfo->playContext->setPosition(
				getParentNode()->_getDerivedPosition());
		}		
	}
	//-----------------------------------------------------------------------
	void BoxColliderExtern::_preProcessParticles(ParticleTechnique* particleTechnique, Real timeElapsed)
	{
		if (isAttached())
		{
			// Use the position of the parent node in this case.
			position = getParentNode()->_getDerivedPosition();
			mDerivedPosition = position;
			populateAlignedBox(mBox, mDerivedPosition, mWidth, mHeight, mDepth);
			_calculateBounds();
		}
	}
Ejemplo n.º 24
0
void EmulatePrecision::visitSymbol(TIntermSymbol *node)
{
    TIntermNode *parent = getParentNode();
    if (canRoundFloat(node->getType()) && ParentUsesResult(parent, node) &&
        !ParentConstructorTakesCareOfRounding(parent, node) && !mDeclaringVariables &&
        !isLValueRequiredHere())
    {
        TIntermNode *replacement = createRoundingFunctionCallNode(node);
        queueReplacement(replacement, OriginalNode::BECOMES_CHILD);
    }
}
Ejemplo n.º 25
0
/** Return the parent Node from the current node,
 *  after applying filter, whatToshow.
 *  If result is not null, set the current Node.
 */
DOM_Node TreeWalkerImpl::parentNode () {

	DOM_Node result;

    if (fCurrentNode.isNull()) return result;

    DOM_Node node = getParentNode(fCurrentNode);
    if (node != 0) {
        fCurrentNode = node;
    }
    return node;

}
Ejemplo n.º 26
0
DOMNode* DOMElementImpl::rename(const XMLCh* namespaceURI, const XMLCh* name)
{
    DOMDocumentImpl* doc = (DOMDocumentImpl*) fParent.fOwnerDocument;

    if (!namespaceURI || !*namespaceURI) {
        fName = doc->getPooledString(name);
        fAttributes->reconcileDefaultAttributes(getDefaultAttributes());

        // and fire user data NODE_RENAMED event
        castToNodeImpl(this)->callUserDataHandlers(DOMUserDataHandler::NODE_RENAMED, this, this);

        return this;
    }
    else {

        // create a new ElementNS
        DOMElementNSImpl* newElem = (DOMElementNSImpl*)doc->createElementNS(namespaceURI, name);

        // transfer the userData
        doc->transferUserData(castToNodeImpl(this), castToNodeImpl(newElem));

        // remove old node from parent if any
        DOMNode* parent = getParentNode();
        DOMNode* nextSib = getNextSibling();
        if (parent) {
            parent->removeChild(this);
        }

        // move children to new node
        DOMNode* child = getFirstChild();
        while (child) {
            removeChild(child);
            newElem->appendChild(child);
            child = getFirstChild();
        }

        // insert new node where old one was
        if (parent) {
            parent->insertBefore(newElem, nextSib);
        }

        // move specified attributes to new node
        newElem->fAttributes->moveSpecifiedAttributes(fAttributes);

        // and fire user data NODE_RENAMED event
        castToNodeImpl(newElem)->callUserDataHandlers(DOMUserDataHandler::NODE_RENAMED, this, newElem);

        return newElem;
    }
}
Ejemplo n.º 27
0
long PANEElement::getLeftOffset(){
	PANEElement * const parent = dynamic_cast< PANEElement * >( getParentNode() );
	if( NULL == parent ) return 0;

	PANEElement * const prevSibling = dynamic_cast< PANEElement * >( getPreviousSibling() );
	if( NULL == prevSibling )
		return parent->getLeftOffset();

	const unsigned long availableWidth = getAvailableWidth();
	if( availableWidth  < getActualWidth( availableWidth ) )
		return parent->getLeftOffset();

	return prevSibling->getRightOffset();
}
Ejemplo n.º 28
0
DOMNode* DOMTreeWalkerImpl::getParentNode (DOMNode* node) {
	
    if (!node || node == fRoot) return 0;

    DOMNode* newNode = node->getParentNode();
    if (!newNode)  return 0;

    short accept = acceptNode(newNode);

    if (accept == DOMNodeFilter::FILTER_ACCEPT)
        return newNode;

    return getParentNode(newNode);

}
Ejemplo n.º 29
0
    void 
    IntersectGrid::fillPosition( const PositionArray &posArray )
    {
        size_t posCount = posArray.size();

        if ( posCount <= 0 )
            return;

    //    if ( posCount > mCurrentVertexCount )
    //   {   
            // 如果缓冲区不够用了,就扩容一倍
        //    mCurrentVertexCount = posCount<<1;
            // 如果不每帧创建缓冲区的话,由于lock时用的是discard,所以上次缓冲区中的内容还是会被显示
            mCurrentVertexCount = posCount;
            _createBuffer();
     //   }

        Ogre::Vector3 vmax = posArray[posCount-1];
        Ogre::Vector3 vmin = posArray[0];

        vmin.y -= 100.0f;
        vmax.y += 100.0f;

        Real sqLen = std::max(vmax.squaredLength(), vmin.squaredLength());
        mRadius = Ogre::Math::Sqrt(sqLen);//

        mBox.setExtents(vmin,vmax);//

        getParentNode()->needUpdate();//

        float *vertexPos = static_cast<float*>(vbuf->lock(Ogre::HardwareBuffer::HBL_DISCARD));

        for (size_t i = 0; i < posCount; ++i)
        {
            *vertexPos++ = posArray[i].x;
            *vertexPos++ = posArray[i].y+1;
            *vertexPos++ = posArray[i].z;

            Ogre::RGBA *pCol;
            pCol = static_cast<Ogre::RGBA*>(static_cast<void*>(vertexPos));
            // 用diffuse来做为alpha来源
            Ogre::Root::getSingleton().convertColourValue(mGridsColour, pCol++ ) ;

            vertexPos = static_cast<float*>(static_cast<void*>(pCol));
        }

        vbuf->unlock();     
    }
Ejemplo n.º 30
0
std::string &uSQL::SQLSet::toString(std::string &buf) 
{
  std::ostringstream oss;
  
  oss << name;

  SQLNode *parentNode = getParentNode();
  oss << ((isUnQLNode() && (parentNode->isColumnsNode() || parentNode->isValuesNode())) ? ":" : " = ");

  std::string valueString;
  oss << SQLExpression::toString(valueString);
  
  buf = oss.str();
  
  return buf;
}