summaryrefslogtreecommitdiffstats
path: root/kdvi/bigEndianByteReader.h
blob: 269d97d1e7db21a2213ac4d51504e3af778313bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// -*- C++ -*-
/* This file is part of KDVI (C) 2001 by Stefan Kebekus (kebekus@kde.org)

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public License
   as published by the Free Software Foundation; either version 2 of
   the License, or (at your option) any later version.
*/

/**
 * Byte reading routines which read big endian numbers from memory and
 * convert them to native integers.
 *
 * @author Stefan Kebekus (kebekus@kde.org)
 *
 **/

#ifndef _bigEndianByteReader_H
#define _bigEndianByteReader_H

#include <tqglobal.h>

class bigEndianByteReader {
 public:
  /** Set this pointer to the location where the number resides which
      you want to read. */
  TQ_UINT8      * command_pointer;

  /** This pointer marks the end of the memory area where bytes can be
      read. It should point to the first byte which CANNOT be
      read. The idea is to have a safety net which protects us against
      SEGFAULTs. This is also used in virtual fonts, where the macro
      does not have an EOP command at the end of the macro. */
  TQ_UINT8      * end_pointer;

  /** If command_pointer >= end_pointer, this method return EOP (=140)
      and exists. Otherwise, the method returns the unsigned byte
      and increases the command_pointer by one. */
  TQ_UINT8        readUINT8();

  /** Similar to the method above, only that the method reads a big
      endian 2-byte word and increases the pointer by two. */
  TQ_UINT16       readUINT16();

  /** Similar to the method above, only that the method reads a big
      endian 4-byte word and increases the pointer by four. */
  TQ_UINT32       readUINT32();

  void writeUINT32(TQ_UINT32 a);

  /** Similar to the method above, only that the method reads a big
      endian number of length size, where 1 <= size <= 4. Note that
      the value 3 is allowed (and is acually used in DVI files)!!!  */
  TQ_UINT32       readUINT(TQ_UINT8 size);

  /** Similar to the method above, only that the method reads a SIGNED
      number */
  TQ_INT32        readINT(TQ_UINT8);

};

#endif //ifndef _bigEndianByteReader_H