summaryrefslogtreecommitdiff
path: root/tvision/include/tv/opstream.h
blob: d6847ee6d53a2e4594fe979578b311edbb97525c (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 *      Turbo Vision - Version 2.0
 *
 *      Copyright (c) 1994 by Borland International
 *      All Rights Reserved.
 *

Modified by Robert H”hne to be used for RHIDE.
Modified to compile with gcc v3.x by Salvador E. Tropea, with the help of
Andris Pavenis and Christoph Bauer.

 *
 *
 */

/* ------------------------------------------------------------------------*/
/*                                                                         */
/*   class opstream                                                        */
/*                                                                         */
/*   Base class for writing streamable objects                             */
/*                                                                         */
/* ------------------------------------------------------------------------*/

#if defined( Uses_opstream ) && !defined( __opstream )
#define __opstream

class TStreamableClass;
class TPWrittenObjects;

class CLY_EXPORT opstream : virtual public pstream
{
public:
    opstream( CLY_streambuf * );
    ~opstream();

    CLY_StreamPosT tellp();
    opstream& seekp( CLY_StreamPosT );
    opstream& seekp( CLY_StreamOffT, CLY_IOSSeekDir );
    opstream& flush();

    void writeByte( uchar );
    void writeBytes( const void *, size_t );
    void writeWord( ushort val ) { writeShort(val); };
    void writeString( const char * );
    /* Platform dependent: */
    void writeShort(ushort val);
    void writeInt(uint val);
    void writeLong(ulong val);
    /* The following are platform independent (stores in little endian) */
    void write8(uint8 val) { writeByte(val); };
    void write16(uint16 val);
    void write32(uint32 val);
    void write64(uint64 val);

    opstream& operator << ( char           val ) { writeByte(val); return *this; };
    #ifndef TVComp_BCPP
    opstream& operator << ( signed char    val ) { writeByte(val); return *this; };
    #endif
    opstream& operator << ( unsigned char  val ) { writeByte(val); return *this; };
    opstream& operator << ( signed short   val ) { writeShort(val); return *this; };
    opstream& operator << ( unsigned short val ) { writeShort(val); return *this; };
    opstream& operator << ( signed int     val ) { writeInt(val); return *this; };
    opstream& operator << ( unsigned int   val ) { writeInt(val); return *this; };
    opstream& operator << ( signed long    val ) { writeLong(val); return *this; };
    opstream& operator << ( unsigned long  val ) { writeLong(val); return *this; };
    opstream& operator << ( float          val ) { writeBytes(&val,sizeof(val)); return *this; };
    opstream& operator << ( double         val ) { writeBytes(&val,sizeof(val)); return *this; };
    opstream& operator << ( long double    val ) { writeBytes(&val,sizeof(val)); return *this; };

    friend opstream& operator << ( opstream&, TStreamable& );
    friend opstream& operator << ( opstream&, TStreamable * );

protected:
    opstream();

    void writePrefix( const TStreamable& );
    void writeData( TStreamable& );
    void writeSuffix( const TStreamable& );

    P_id_type find( const void *adr );
    void registerObject( const void *adr );

private:
    TPWrittenObjects *objs;
};

#endif  // Uses_opstream