Panda3D
fltRecordReader.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file fltRecordReader.h
10  * @author drose
11  * @date 2000-08-24
12  */
13 
14 #ifndef FLTRECORDREADER_H
15 #define FLTRECORDREADER_H
16 
17 #include "pandatoolbase.h"
18 
19 #include "fltOpcode.h"
20 #include "fltError.h"
21 
22 #include "datagram.h"
23 #include "datagramIterator.h"
24 
25 /**
26  * This class turns an istream into a sequence of FltRecords by reading a
27  * sequence of Datagrams and extracting the opcode from each one. It
28  * remembers where it is in the file and what the current record is.
29  */
31 public:
32  FltRecordReader(std::istream &in);
33  ~FltRecordReader();
34 
35  FltOpcode get_opcode() const;
37  const Datagram &get_datagram();
38  int get_record_length() const;
39 
40  FltError advance(bool ok_eof = false);
41 
42  bool eof() const;
43  bool error() const;
44 
45 private:
46  void read_next_header();
47 
48  std::istream &_in;
49  Datagram _datagram;
50  FltOpcode _opcode;
51  int _record_length;
52  DatagramIterator *_iterator;
53 
54  FltError _next_error;
55  FltOpcode _next_opcode;
56  int _next_record_length;
57 
58  enum State {
59  S_begin,
60  S_normal,
61  S_eof,
62  S_error
63  };
64  State _state;
65 };
66 
67 #endif
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:38
This class turns an istream into a sequence of FltRecords by reading a sequence of Datagrams and extr...
FltOpcode get_opcode() const
Returns the opcode associated with the current record.
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.
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.
FltError advance(bool ok_eof=false)
Extracts the next record from the file.
const Datagram & get_datagram()
Returns the datagram representing the entire record, less the four-byte header.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.