Panda3D
fltRecordReader.h
1 // Filename: fltRecordReader.h
2 // Created by: drose (24Aug00)
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 #ifndef FLTRECORDREADER_H
16 #define FLTRECORDREADER_H
17 
18 #include "pandatoolbase.h"
19 
20 #include "fltOpcode.h"
21 #include "fltError.h"
22 
23 #include "datagram.h"
24 #include "datagramIterator.h"
25 
26 ////////////////////////////////////////////////////////////////////
27 // Class : FltRecordReader
28 // Description : This class turns an istream into a sequence of
29 // FltRecords by reading a sequence of Datagrams and
30 // extracting the opcode from each one. It remembers
31 // where it is in the file and what the current record
32 // is.
33 ////////////////////////////////////////////////////////////////////
35 public:
36  FltRecordReader(istream &in);
37  ~FltRecordReader();
38 
39  FltOpcode get_opcode() const;
41  const Datagram &get_datagram();
42  int get_record_length() const;
43 
44  FltError advance(bool ok_eof = false);
45 
46  bool eof() const;
47  bool error() const;
48 
49 private:
50  void read_next_header();
51 
52  istream &_in;
53  Datagram _datagram;
54  FltOpcode _opcode;
55  int _record_length;
56  DatagramIterator *_iterator;
57 
58  FltError _next_error;
59  FltOpcode _next_opcode;
60  int _next_record_length;
61 
62  enum State {
63  S_begin,
64  S_normal,
65  S_eof,
66  S_error
67  };
68  State _state;
69 };
70 
71 #endif
72 
73 
This class turns an istream into a sequence of FltRecords by reading a sequence of Datagrams and extr...
bool error() const
Returns true if some error has been encountered while reading (for instance, a truncated file)...
DatagramIterator & get_iterator()
Returns an iterator suitable for extracting data from the current record.
const Datagram & get_datagram()
Returns the datagram representing the entire record, less the four-byte header.
FltOpcode get_opcode() const
Returns the opcode associated with the current record.
A class to retrieve the individual data elements previously stored in a Datagram. ...
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
FltError advance(bool ok_eof=false)
Extracts the next record from the file.
bool eof() const
Returns true if end-of-file has been reached without error.
int get_record_length() const
Returns the entire length of the record, including the four-byte header.