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; }
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; }
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; }
bool PyDumpVisitor::VisitChecksumedStream( const PyChecksumedStream* rep ) { _print( "%sStream With Checksum: 0x%08x", _pfx(), rep->checksum() ); _pfxExtend( " " ); bool res = PyVisitor::VisitChecksumedStream( rep ); _pfxWithdraw(); return res; }
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; }
bool PyDumpVisitor::VisitSubStruct( const PySubStruct* rep ) { _print( "%sSubstruct:", _pfx() ); _pfxExtend( " " ); bool res = PyVisitor::VisitSubStruct( rep ); _pfxWithdraw(); return res; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
bool PyDumpVisitor::VisitObjectEx( const PyObjectEx* rep ) { _print( "%sObjectEx%s:", _pfx(), rep->isType2() ? " (Type2)" : "" ); _print( "%sHeader:", _pfx() ); if( rep->header() == NULL ) _print( "%s (None)", _pfx() ); else { _pfxExtend( " " ); bool res = rep->header()->visit( *this ); _pfxWithdraw(); if( !res ) return false; } _print( "%sList data:", _pfx() ); if( rep->list().empty() ) _print( "%s Empty", _pfx() ); else { PyObjectEx::const_list_iterator cur, end; cur = rep->list().begin(); end = rep->list().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; } } _print( "%sDict data:", _pfx() ); if( rep->dict().empty() ) _print( "%s Empty", _pfx() ); else { PyObjectEx::const_dict_iterator cur, end; cur = rep->dict().begin(); end = rep->dict().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; }