Ejemplo n.º 1
0
    indri::xml::XMLNode* Packer::_getNodeReference( class indri::lang::Node* node, const ::std::string& name ) {
      if( !node )
        return 0;

      indri::xml::XMLNode* reference = new indri::xml::XMLNode( name, node->nodeName() );

      if( _getElement(node)->flushed == false ) {
        node->pack(*this);
      }

      return reference;
    }
Ejemplo n.º 2
0
static void _getEigenVectors(Mat4* vout, Vec3* dout, Mat4 a)
{
    int n = 3;
    int j,iq,ip,i;
    double tresh, theta, tau, t, sm, s, h, g, c;
    int nrot;
    Vec3 b;
    Vec3 z;
    Mat4 v;
    Vec3 d;

    v = Mat4::IDENTITY;
    for(ip = 0; ip < n; ip++)
    {
        _getElement(b, ip) = a.m[ip + 4 * ip];
        _getElement(d, ip) = a.m[ip + 4 * ip];
        _getElement(z, ip) = 0.0;
    }

    nrot = 0;

    for(i = 0; i < 50; i++)
    {
        sm = 0.0;
        for(ip = 0; ip < n; ip++) for(iq = ip+1; iq < n; iq++) sm += fabs(a.m[ip + 4 * iq]);
        if( fabs(sm) < FLT_EPSILON )
        {
            v.transpose();
            *vout = v;
            *dout = d;
            return;
        }

        if (i < 3)
            tresh = 0.2 * sm / (n*n);
        else 
            tresh = 0.0;

        for(ip = 0; ip < n; ip++)
        {
            for(iq = ip + 1; iq < n; iq++)
            {
                g = 100.0 * fabs(a.m[ip + iq * 4]);
                float dmip = _getElement(d, ip);
                float dmiq = _getElement(d, iq);

                if( i>3 && fabs(dmip) + g == fabs(dmip) && fabs(dmiq) + g == fabs(dmiq) )
                {
                    a.m[ip + 4 * iq] = 0.0;
                }
                else if (fabs(a.m[ip + 4 * iq]) > tresh)
                {
                    h = dmiq - dmip;
                    if (fabs(h) + g == fabs(h))
                    {
                        t=(a.m[ip + 4 * iq])/h;
                    }
                    else
                    {
                        theta = 0.5 * h / (a.m[ip + 4 * iq]);
                        t=1.0 / (fabs(theta) + sqrt(1.0 + theta * theta));
                        if (theta < 0.0) t = -t;
                    }
                    c = 1.0 / sqrt(1+t*t);
                    s = t*c;
                    tau = s / (1.0+c);
                    h = t * a.m[ip + 4 * iq];
                    _getElement(z, ip) -= (float)h;
                    _getElement(z, iq) += (float)h;
                    _getElement(d, ip) -= (float)h;
                    _getElement(d, iq) += (float)h;
                    a.m[ip + 4 * iq]=0.0;
                    for(j = 0; j < ip; j++) { ROTATE(a,j,ip,j,iq); }
                    for(j = ip + 1; j < iq; j++) { ROTATE(a,ip,j,j,iq); }
                    for(j = iq + 1; j < n; j++) { ROTATE(a,ip,j,iq,j); }
                    for(j = 0; j < n; j++) { ROTATE(v,j,ip,j,iq); }
                    nrot++;
                }
            }
        }

        for(ip = 0; ip < n; ip++)
        {
            _getElement(b, ip) += _getElement(z, ip);
            _getElement(d, ip) = _getElement(b, ip);
            _getElement(z, ip) = 0.0f;
        }
    }

    v.transpose();
    *vout = v;
    *dout = d;
    return;
}
Ejemplo n.º 3
0
 void Packer::before( class indri::lang::Node* someNode ) {
   node_element* element = _getElement(someNode);
   _stack.push( element );
 }
Ejemplo n.º 4
0
 void Packer::pack( class indri::lang::Node* root ) {
   node_element* element = _getElement( root );
   element->xmlNode->addAttribute( "root", "true" );
   root->pack(*this);
 }
