Пример #1
0
bool PyDumpVisitor::VisitList( const PyList* rep )
{
    if( rep->empty() )
        _print( "%sList: Empty", _pfx() );
    else
    {
        _print( "%sList: %lu elements", _pfx(), rep->size() );

        PyList::const_iterator cur, _end;
        cur = rep->begin();
        _end = rep->end();
        for( uint32 i = 0; cur != _end; cur++, i++ )
        {
            if( i > 200 && !fullNested() )
            {
                _print( "%s  ... truncated ...", _pfx() );
                break;
            }

            _pfxExtend( "  [%2u] ", i );
            bool res = (*cur)->visit( *this );
            _pfxWithdraw();

            if( !res )
                return false;
        }
    }
    return true;
}
Пример #2
0
bool PyDumpVisitor::VisitPackedRow( const PyPackedRow* rep )
{
    _print( "%sPacked Row:", _pfx() );
    _print( "%s column_count=%u", _pfx(), rep->header()->ColumnCount() );

    PyPackedRow::const_iterator cur, end;
    cur = rep->begin();
    end = rep->end();
    for( uint32 i = 0; cur != end; cur++, i++ )
    {
        _pfxExtend( "  [%2u] %s: ", i, rep->header()->GetColumnName( i )->content().c_str() );

        bool res = true;
        if( (*cur) == NULL )
            _print( "%s(None)", _pfx() );
        else
            res = (*cur)->visit( *this );

        _pfxWithdraw();

        if( !res )
            return false;
    }

    return true;
}
Пример #3
0
bool PyDumpVisitor::VisitString( const PyString *rep )
{
    if( IsPrintable( rep ) )
        _print( "%sString: '%s'", _pfx(), rep->content().c_str() );
    else
        _print( "%sString: '<binary, len=%lu>'", _pfx(), rep->content().length() );

    return true;
}
Пример #4
0
bool PyDumpVisitor::VisitBuffer( const PyBuffer* rep )
{
    _print( "%sBuffer of length %lu:", _pfx(), rep->content().size() );

    _pfxExtend( "  " );
    _dump( _pfx(), &rep->content()[ 0 ], rep->content().size() );
    _pfxWithdraw();

    return true;
}
Пример #5
0
bool PyDumpVisitor::VisitWString( const PyWString* rep )
{
    // how to do it correctly?
    if( IsPrintable( rep ) )
        _print( "%sWString: '%s'", _pfx(), rep->content().c_str() );
    else
        _print( "%sWstring: '<binary, len=%lu>'", _pfx(), rep->content().length() );

    return true;
}
Пример #6
0
bool PyXMLGenerator::VisitObject( const PyObject* rep )
{
    fprintf( mInto, "%s<objectInline>\n", _pfx() );

    _pfxExtend( "    " );
    bool res = PyPfxVisitor::VisitObject( rep );
    _pfxWithdraw();

    fprintf( mInto, "%s</objectInline>\n", _pfx() );

    return res;
}
Пример #7
0
bool PyXMLGenerator::VisitSubStream( const PySubStream* rep )
{
    fprintf( mInto, "%s<substreamInline>\n", _pfx() );

    _pfxExtend( "    " );
    bool res = PyVisitor::VisitSubStream( rep );
    _pfxWithdraw();

    fprintf( mInto, "%s</substreamInline>\n", _pfx() );

    return res;
}
Пример #8
0
bool PyDumpVisitor::VisitSubStruct( const PySubStruct* rep )
{
    _print( "%sSubstruct:", _pfx() );

    _pfxExtend( "  " );
    bool res = PyVisitor::VisitSubStruct( rep );
    _pfxWithdraw();

    return res;
}
Пример #9
0
bool PyDumpVisitor::VisitChecksumedStream( const PyChecksumedStream* rep )
{
    _print( "%sStream With Checksum: 0x%08x", _pfx(), rep->checksum() );

    _pfxExtend( "  " );
    bool res = PyVisitor::VisitChecksumedStream( rep );
    _pfxWithdraw();

    return res;
}
Пример #10
0
bool PyDumpVisitor::VisitSubStream( const PySubStream* rep )
{
    _print( "%sSubstream: %s", _pfx(), ( rep->decoded() == NULL ) ? "from data" : "from rep" );

    _pfxExtend( "  " );
    bool res = PyVisitor::VisitSubStream( rep );
    _pfxWithdraw();

    return res;
}
Пример #11
0
bool PyLookupDumpVisitor::VisitString( const PyString* rep )
{
    if( !PyLogDumpVisitor::VisitString( rep ) )
        return false;

    const char* look = resolver()->LookupString( rep->content().c_str() );
    if( look != NULL )
        _print( "%s    %s", _pfx(), look );

    return true;
}
Пример #12
0
bool PyLookupDumpVisitor::VisitInteger( const PyInt* rep )
{
    if( !PyLogDumpVisitor::VisitInteger( rep ) )
        return false;

    const char* look = resolver()->LookupInt( rep->value() );
    if( look != NULL )
        _print( "%s    %s", _pfx(), look );

    return true;
}
Пример #13
0
bool PyXMLGenerator::VisitTuple( const PyTuple* rep )
{
    fprintf( mInto, "%s<tupleInline>\n", _pfx() );

    _pfxExtend( "    " );

    //! visits the tuple elements.
    PyTuple::const_iterator cur, end;
    cur = rep->begin();
    end = rep->end();
    for(uint32 i = 0; cur != end; ++cur, ++i)
    {
        fprintf( mInto, "%s<!-- %d -->\n", _pfx(), i );
        (*cur)->visit( *this );
    }

    _pfxWithdraw();

    fprintf( mInto, "%s</tupleInline>\n", _pfx() );

    return true;
}
Пример #14
0
bool PyDumpVisitor::VisitDict( const PyDict* rep )
{
    if( rep->empty() )
        _print( "%sDictionary: Empty", _pfx() );
    else
    {
        _print( "%sDictionary: %lu entries", _pfx(), rep->size() );

        PyDict::const_iterator cur, _end;
        cur = rep->begin();
        _end = rep->end();
        for( uint32 i = 0; cur != _end; cur++, i++ )
        {
            if( i > 200 && !fullNested() )
            {
                _print( "%s  ... truncated ...", _pfx() );
                break;
            }

            _pfxExtend( "  [%2u] Key: ", i );
            bool res = cur->first->visit( *this );
            _pfxWithdraw();

            if( !res )
                return false;

            _pfxExtend( "  [%2u] Value: ", i );
            res = cur->second->visit( *this );
            _pfxWithdraw();

            if( !res )
                return false;
        }
    }
    return true;
}
Пример #15
0
void PyPfxVisitor::_pfxExtend( const char* fmt, ... )
{
    va_list ap;
    va_start( ap, fmt );

    char* res;
    vasprintf( &res, fmt, ap );

    va_end( ap );

    std::string p( _pfx() );
    p += res;
    mPfxStack.push( p );

    SafeFree( res );
}
Пример #16
0
bool PyDumpVisitor::VisitObject( const PyObject* rep )
{
    _print( "%sObject:", _pfx() );

    _pfxExtend( "  Type: " );
    bool res = rep->type()->visit( *this );
    _pfxWithdraw();

    if( !res )
        return false;

    _pfxExtend( "  Args: " );
    res = rep->arguments()->visit( *this );
    _pfxWithdraw();

    if( !res )
        return false;

    return true;
}
Пример #17
0
bool PyXMLGenerator::VisitChecksumedStream( const PyChecksumedStream* rep )
{
    fprintf( mInto, "%s<!-- PyChecksumedStream stub -->\n", _pfx() );

    return true;
}
Пример #18
0
bool PyXMLGenerator::VisitString( const PyString* rep )
{
    fprintf( mInto, "%s<string name=\"string%u\" />\n", _pfx(), mItem++ );

    return true;
}
Пример #19
0
bool PyXMLGenerator::VisitPackedRow( const PyPackedRow* rep )
{
    fprintf( mInto, "%s<!-- PyPackedRow stub -->\n", _pfx() );

    return true;
}
Пример #20
0
bool PyXMLGenerator::VisitNone( const PyNone* rep )
{
    fprintf( mInto, "%s<none />\n", _pfx() );

    return true;
}
Пример #21
0
bool PyXMLGenerator::VisitBuffer( const PyBuffer* rep )
{
    fprintf( mInto, "%s<buffer name=\"buffer%u\" />\n", _pfx(), mItem++ );

    return true;
}
Пример #22
0
bool PyXMLGenerator::VisitReal( const PyFloat* rep )
{
    fprintf( mInto, "%s<real name=\"real%u\" />\n", _pfx(), mItem++ );

    return true;
}
Пример #23
0
bool PyXMLGenerator::VisitBoolean( const PyBool* rep )
{
    fprintf( mInto, "%s<bool name=\"bool%u\" />\n", _pfx(), mItem++ );

    return true;
}
Пример #24
0
bool PyXMLGenerator::VisitInteger( const PyInt* rep )
{
    fprintf( mInto, "%s<int name=\"integer%u\" />\n", _pfx(), mItem++ );

    return true;
}
Пример #25
0
bool PyDumpVisitor::VisitReal( const PyFloat* rep )
{
    _print( "%sReal field: %f", _pfx(), rep->value() );
    return true;
}
Пример #26
0
bool PyXMLGenerator::VisitList( const PyList* rep )
{
    //for now presume we cant do anything useful with lists that contain
    //more than a few things...
    if( rep->size() < 5 )
    {
        fprintf( mInto, "%s<listInline>\n", _pfx() );

        _pfxExtend( "    " );

        //! visit the list elements.
        PyList::const_iterator cur, end;
        cur = rep->begin();
        end = rep->end();
        for( uint32 i = 0; cur != end; ++cur, ++i )
        {
            fprintf( mInto, "%s<!-- %u -->\n", _pfx(), i );
            (*cur)->visit( *this );
        }

        _pfxWithdraw();

        fprintf( mInto, "%s</listInline>\n", _pfx() );
    }
    else
    {
        enum
        {
            TypeUnknown,
            TypeString,
            TypeInteger,
            TypeReal,
            TypeMixed
        } eletype;
        eletype = TypeUnknown;

        //scan the list to see if we can classify the contents.
        PyList::const_iterator cur, end;
        cur = rep->begin();
        end = rep->end();
        for(; cur != end; cur++)
        {
            if( (*cur)->IsString() )
            {
                if( eletype == TypeInteger || eletype == TypeReal )
                {
                    eletype = TypeMixed;
                    break;
                }
                else if( eletype == TypeUnknown )
                    eletype = TypeString;
            }
            else if( (*cur)->IsInt() )
            {
                if( eletype == TypeString || eletype == TypeReal )
                {
                    eletype = TypeMixed;
                    break;
                }
                else if( eletype == TypeUnknown )
                    eletype = TypeInteger;
            }
            else if( (*cur)->IsFloat() )
            {
                if( eletype == TypeString || eletype == TypeInteger )
                {
                    eletype = TypeMixed;
                    break;
                }
                else if( eletype == TypeUnknown )
                    eletype = TypeReal;
            }
            else
            {
                eletype = TypeMixed;
                break;
            }
        }

        switch( eletype )
        {
        case TypeString:
            fprintf( mInto, "%s<listStr name=\"list%u\" />\n", _pfx(), mItem++ );
            break;
        case TypeInteger:
            fprintf( mInto, "%s<listInt name=\"list%u\" />\n", _pfx(), mItem++ );
            break;
        case TypeReal:
            fprintf( mInto, "%s<listReal name=\"list%u\" />\n", _pfx(), mItem++ );
            break;
        case TypeUnknown:
        case TypeMixed:
            fprintf( mInto, "%s<list name=\"list%u\" />\n", _pfx(), mItem++ );
            break;
        }
    }

    return true;
}
Пример #27
0
bool PyXMLGenerator::VisitDict( const PyDict* rep )
{
    enum
    {
        DictInline,
        DictStringKey,
        DictIntKey,
        DictRaw
    } ktype;

    enum
    {
        ValueUnknown,
        ValueString,
        ValueInt,
        ValueReal,
        ValueMixed
    } vtype;

    ktype = DictInline;
    vtype = ValueUnknown;

    //this is kinda a hack, but we want to try and classify the contents of this dict:
    PyDict::const_iterator cur, end;
    cur = rep->begin();
    end = rep->end();
    for(; cur != end; ++cur)
    {
        if( cur->first->IsString() )
        {
            if( ktype == DictIntKey )
            {
                //we have varying key types, raw dict it is.
                ktype = DictRaw;
                break;
            }
            else if( ktype == DictInline )
                ktype = DictStringKey;
        }
        else if( cur->first->IsInt() )
        {
            if( ktype == DictStringKey )
            {
                //we have varying key types, raw dict it is.
                ktype = DictRaw;
                break;
            }
            else if( ktype == DictInline )
                ktype = DictIntKey;
        }
        else
        {
            //anything but those key types is more than we can think about, keep it raw.
            ktype = DictRaw;
            break;
        }

        if( cur->second->IsString() )
        {
            if( vtype == ValueInt || vtype == ValueReal )
                vtype = ValueMixed;
            else if( vtype == ValueUnknown )
                vtype = ValueString;
        }
        else if(cur->second->IsInt())
        {
            if( vtype == ValueString || vtype == ValueReal )
                vtype = ValueMixed;
            else if( vtype == ValueUnknown )
                vtype = ValueInt;
        }
        else if( cur->second->IsFloat() )
        {
            if( vtype == ValueString || vtype == ValueInt )
                vtype = ValueMixed;
            else if(vtype == ValueUnknown)
                vtype = ValueReal;
        }
        else
            vtype = ValueMixed;
    }

    if( ktype == DictRaw )
    {
        fprintf( mInto, "%s<dict name=\"dict%u\" />\n", _pfx(), mItem++ );
        return true;
    }
    else if( ktype == DictIntKey )
    {
        //cant do an inline dict, but can try a vector
        switch( vtype )
        {
        case ValueString:
            fprintf( mInto, "%s<dictInt name=\"dict%u\" type=\"string\" />\n", _pfx(), mItem++ );
            break;
        case ValueInt:
            fprintf( mInto, "%s<dictInt name=\"dict%u\" type=\"int\" />\n", _pfx(), mItem++ );
            break;
        case ValueReal:
            fprintf( mInto, "%s<dictInt name=\"dict%u\" type=\"real\" />\n", _pfx(), mItem++ );
            break;
        case ValueUnknown:
        case ValueMixed:
            fprintf( mInto, "%s<dictRaw name=\"dict%u\" />\n", _pfx(), mItem++ );
            break;
        }

        return true;
    }

    fprintf( mInto, "%s<dictInline>\n", _pfx() );

    _pfxExtend( "    " );

    //! visit dict elements.
    cur = rep->begin();
    end = rep->end();
    for(; cur != end; ++cur)
    {
        if( !cur->first->IsString() )
        {
            fprintf( mInto, "%s<!-- non-string dict key of type %s -->\n", _pfx(), cur->first->TypeString() );
            return false;
        }
        PyString* str = cur->first->AsString();

        fprintf( mInto, "%s<dictInlineEntry key=\"%s\">\n", _pfx(), str->content().c_str() );

        _pfxExtend( "    " );
        cur->second->visit( *this );
        _pfxWithdraw();

        fprintf( mInto, "%s</dictInlineEntry>\n", _pfx() );
    }

    _pfxWithdraw();

    fprintf( mInto, "%s</dictInline>\n", _pfx() );

    return true;
}
Пример #28
0
bool PyDumpVisitor::VisitBoolean( const PyBool* rep )
{
    _print( "%sBoolean field: %s", _pfx(), rep->value() ? "true" : "false" );
    return true;
}
Пример #29
0
bool PyDumpVisitor::VisitNone( const PyNone* rep )
{
    _print( "%s(None)", _pfx() );
    return true;
}
Пример #30
0
bool PyXMLGenerator::VisitObjectEx( const PyObjectEx* rep )
{
    fprintf( mInto, "%s<!-- PyObjectEx stub -->\n", _pfx() );

    return true;
}