Panda3D

lwoSurfaceBlockHeader.cxx

00001 // Filename: lwoSurfaceBlockHeader.cxx
00002 // Created by:  drose (24Apr01)
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 "lwoSurfaceBlockHeader.h"
00016 #include "lwoInputFile.h"
00017 #include "lwoSurfaceBlockChannel.h"
00018 #include "lwoSurfaceBlockEnabled.h"
00019 #include "lwoSurfaceBlockOpacity.h"
00020 #include "lwoSurfaceBlockAxis.h"
00021 
00022 #include "dcast.h"
00023 #include "indent.h"
00024 
00025 TypeHandle LwoSurfaceBlockHeader::_type_handle;
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //     Function: LwoSurfaceBlockHeader::read_iff
00029 //       Access: Public, Virtual
00030 //  Description: Reads the data of the chunk in from the given input
00031 //               file, if possible.  The ID and length of the chunk
00032 //               have already been read.  stop_at is the byte position
00033 //               of the file to stop at (based on the current position
00034 //               at in->get_bytes_read()).  Returns true on success,
00035 //               false otherwise.
00036 ////////////////////////////////////////////////////////////////////
00037 bool LwoSurfaceBlockHeader::
00038 read_iff(IffInputFile *in, size_t stop_at) {
00039   LwoInputFile *lin = DCAST(LwoInputFile, in);
00040 
00041   _ordinal = lin->get_string();
00042   read_subchunks_iff(lin, stop_at);
00043 
00044   return true;
00045 }
00046 
00047 ////////////////////////////////////////////////////////////////////
00048 //     Function: LwoSurfaceBlockHeader::write
00049 //       Access: Public, Virtual
00050 //  Description:
00051 ////////////////////////////////////////////////////////////////////
00052 void LwoSurfaceBlockHeader::
00053 write(ostream &out, int indent_level) const {
00054   indent(out, indent_level)
00055     << get_id() << " {\n";
00056   indent(out, indent_level + 2)
00057     << "ordinal = 0x" << hex << setfill('0');
00058 
00059   string::const_iterator si;
00060   for (si = _ordinal.begin(); si != _ordinal.end(); ++si) {
00061     out << setw(2) << (int)(unsigned char)(*si);
00062   }
00063 
00064   out << dec << setfill(' ') << "\n";
00065 
00066   write_chunks(out, indent_level + 2);
00067   indent(out, indent_level)
00068     << "}\n";
00069 }
00070 
00071 ////////////////////////////////////////////////////////////////////
00072 //     Function: LwoSurfaceBlockHeader::make_new_chunk
00073 //       Access: Protected, Virtual
00074 //  Description: Allocates and returns a new chunk of the appropriate
00075 //               type based on the given ID, according to the context
00076 //               given by this chunk itself.
00077 ////////////////////////////////////////////////////////////////////
00078 IffChunk *LwoSurfaceBlockHeader::
00079 make_new_chunk(IffInputFile *in, IffId id) {
00080   if (id == IffId("CHAN")) {
00081     return new LwoSurfaceBlockChannel;
00082 
00083   } else if (id == IffId("ENAB")) {
00084     return new LwoSurfaceBlockEnabled;
00085 
00086   } else if (id == IffId("OPAC")) {
00087     return new LwoSurfaceBlockOpacity;
00088 
00089   } else if (id == IffId("AXIS")) {
00090     return new LwoSurfaceBlockAxis;
00091 
00092   } else {
00093     return IffChunk::make_new_chunk(in, id);
00094   }
00095 }
00096 
 All Classes Functions Variables Enumerations