Panda3D

bamFile.h

00001 // Filename: bamFile.h
00002 // Created by:  drose (02Jul00)
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 #ifndef BAMFILE_H
00016 #define BAMFILE_H
00017 
00018 #include "pandabase.h"
00019 #include "datagramInputFile.h"
00020 #include "datagramOutputFile.h"
00021 #include "pandaNode.h"
00022 #include "pointerTo.h"
00023 #include "bamEnums.h"
00024 
00025 class BamReader;
00026 class BamWriter;
00027 class TypedWritable;
00028 class Filename;
00029 
00030 ////////////////////////////////////////////////////////////////////
00031 //       Class : BamFile
00032 // Description : The principle public interface to reading and writing
00033 //               Bam disk files.  See also BamReader and BamWriter,
00034 //               the more general implementation of this class.
00035 //
00036 //               Bam files are most often used to store scene graphs
00037 //               or subgraphs, and by convention they are given
00038 //               filenames ending in the extension ".bam" when they
00039 //               are used for this purpose.  However, a Bam file may
00040 //               store any arbitrary list of TypedWritable objects;
00041 //               in this more general usage, they are given filenames
00042 //               ending in ".boo" to differentiate them from the more
00043 //               common scene graph files.
00044 ////////////////////////////////////////////////////////////////////
00045 class EXPCL_PANDA_PGRAPH BamFile : public BamEnums {
00046 PUBLISHED:
00047   BamFile();
00048   ~BamFile();
00049 
00050   bool open_read(const Filename &bam_filename, bool report_errors = true);
00051   bool open_read(istream &in, const string &bam_filename = "stream",
00052                  bool report_errors = true);
00053 
00054   TypedWritable *read_object();
00055 
00056   bool is_eof() const;
00057   bool resolve();
00058 
00059   PT(PandaNode) read_node(bool report_errors = true);
00060 
00061   bool open_write(const Filename &bam_filename, bool report_errors = true);
00062   bool open_write(ostream &out, const string &bam_filename = "stream",
00063                   bool report_errors = true);
00064   bool write_object(const TypedWritable *object);
00065 
00066   void close();
00067   INLINE bool is_valid_read() const;
00068   INLINE bool is_valid_write() const;
00069 
00070   int get_file_major_ver();
00071   int get_file_minor_ver();
00072   BamEndian get_file_endian() const;
00073   bool get_file_stdfloat_double() const;
00074 
00075   int get_current_major_ver();
00076   int get_current_minor_ver();
00077 
00078   BamReader *get_reader();
00079   BamWriter *get_writer();
00080 
00081 private:
00082   bool continue_open_read(const string &bam_filename, bool report_errors);
00083   bool continue_open_write(const string &bam_filename, bool report_errors);
00084 
00085   string _bam_filename;
00086   DatagramInputFile _din;
00087   DatagramOutputFile _dout;
00088   BamReader *_reader;
00089   BamWriter *_writer;
00090 };
00091 
00092 #include "bamFile.I"
00093 
00094 #endif
 All Classes Functions Variables Enumerations