Panda3D
 All Classes Functions Variables Enumerations
iffId.cxx
1 // Filename: iffId.cxx
2 // Created by: drose (23Apr01)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "iffId.h"
16 
17 #include <ctype.h>
18 
19 ////////////////////////////////////////////////////////////////////
20 // Function: IffId::output
21 // Access: Public
22 // Description:
23 ////////////////////////////////////////////////////////////////////
24 void IffId::
25 output(ostream &out) const {
26  // If all of the characters are printable, just output them.
27  if (isprint(_id._c[0]) && isprint(_id._c[1]) &&
28  isprint(_id._c[2]) && isprint(_id._c[3])) {
29  out << _id._c[0] << _id._c[1] << _id._c[2] << _id._c[3];
30 
31  } else if (isprint(_id._c[0]) && isprint(_id._c[1]) &&
32  isprint(_id._c[2]) && _id._c[3] == '\0') {
33  // If the last character is 0, output a 3-letter ID.
34  out << _id._c[0] << _id._c[1] << _id._c[2];
35 
36  } else {
37  // Otherwise, write out the hex.
38  out << "0x" << hex << setfill('0');
39  for (int i = 0; i < 4; i++) {
40  out << setw(2) << (int)(unsigned char)_id._c[i];
41  }
42  out << dec << setfill(' ');
43  }
44 }