Changeset 1430

Show
Ignore:
Timestamp:
07/07/05 12:30:45 (4 years ago)
Author:
madcat
Message:

Safer Tag::dump() method [tnx to cyberz for pointing this out]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • hydranode/modules/ed2k/tag.cpp

    r1428 r1430  
    152152 
    153153std::string Tag::dump(bool data) const { 
     154        using Utils::hexDump; 
     155        using boost::any_cast; 
     156 
    154157        boost::format fmt("type=%1% %2%=%3% valueType=%4% value=%5%"); 
    155         using Utils::hexDump; 
     158 
    156159        fmt % hexDump(m_valueType) % (m_opcode ? "opcode" : "name"); 
    157160        fmt % (m_opcode ? hexDump(m_opcode) : m_name) % hexDump(m_valueType); 
     
    160163                        case TT_UINT8: 
    161164                        case TT_UINT16: 
    162                         case TT_UINT32: 
    163                                 fmt % getInt(); 
     165                        case TT_UINT32:  
     166                                try { 
     167                                        fmt % any_cast<uint32_t>(m_value); 
     168                                } catch (boost::bad_any_cast&) { 
     169                                        fmt % "<unknown value>"; 
     170                                } 
    164171                                break; 
    165172                        case TT_FLOAT: 
    166                                 fmt % getFloat(); 
     173                                try { 
     174                                        fmt % any_cast<float>(m_value); 
     175                                } catch (boost::bad_any_cast&) { 
     176                                        fmt % "<unknown value>"; 
     177                                } 
    167178                                break; 
    168179                        case TT_STRING: 
    169                                 fmt % Utils::hexDump(getStr()); 
     180                                try { 
     181                                        fmt % hexDump( 
     182                                                any_cast<std::string>(m_value) 
     183                                        ); 
     184                                } catch (...) { 
     185                                        fmt % "<unknown value>"; 
     186                                } 
    170187                                break; 
    171188                        default: