Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

pandatool/src/flt/fltBeadID.cxx

Go to the documentation of this file.
00001 // Filename: fltBeadID.cxx
00002 // Created by:  drose (24Aug00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "fltBeadID.h"
00020 #include "fltRecordReader.h"
00021 #include "fltRecordWriter.h"
00022 
00023 TypeHandle FltBeadID::_type_handle;
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //     Function: FltBeadID::Constructor
00027 //       Access: Public
00028 //  Description:
00029 ////////////////////////////////////////////////////////////////////
00030 FltBeadID::
00031 FltBeadID(FltHeader *header) : FltBead(header) {
00032 }
00033 
00034 ////////////////////////////////////////////////////////////////////
00035 //     Function: FltBeadID::get_id
00036 //       Access: Public
00037 //  Description: Returns the id (name) of this particular bead.  Each
00038 //               MultiGen bead will have a unique name.
00039 ////////////////////////////////////////////////////////////////////
00040 const string &FltBeadID::
00041 get_id() const {
00042   return _id;
00043 }
00044 
00045 ////////////////////////////////////////////////////////////////////
00046 //     Function: FltBeadID::set_id
00047 //       Access: Public
00048 //  Description: Changes the id (name) of this particular bead.  This
00049 //               should be a name that is unique to this bead.
00050 ////////////////////////////////////////////////////////////////////
00051 void FltBeadID::
00052 set_id(const string &id) {
00053   _id = id;
00054 }
00055 
00056 ////////////////////////////////////////////////////////////////////
00057 //     Function: FltBeadID::output
00058 //       Access: Public
00059 //  Description: Writes a quick one-line description of the record, but
00060 //               not its children.  This is a human-readable
00061 //               description, primarily for debugging; to write a flt
00062 //               file, use FltHeader::write_flt().
00063 ////////////////////////////////////////////////////////////////////
00064 void FltBeadID::
00065 output(ostream &out) const {
00066   out << get_type();
00067   if (!_id.empty()) {
00068     out << " " << _id;
00069   }
00070 }
00071 
00072 ////////////////////////////////////////////////////////////////////
00073 //     Function: FltBeadID::extract_record
00074 //       Access: Protected, Virtual
00075 //  Description: Fills in the information in this bead based on the
00076 //               information given in the indicated datagram, whose
00077 //               opcode has already been read.  Returns true on
00078 //               success, false if the datagram is invalid.
00079 ////////////////////////////////////////////////////////////////////
00080 bool FltBeadID::
00081 extract_record(FltRecordReader &reader) {
00082   if (!FltBead::extract_record(reader)) {
00083     return false;
00084   }
00085 
00086   _id = reader.get_iterator().get_fixed_string(8);
00087   return true;
00088 }
00089 
00090 ////////////////////////////////////////////////////////////////////
00091 //     Function: FltBeadID::extract_ancillary
00092 //       Access: Protected, Virtual
00093 //  Description: Checks whether the given bead, which follows this
00094 //               bead sequentially in the file, is an ancillary record
00095 //               of this bead.  If it is, extracts the relevant
00096 //               information and returns true; otherwise, leaves it
00097 //               alone and returns false.
00098 ////////////////////////////////////////////////////////////////////
00099 bool FltBeadID::
00100 extract_ancillary(FltRecordReader &reader) {
00101   if (reader.get_opcode() == FO_long_id) {
00102     string s = reader.get_iterator().get_remaining_bytes();
00103     size_t zero_byte = s.find('\0');
00104     _id = s.substr(0, zero_byte);
00105     return true;
00106   }
00107 
00108   return FltBead::extract_ancillary(reader);
00109 }
00110 
00111 ////////////////////////////////////////////////////////////////////
00112 //     Function: FltBeadID::build_record
00113 //       Access: Protected, Virtual
00114 //  Description: Fills up the current record on the FltRecordWriter with
00115 //               data for this record, but does not advance the
00116 //               writer.  Returns true on success, false if there is
00117 //               some error.
00118 ////////////////////////////////////////////////////////////////////
00119 bool FltBeadID::
00120 build_record(FltRecordWriter &writer) const {
00121   if (!FltBead::build_record(writer)) {
00122     return false;
00123   }
00124 
00125   writer.update_datagram().add_fixed_string(_id.substr(0, 7), 8);
00126   return true;
00127 }
00128 
00129 ////////////////////////////////////////////////////////////////////
00130 //     Function: FltBeadID::write_ancillary
00131 //       Access: Protected, Virtual
00132 //  Description: Writes whatever ancillary records are required for
00133 //               this record.  Returns FE_ok on success, or something
00134 //               else if there is some error.
00135 ////////////////////////////////////////////////////////////////////
00136 FltError FltBeadID::
00137 write_ancillary(FltRecordWriter &writer) const {
00138   if (_id.length() > 7) {
00139 
00140     // Although the manual mentions nothing of this, it is essential
00141     // that the length of the record be a multiple of 4 bytes.
00142     string id = _id;
00143     while ((id.length() % 4) != 0) {
00144       id += '\0';
00145     }
00146     Datagram dc(id);
00147 
00148     FltError result = writer.write_record(FO_long_id, dc);
00149     if (result != FE_ok) {
00150       return result;
00151     }
00152   }
00153 
00154   return FltBead::write_ancillary(writer);
00155 }

Generated on Fri May 2 03:19:03 2003 for Panda-Tool by doxygen1.3