00001 // Filename: iffId.cxx 00002 // Created by: drose (23Apr01) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "iffId.h" 00016 00017 #include <ctype.h> 00018 00019 //////////////////////////////////////////////////////////////////// 00020 // Function: IffId::output 00021 // Access: Public 00022 // Description: 00023 //////////////////////////////////////////////////////////////////// 00024 void IffId:: 00025 output(ostream &out) const { 00026 // If all of the characters are printable, just output them. 00027 if (isprint(_id._c[0]) && isprint(_id._c[1]) && 00028 isprint(_id._c[2]) && isprint(_id._c[3])) { 00029 out << _id._c[0] << _id._c[1] << _id._c[2] << _id._c[3]; 00030 00031 } else if (isprint(_id._c[0]) && isprint(_id._c[1]) && 00032 isprint(_id._c[2]) && _id._c[3] == '\0') { 00033 // If the last character is 0, output a 3-letter ID. 00034 out << _id._c[0] << _id._c[1] << _id._c[2]; 00035 00036 } else { 00037 // Otherwise, write out the hex. 00038 out << "0x" << hex << setfill('0'); 00039 for (int i = 0; i < 4; i++) { 00040 out << setw(2) << (int)(unsigned char)_id._c[i]; 00041 } 00042 out << dec << setfill(' '); 00043 } 00044 }