Ejemplo n.º 5
0
Boolean XmlParser::_next(
    XmlEntry& entry,
    Boolean includeComment)
{
    if (!_putBackStack.isEmpty())
    {
        entry = _putBackStack.top();
        _putBackStack.pop();
        return true;
    }

    // If a character was overwritten with a null-terminator the last
    // time this routine was called, then put back that character. Before
    // exiting of course, restore the null-terminator.

    char* nullTerminator = 0;

    if (_restoreChar && !*_current)
    {
        nullTerminator = _current;
        *_current = _restoreChar;
        _restoreChar = '\0';
    }

    entry.attributes.clear();

    if (_supportedNamespaces)
    {
        // Remove namespaces of a deeper scope level from the stack.
        while (!_nameSpaces.isEmpty() &&
               _nameSpaces.top().scopeLevel > _stack.size())
        {
            _nameSpaces.pop();
        }
    }

    // Loop until we are done with comments if includeComment is false.
    do
    {
        // Skip over any whitespace:
        _skipWhitespace(_line, _current);

        if (!*_current)
        {
            if (nullTerminator)
                *nullTerminator = '\0';

            if (!_stack.isEmpty())
                throw XmlException(XmlException::UNCLOSED_TAGS, _line);

            return false;
        }

        // Either a "<...>" or content begins next:

        if (*_current == '<')
        {
            _current++;
            _getElement(_current, entry);

            if (nullTerminator)
                *nullTerminator = '\0';

            if (entry.type == XmlEntry::START_TAG)
            {
                if (_stack.isEmpty() && _foundRoot)
                    throw XmlException(XmlException::MULTIPLE_ROOTS, _line);

                _foundRoot = true;
                _stack.push((char*)entry.text);
            }
            else if (entry.type == XmlEntry::END_TAG)
            {
                if (_stack.isEmpty())
                    throw XmlException(XmlException::START_END_MISMATCH, _line);

                if (strcmp(_stack.top(), entry.text) != 0)
                    throw XmlException(XmlException::START_END_MISMATCH, _line);

                _stack.pop();
            }
        }
        else
        {
            // Normalize the content:

            char* start = _current;
            Uint32 textLen;
            _normalizeElementValue(_line, _current, textLen);

            // Get the content:

            entry.type = XmlEntry::CONTENT;
            entry.text = start;
            entry.textLen = textLen;

            // Overwrite '<' with a null character (temporarily).

            _restoreChar = *_current;
            *_current = '\0';

            if (nullTerminator)
                *nullTerminator = '\0';
        }
    } while (!includeComment && entry.type == XmlEntry::COMMENT);

    if (_supportedNamespaces &&
        (entry.type == XmlEntry::START_TAG ||
         entry.type == XmlEntry::EMPTY_TAG ||
         entry.type == XmlEntry::END_TAG))
    {
        // Determine the namespace type for this entry

        if (entry.type == XmlEntry::START_TAG ||
            entry.type == XmlEntry::EMPTY_TAG)
        {
            // Process namespace declarations and determine the namespace type
            // for the attributes.

            Uint32 scopeLevel = _stack.size();
            if (entry.type == XmlEntry::EMPTY_TAG)
            {
                // Empty tags are deeper scope, but not pushed onto the stack
                scopeLevel++;
            }

            for (Uint32 i = 0, n = entry.attributes.size(); i < n; i++)
            {
                XmlAttribute& attr = entry.attributes[i];
                if ((strncmp(attr.name, "xmlns:", 6) == 0) ||
                    (strcmp(attr.name, "xmlns") == 0))
                {
                    // Process a namespace declaration
                    XmlNamespace ns;
                    if (attr.name[5] == ':')
                    {
                        ns.localName = attr.localName;
                    }
                    else
                    {
                        // Default name space has no local name
                        ns.localName = 0;
                    }
                    ns.extendedName = attr.value;
                    ns.scopeLevel = scopeLevel;
                    ns.type = _getSupportedNamespaceType(ns.extendedName);

                    // If the namespace is not supported, assign it a unique
                    // negative identifier.
                    if (ns.type == -1)
                    {
                        ns.type = _currentUnsupportedNSType--;
                    }

                    _nameSpaces.push(ns);
                }
                else
                {
                    // Get the namespace type for this attribute.
                    attr.nsType = _getNamespaceType(attr.name);
                }
            }
        }

        entry.nsType = _getNamespaceType(entry.text);
    }
    else
    {
        entry.nsType = -1;
    }

    return true;
}