OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
objstrm.h
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1992, 1996 by Borland International, All Rights Reserved
4// Revision by Yura Bidus
5//
6//----------------------------------------------------------------------------
7
8#if !defined(OWL_OBJSTRM_H)
9#define OWL_OBJSTRM_H
10
11#include <owl/defs.h>
12#if defined(BI_HAS_PRAGMA_ONCE)
13# pragma once
14#endif
15
16#include <owl/streambl.h>
17
18
19#include <iostream>
20#include <fstream>
21
22#include <typeinfo>
23
24namespace owl {
25
26#include <owl/preclass.h>
27
28/// \addtogroup base
29/// @{
30
31/*------------------------------------------------------------------------*/
32/* */
33/* The __link() macro forces the compiler to link in a static instance */
34/* of class TStreamableClass, which in turn registers its associated */
35/* TStreamable object with the stream manager. Applications that do */
36/* not use streaming won't use __link(), and that will reduce the amount */
37/* of code that is linked into the application. */
38/* */
39/*------------------------------------------------------------------------*/
40
41/// \cond
42struct fLink
43{
44 struct fLink *f;
45 class TStreamableClass *t;
46};
47
48#define __link( s ) \
49 extern TStreamableClass s; \
50 static fLink force ## s = \
51 { (fLink *)&force ## s, (TStreamableClass *)&s };
52/// \endcond
53
54typedef unsigned P_id_type;
55
60
61
62
64
66 const tstring & str );
67
68/* -----------------------------------------------------------------------*/
69/* */
70/* _OBJ_TYPENAME(obj) provides a macro for getting the type name from a */
71/* pointer to an object. If runtime type information is available, this */
72/* macro uses the typeid of the object to get its name. If runtime type */
73/* information is not available, it uses the CastableID() for the object.*/
74/* */
75/* -----------------------------------------------------------------------*/
76
77
78#define _OBJ_FULLTYPENAME(obj) typeid(*obj).name()
79#if defined(BI_COMP_MSC) && !defined(UNIX) && !defined(__EDG__)
80# if defined(BI_COMPATIBLE_STREAMING)
81# define _OBJ_TYPENAME(obj) typeid(*obj).name() + 6
82# else
83# define _OBJ_TYPENAME(obj) typeid(*obj).raw_name()
84# endif
85#else
86# define _OBJ_TYPENAME(obj) typeid(*obj).name()
87#endif
88/* -----------------------------------------------------------------------*/
89/* */
90/*! \ class TStreamable */
91/* */
92/*! This is the base class from which all streamable objects must be */
93/*! derived. */
94/* */
95/* -----------------------------------------------------------------------*/
96
97
99
100/// Classes that inherit from TStreamableBase are known as streamable classes (their
101/// objects can be written to and read from streams). If you develop your own
102/// streamable classes, make sure that TStreamableBase is somewhere in their
103/// ancestry.
104///
105/// Using an existing streamable class as a base is the easiest way to create a
106/// streamable class. If your class must also fit into an existing class hierarchy,
107/// you can use multiple inheritance to derive a class from TStreamableBase .
109 public:
110 virtual ~TStreamableBase();
111
112};
113
114
116
118
119 protected:
120
121 virtual LPCSTR streamableName() const = 0;
122
123 virtual void * read( ipstream& ) = 0;
124 virtual void write( opstream& ) = 0;
125
126};
127
128//
129/// Provides a base class for all streamable objects.
131
132 friend class ipstream;
133 friend class opstream;
134
135 public:
136
137 virtual ~TStreamer() {}
138
139/// Returns the address of the TStreamableBase component of the streamable object.
140 TStreamableBase * GetObject() const { return object; }
141
142 protected:
143
144/// Constructs the TStreamer object, and initializes the streamable object pointer.
146
147/// This pure virtual member function must be redefined for every streamable class.
148/// It returns the name of the streamable class, which is used by the stream manager
149/// to register the streamable class. The name returned must be a zero-terminated
150/// string.
151 virtual LPCSTR StreamableName() const = 0;
152
153/// This pure virtual member function must be redefined for every streamable class.
154/// It must read the necessary data members for the streamable class from the
155/// supplied ipstream.
156 virtual void * Read( ipstream&, uint32 ) const = 0;
157
158/// This pure virtual function must be redefined for every streamable class. It must
159/// write the necessary streamable class data members to the supplied opstream
160/// object. Write is usually implemented by calling the Write member function (if
161/// available) of a base class, and then inserting any additional data members for
162/// the derived class.
163 virtual void Write( opstream& ) const = 0;
164
165 private:
166
167 virtual uint32 ClassVersion() const = 0;
168
169 TStreamableBase *object;
170
171};
172
173/// Provides a base class for all streamable objects.
175
176 public:
177
178/// Constructs the TOldStreamer object, and initializes the streamable object
179/// pointer.
181
182 protected:
183
184/// This pure virtual member function must be redefined for every streamable class.
185/// It returns the name of the streamable class, which is used by the stream manager
186/// to register the streamable class. The name returned must be a zero-terminated
187/// string.
188 virtual LPCSTR StreamableName() const
189 {
190 return STATIC_CAST(TStreamable *,GetObject())->streamableName();
191 }
192
193/// This pure virtual member function must be redefined for every streamable class.
194/// It must read the necessary data members for the streamable class from the
195/// supplied ipstream.
196 virtual void * Read( ipstream& is, uint32 ) const
197 {
198 return STATIC_CAST(TStreamable *,GetObject())->read( is );
199 }
200
201/// This pure virtual function must be redefined for every streamable class. It must
202/// write the necessary streamable class data members to the supplied opstream
203/// object. Write is usually implemented by calling the Write member function (if
204/// available) of a base class, and then inserting any additional data members for
205/// the derived class.
206 virtual void Write( opstream& os ) const
207 {
208 STATIC_CAST(TStreamable *,GetObject())->write( os );
209 }
210
211 private:
212
213 virtual uint32 ClassVersion() const
214 {
215 return 0;
216 }
217
218};
219
221
222 public:
223
224/// Constructs the TNewStreamer object, and initializes the streamable object
225/// pointer.
227
228 protected:
229
230 virtual LPCSTR StreamableName() const
231 {
232 const auto p = GetObject();
233 return _OBJ_TYPENAME(p);
234 }
235
236};
237
238
239/* ------------------------------------------------------------------------*/
240/* */
241/*! \class TPWrittenObjects */
242/* */
243/*! Maintains a database of all objects that have been written to the */
244/*! current persistent stream. */
245/* */
246/*! Used by opstream when it writes a pointer from a stream to save the */
247/*! address and ID of the object being written. */
248/* */
249/* ------------------------------------------------------------------------*/
250
251class TSortedTPWObjObjectArray;
252
254
255 friend class opstream;
256
257 public:
258
259 void RemoveAll();
260
262 public:
263
264 TPWObj() : Address(nullptr), Ident(0) {}
265 TPWObj( const void *adr, P_id_type id ) :
266 Address(adr), Ident(id) {}
267
268 bool operator == ( const TPWObj& o) const
269 { return reinterpret_cast<TAddrInt>(Address) == reinterpret_cast<TAddrInt>(o.Address); }
270
271 bool operator < ( const TPWObj& o ) const
272 { return reinterpret_cast<TAddrInt>(Address) < reinterpret_cast<TAddrInt>(o.Address); }
273
274 const void *Address;
276
277 private:
278
279 typedef UINT_PTR TAddrInt;
280 };
281
282 private:
283
286
287 void RegisterObject( TStreamableBase *adr );
288 void RegisterVB( const TStreamableBase *adr );
289 P_id_type FindObject( TStreamableBase *adr );
290 P_id_type FindVB( TStreamableBase *adr );
291
292 P_id_type CurId;
293 TSortedTPWObjObjectArray* Data;
294};
295
296
297/* ------------------------------------------------------------------------*/
298/* */
299/*! \class TPReadObjects */
300/* */
301/*! Maintains a database of all objects that have been read from the */
302/*! current persistent stream. */
303/* */
304/*! Used by ipstream when it reads a pointer from a stream to determine */
305/*! the address of the object being referred to. */
306/* */
307/* ------------------------------------------------------------------------*/
308
309class TStreamableBaseArray;
310
312 friend class ipstream;
313 public:
314
315 void RemoveAll();
316
317 private:
320
321 void RegisterObject( TStreamableBase *adr );
322 TStreamableBase * Find( P_id_type id );
323
324 TStreamableBaseArray* Data;
325};
326
327/// \class pstream
328/// Base class for handling streamable objects.
329
331 friend class TStreamableTypes;
332 friend class TStreamableClass;
333 public:
334
335/// Enumerates object pointer types.
336 enum PointerTypes { ptNull, ptIndexed, ptObject };
337
338 pstream( std::streambuf * );
339 virtual ~pstream();
340
341 int rdstate() const;
342 int eof() const;
343 int fail() const;
344 int bad() const;
345 int good() const;
346 void clear( int = 0 );
347 operator void *() const;
348 int operator ! () const;
349
350 std::streambuf * rdbuf() const;
351
352 protected:
353
354 pstream();
355
356 std::streambuf *bp;
357 int state;
358
359 void init( std::streambuf * );
360 void setstate( int );
361
362// static TStreamableTypes *types;
363};
364
365/* ------------------------------------------------------------------------*/
366/* */
367/*! \class ipstream */
368/* */
369/*! Base class for reading streamable objects */
370/* */
371/* ------------------------------------------------------------------------*/
372inline ipstream& operator >> ( ipstream&, int8& );
373inline ipstream& operator >> ( ipstream&, uint8& );
374inline ipstream& operator >> ( ipstream&, char& );
375inline ipstream& operator >> ( ipstream&, signed short& );
376inline ipstream& operator >> ( ipstream&, unsigned short& );
377inline ipstream& operator >> ( ipstream&, signed int& );
378inline ipstream& operator >> ( ipstream&, unsigned int& );
379inline ipstream& operator >> ( ipstream&, bool& );
380inline ipstream& operator >> ( ipstream&, signed long& );
381inline ipstream& operator >> ( ipstream&, unsigned long& );
382inline ipstream& operator >> ( ipstream&, int64& );
384inline ipstream& operator >> ( ipstream&, float& );
385inline ipstream& operator >> ( ipstream&, double&);
386inline ipstream& operator >> ( ipstream&, long double&);
387
388
389/// ipstream, a specialized input stream derivative of pstream, is the base class
390/// for reading (extracting) streamable objects.
391class _OWLCLASS ipstream : virtual public pstream {
392 friend class TStreamableClass;
393 public:
394
395 ipstream( std::streambuf * );
396
397 std::streampos tellg();
398 ipstream& seekg( std::streampos );
399 ipstream& seekg( std::streamoff, std::ios::seekdir );
400
401 uint8 readByte();
402 void readBytes( void *, size_t );
403 void freadBytes( void * data, size_t sz );
404
405 uint32 readWord();
406 uint16 readWord16();
407 uint32 readWord32();
408
409 LPSTR readString();
410 LPSTR readString( LPSTR , unsigned );
411 char * freadString();
412 char * freadString( char *buf,
413 unsigned maxLen );
414
415 friend ipstream& operator >> ( ipstream&, int8& );
416 friend ipstream& operator >> ( ipstream&, uint8& );
417 friend ipstream& operator >> ( ipstream&, char& );
418 friend ipstream& operator >> ( ipstream&, signed short& );
419 friend ipstream& operator >> ( ipstream&, unsigned short& );
420 friend ipstream& operator >> ( ipstream&, signed int& );
421 friend ipstream& operator >> ( ipstream&, unsigned int& );
422 friend ipstream& operator >> ( ipstream&, bool& );
423 friend ipstream& operator >> ( ipstream&, signed long& );
424 friend ipstream& operator >> ( ipstream&, unsigned long& );
425 friend ipstream& operator >> ( ipstream&, int64& );
426 friend ipstream& operator >> ( ipstream&, uint64& );
427 friend ipstream& operator >> ( ipstream&, float& );
428 friend ipstream& operator >> ( ipstream&, double& );
429 friend ipstream& operator >> ( ipstream&, long double& );
431
432 uint32 getVersion() const;
433
435 TStreamableBase * readObjectPointer( TStreamableBase *&mem, ModuleId mid = GetModuleId() );
436
437 TStreamableBase * find( P_id_type );
438 void registerObject( TStreamableBase *adr );
439
440 protected:
441
442 ipstream();
443
444 const ObjectBuilder * readPrefix( ModuleId mid );
445 void readData( const ObjectBuilder *,
446 TStreamableBase *& );
447 void readSuffix();
448
449 void readVersion();
450
451private:
452
453 uint32 readStringLength();
454 TPReadObjects objs;
455 uint32 version;
456};
457
458/// \class opstream
459/// Base class for writing streamable objects
460//
461/// opstream, a specialized derivative of pstream, is the base class for writing
462/// (inserting) streamable objects.
463
466inline opstream& operator << ( opstream&, char );
467inline opstream& operator << ( opstream&, signed short );
468inline opstream& operator << ( opstream&, unsigned short );
469inline opstream& operator << ( opstream&, signed int );
470inline opstream& operator << ( opstream&, unsigned int );
471inline opstream& operator << ( opstream&, bool );
472inline opstream& operator << ( opstream&, signed long );
473inline opstream& operator << ( opstream&, unsigned long );
476inline opstream& operator << ( opstream&, float );
477inline opstream& operator << ( opstream&, double );
478inline opstream& operator << ( opstream&, long double );
479
480class _OWLCLASS opstream : virtual public pstream {
481 public:
482
483 opstream( std::streambuf * );
484 virtual ~opstream();
485
486 std::streampos tellp();
487 opstream& seekp( std::streampos );
488 opstream& seekp( std::streamoff, std::ios::seekdir );
489 opstream& flush();
490
491 void writeByte( uint8 );
492 void writeBytes( const void *, size_t );
493 void fwriteBytes( const void *data, size_t sz );
494
495 void writeWord( uint32 );
496 void writeWord16( uint16 );
497 void writeWord32( uint32 );
498
499 void writeString( const char * );
500 void fwriteString( const char * str );
501
502 friend opstream& operator << ( opstream&, int8 );
503 friend opstream& operator << ( opstream&, uint8 );
504 friend opstream& operator << ( opstream&, char );
505 friend opstream& operator << ( opstream&, signed short );
506 friend opstream& operator << ( opstream&, unsigned short );
507 friend opstream& operator << ( opstream&, signed int );
508 friend opstream& operator << ( opstream&, unsigned int );
509 friend opstream& operator << ( opstream&, bool );
510 friend opstream& operator << ( opstream&, signed long );
511 friend opstream& operator << ( opstream&, unsigned long );
514 friend opstream& operator << ( opstream&, float );
515 friend opstream& operator << ( opstream&, double );
516 friend opstream& operator << ( opstream&, long double );
517
518 void writeObject( const TStreamableBase *t, int isPtr = 0, ModuleId mid = GetModuleId() );
519 void writeObjectPointer( const TStreamableBase *t, ModuleId mid = GetModuleId() );
520
521 P_id_type findObject( TStreamableBase *adr );
522 void registerObject( TStreamableBase *adr );
523
524 P_id_type findVB( TStreamableBase *adr );
525 void registerVB( TStreamableBase *adr );
526
527 protected:
528
529 opstream();
530
531 void writePrefix( const TStreamableBase * );
532 void writeData( const TStreamableBase *, ModuleId mid );
533 void writeSuffix( const TStreamableBase * );
534
535 void writeVersion();
536
537 private:
538
539 TPWrittenObjects* objs;
540};
541
542/// \class fpbase
543/// Base class for handling streamable objects on file streams
544//
545/// Provides the basic operations common to all object file stream I/O. It is a base
546/// class for handling streamable objects on file streams.
547
548class _OWLCLASS fpbase : virtual public pstream {
549 public:
550
551 enum { openprot = 0666 }; // default open mode
552 fpbase();
553 fpbase( LPCSTR, int, int = openprot );
554 fpbase( LPCWSTR, int, int = openprot );
555
556 void open( LPCSTR, int, int = openprot );
557 void open( LPCWSTR, int, int = openprot );
558
559 void close();
560 void setbuf( LPSTR, int );
561 std::filebuf * rdbuf();
562
563 private:
564
565 std::filebuf buf;
566};
567
568/// \class ifpstream
569/// Base class for reading streamable objects from file streams
570//
571/// ifpstream is a simple "mix" of its bases, fpbase and ipstream. It provides the
572/// base class reading (extracting) streamable objects from file streams.
573
574class _OWLCLASS ifpstream : public fpbase, public ipstream {
575 public:
576
577 ifpstream();
579 int = std::ios::in,
580 int = fpbase::openprot
581 );
583 int = std::ios::in,
584 int = fpbase::openprot
585 );
586
587 std::filebuf * rdbuf();
588
589 void open( LPCSTR ,
590 int = std::ios::in,
591 int = fpbase::openprot
592 );
593 void open( LPCWSTR ,
594 int = std::ios::in,
595 int = fpbase::openprot
596 );
597};
598
599/// \class ofpstream
600/// Base class for writing streamable objects to file streams
601//
602/// Provides the base class for writing (inserting) streamable objects to file
603/// streams.
604
605class _OWLCLASS ofpstream : public fpbase, public opstream {
606 public:
607
608 ofpstream();
610 int = std::ios::out,
611 int = fpbase::openprot
612 );
614 int = std::ios::out,
615 int = fpbase::openprot
616 );
617
618 std::filebuf * rdbuf();
619
620 void open( LPCSTR,
621 int = std::ios::out,
622 int = fpbase::openprot
623 );
624 void open( LPCWSTR,
625 int = std::ios::out,
626 int = fpbase::openprot
627 );
628};
629
630#include <owl/posclass.h>
631
632
633/* ------------------------------------------------------------------------*/
634/* */
635/* Inline functions */
636/* */
637/* ------------------------------------------------------------------------*/
638
639/// Creates a buffered pstream with the given buffer. The state is set to 0.
640inline pstream::pstream( std::streambuf *sb ){
641 init( sb );
642}
643
644/// Returns the current state value.
645inline int pstream::rdstate() const {
646 return state;
647}
648
649/// Returns nonzero on end of stream.
650inline int pstream::eof() const {
651 return state & std::ios::eofbit;
652}
653
654/// Returns nonzero if a previous stream operation failed.
655inline int pstream::fail() const {
656 return state & (std::ios::failbit | std::ios::badbit | std::ios::goodbit);
657}
658
659/// Returns nonzero if an error occurs.
660inline int pstream::bad() const {
661 return state & (std::ios::badbit | std::ios::goodbit);
662}
663
664/// Returns nonzero if no error states have been recorded for the stream (that is,
665/// no errors have occurred).
666inline int pstream::good() const {
667 return state == 0;
668}
669
670/// Sets the stream state to the given value (defaults to 0).
671inline void pstream::clear( int i ){
672 state = (i & 0xFF) | (state & std::ios::goodbit);
673}
674
675/// Converts to a void pointer.
676inline pstream::operator void *() const {
677 return fail() ? 0 : (void *)this;
678}
679
680/// Overloads the NOT operator. Returns 0 if the operation has failed (that is, if
681/// pstream::fail returned nonzero); otherwise, returns nonzero.
682inline int pstream::operator! () const {
683 return fail();
684}
685
686/// Returns the pb pointer to the buffer assigned to the stream.
687inline std::streambuf * pstream::rdbuf() const {
688 return bp;
689}
690
691/// Creates a pstream without initializing the buffer pointer bp or state.
692/// Use init to set the buffer and setstate to set the state.
694}
695
696/// The init member function initializes the stream and sets state to 0 and bp to
697/// sbp.
698inline void pstream::init( std::streambuf *sbp ){
699 state = 0;
700 bp = sbp;
701}
702
703/// Updates the state data member with state |= (b & 0xFF).
704inline void pstream::setstate( int b ){
705 state |= (b&0xFF);
706}
707
708/// Creates a buffered ipstream with the given buffer. The state is set to 0.
709inline ipstream::ipstream( std::streambuf *sb ){
710 pstream::init( sb );
711 readVersion();
712}
713
714/// Creates a buffered ipstream without initializing the buffer pointer, bp.
715/// Use psteam::init to set the buffer and state.
717 if( bp != 0 )
718 readVersion();
719}
720
721/// Returns a pointer to the object corresponding to Id.
723 return objs.Find( id );
724}
725
726/// Registers the object pointed to by adr.
728 objs.RegisterObject( adr );
729}
730
731/// Returns the object version number.
733 return version;
734}
736 delete objs;
737}
738
739/// Writes the 32-bit word us to the stream.
743
744/// Writes the class name suffix to the stream. The << operator uses this function
745/// to write a prefix and suffix around the data written with writeData. The
746/// prefix/suffix is used to ensure type-safe stream I/O.
748 writeByte( ']' );
749}
750
751/// Returns the type ID for the object pointed to by adr.
753 return objs->FindObject( adr );
754}
755
756/// Registers the class of the object pointed to by adr.
758 objs->RegisterObject( adr );
759}
760
761/// Returns a pointer to the virtual base.
763 return objs->FindVB( adr );
764}
765
766/// Registers a virtual base class.
768 objs->RegisterVB( adr );
769}
770
771/// Creates a buffered fpbase object.
773 pstream::init( &buf );
774}
775
776/// Creates a buffered fpbase object. It opens the file specified by name,
777/// using the mode omode and protection prot; and attaches this file to the stream.
778inline fpbase::fpbase( LPCSTR name, int omode, int prot ){
779 pstream::init( &buf );
780 open( name, omode, prot );
781}
782
783/// Creates a buffered fpbase object. It opens the file specified by name,
784/// using the mode omode and protection prot; and attaches this file to the stream.
786 pstream::init( &buf );
787 open( name, omode, prot );
788}
789
790/// Returns a pointer to the current file buffer.
791inline std::filebuf * fpbase::rdbuf(){
792 return &buf;
793}
794
795/// Creates a buffered ifpstream object using a default buffer.
797}
798
799/// Creates a buffered ifpstream object. It opens the file specified by name
800/// using the mode mode and protection prot; and attaches this file to the stream.
802:
803 fpbase( name, omode | std::ios::in | std::ios::binary, prot )
804{
805}
806
807/// Creates a buffered ifpstream object. It opens the file specified by name
808/// using the mode mode and protection prot; and attaches this file to the stream.
810:
811 fpbase( name, omode | std::ios::in | std::ios::binary, prot )
812{
813}
814
815/// Returns a pointer to the current file buffer.
816inline std::filebuf * ifpstream::rdbuf(){
817 return fpbase::rdbuf();
818}
819
820/// It opens the named file in the given mode (app, ate, in, out, binary, trunc,
821/// nocreate, or noreplace) and protection. The default mode for ifpstream is
822/// ios::in (input) with openprot protection. The opened file is attached to this
823/// stream.
825 int omode,
826 int prot )
827{
828 fpbase::open( name, omode | std::ios::in | std::ios::binary, prot );
829 readVersion();
830}
831
832/// It opens the named file in the given mode (app, ate, in, out, binary, trunc,
833/// nocreate, or noreplace) and protection. The default mode for ifpstream is
834/// ios::in (input) with openprot protection. The opened file is attached to this
835/// stream.
837 int omode,
838 int prot )
839{
840 fpbase::open( name, omode | std::ios::in | std::ios::binary, prot );
841 readVersion();
842}
843
844/// Creates a buffered ofpstream object using a default buffer.
846}
847
848/// Creates a buffered ofpstream object. It opens the file specified by
849/// name, using the mode mode, and protection prot; and attaches this file to the
850/// stream
852:
853 fpbase( name, omode | std::ios::out | std::ios::binary, prot )
854{
855}
856
857/// Creates a buffered ofpstream object. It opens the file specified by
858/// name, using the mode mode, and protection prot; and attaches this file to the
859/// stream
861:
862 fpbase( name, omode | std::ios::out | std::ios::binary, prot )
863{
864}
865
866inline std::filebuf * ofpstream::rdbuf(){
867 return fpbase::rdbuf();
868}
869
870/// Opens the named file in the given mode (app, ate, in, out, binary, trunc,
871/// nocreate, or noreplace) and protection. The default mode for ofpstream is
872/// ios::out (output) with openprot protection. The opened file is attached to this
873/// stream.
875 int omode,
876 int prot )
877{
878 fpbase::open( name, omode | std::ios::out | std::ios::binary, prot );
879 writeVersion();
880}
881
882/// Returns a pointer to the current file buffer.
884 int omode,
885 int prot )
886{
887 fpbase::open( name, omode | std::ios::out | std::ios::binary, prot );
888 writeVersion();
889}
890
891/// This friend operator of ipstream extracts (reads) from the ipstream ps, to the
892/// given argument. It returns a reference to the stream that lets you chain >>
893/// operations in the usual way.
894/// The data type of the argument determines how the read is performed. For example,
895/// reading a signed char is implemented using readByte.
897{
898 ch = ps.readByte();
899 return ps;
900}
901
902/// This friend operator of ipstream extracts (reads) from the ipstream ps, to the
903/// given argument. It returns a reference to the stream that lets you chain >>
904/// operations in the usual way.
905/// The data type of the argument determines how the read is performed. For example,
906/// reading a signed char is implemented using readByte.
908 ch = ps.readByte();
909 return ps;
910}
911
912/// This friend operator of ipstream extracts (reads) from the ipstream ps, to the
913/// given argument. It returns a reference to the stream that lets you chain >>
914/// operations in the usual way.
915/// The data type of the argument determines how the read is performed. For example,
916/// reading a signed char is implemented using readByte.
917inline ipstream& operator >> ( ipstream& ps, char &ch ){
918 ch = ps.readByte();
919 return ps;
920}
921
922/// This friend operator of ipstream extracts (reads) from the ipstream ps, to the
923/// given argument. It returns a reference to the stream that lets you chain >>
924/// operations in the usual way.
925/// The data type of the argument determines how the read is performed. For example,
926/// reading a signed char is implemented using readByte.
927inline ipstream& operator >> ( ipstream& ps, signed short &sh ){
928 sh = ps.readWord16();
929 return ps;
930}
931
932/// This friend operator of ipstream extracts (reads) from the ipstream ps, to the
933/// given argument. It returns a reference to the stream that lets you chain >>
934/// operations in the usual way.
935/// The data type of the argument determines how the read is performed. For example,
936/// reading a signed char is implemented using readByte.
937inline ipstream& operator >> ( ipstream& ps, unsigned short &sh ){
938 sh = ps.readWord16();
939 return ps;
940}
941
942/// This friend operator of ipstream extracts (reads) from the ipstream ps, to the
943/// given argument. It returns a reference to the stream that lets you chain >>
944/// operations in the usual way.
945/// The data type of the argument determines how the read is performed. For example,
946/// reading a signed char is implemented using readByte.
947inline ipstream& operator >> ( ipstream& ps, signed int &i ){
948 i = (int)(ps.readWord());
949 return ps;
950}
951
952/// This friend operator of ipstream extracts (reads) from the ipstream ps, to the
953/// given argument. It returns a reference to the stream that lets you chain >>
954/// operations in the usual way.
955/// The data type of the argument determines how the read is performed. For example,
956/// reading a signed char is implemented using readByte.
957inline ipstream& operator >> ( ipstream& ps, unsigned int &i ){
958 i = (unsigned int)(ps.readWord());
959 return ps;
960}
961
962/// This friend operator of ipstream extracts (reads) from the ipstream ps, to the
963/// given argument. It returns a reference to the stream that lets you chain >>
964/// operations in the usual way.
965/// The data type of the argument determines how the read is performed. For example,
966/// reading a signed char is implemented using readByte.
967inline ipstream& operator >> ( ipstream& ps, signed long &l ){
968 ps.readBytes( &l, sizeof(l) );
969 return ps;
970}
971
972/// This friend operator of ipstream extracts (reads) from the ipstream ps, to the
973/// given argument. It returns a reference to the stream that lets you chain >>
974/// operations in the usual way.
975/// The data type of the argument determines how the read is performed. For example,
976/// reading a signed char is implemented using readByte.
977inline ipstream& operator >> ( ipstream& ps, unsigned long &l ){
978 ps.readBytes( &l, sizeof(l) );
979 return ps;
980}
981
983{
984 ps.readBytes(&v, sizeof v);
985 return ps;
986}
987
989{
990 ps.readBytes(&v, sizeof v);
991 return ps;
992}
993
994/// This friend operator of ipstream extracts (reads) from the ipstream ps, to the
995/// given argument. It returns a reference to the stream that lets you chain >>
996/// operations in the usual way.
997/// The data type of the argument determines how the read is performed. For example,
998/// reading a signed char is implemented using readByte.
999inline ipstream& operator >> ( ipstream& ps, float &f ){
1000 ps.readBytes( &f, sizeof(f) );
1001 return ps;
1002}
1003
1004/// This friend operator of ipstream extracts (reads) from the ipstream ps, to the
1005/// given argument. It returns a reference to the stream that lets you chain >>
1006/// operations in the usual way.
1007/// The data type of the argument determines how the read is performed. For example,
1008/// reading a signed char is implemented using readByte.
1009inline ipstream& operator >> ( ipstream& ps, double &d ){
1010 ps.readBytes( &d, sizeof(d) );
1011 return ps;
1012}
1013
1014/// This friend operator of ipstream extracts (reads) from the ipstream ps, to the
1015/// given argument. It returns a reference to the stream that lets you chain >>
1016/// operations in the usual way.
1017/// The data type of the argument determines how the read is performed. For example,
1018/// reading a signed char is implemented using readByte.
1019inline ipstream& operator >> ( ipstream& ps, long double &l ){
1020 ps.readBytes( &l, sizeof(l) );
1021 return ps;
1022}
1023
1024/// This friend operator of ipstream extracts (reads) from the ipstream ps, to the
1025/// given argument. It returns a reference to the stream that lets you chain >>
1026/// operations in the usual way.
1027/// The data type of the argument determines how the read is performed. For example,
1028/// reading a signed char is implemented using readByte.
1029inline ipstream& operator >> ( ipstream& ps, bool &b ){
1030 b = static_cast<bool>(ps.readWord32());
1031 return ps;
1032}
1033
1034/// This friend operator of opstream inserts (writes) the given argument to the
1035/// given ipstream object.
1036/// The data type of the argument determines the form of write operation employed.
1038 ps.writeByte( ch );
1039 return ps;
1040}
1041
1042/// This friend operator of opstream inserts (writes) the given argument to the
1043/// given ipstream object.
1044/// The data type of the argument determines the form of write operation employed.
1046 ps.writeByte( ch );
1047 return ps;
1048}
1049
1050/// This friend operator of opstream inserts (writes) the given argument to the
1051/// given ipstream object.
1052/// The data type of the argument determines the form of write operation employed.
1054 ps.writeByte( ch );
1055 return ps;
1056}
1057
1058/// This friend operator of opstream inserts (writes) the given argument to the
1059/// given ipstream object.
1060/// The data type of the argument determines the form of write operation employed.
1061inline opstream& operator << ( opstream& ps, signed short sh ){
1062 ps.writeWord16( sh );
1063 return ps;
1064}
1065
1066/// This friend operator of opstream inserts (writes) the given argument to the
1067/// given ipstream object.
1068/// The data type of the argument determines the form of write operation employed.
1069inline opstream& operator << ( opstream& ps, unsigned short sh ){
1070 ps.writeWord16( sh );
1071 return ps;
1072}
1073
1074/// This friend operator of opstream inserts (writes) the given argument to the
1075/// given ipstream object.
1076/// The data type of the argument determines the form of write operation employed.
1077inline opstream& operator << ( opstream& ps, signed int i ){
1078 ps.writeWord32( i );
1079 return ps;
1080}
1081
1082/// This friend operator of opstream inserts (writes) the given argument to the
1083/// given ipstream object.
1084/// The data type of the argument determines the form of write operation employed.
1085inline opstream& operator << ( opstream& ps, unsigned int i ){
1086 ps.writeWord32( i );
1087 return ps;
1088}
1089
1090/// This friend operator of opstream inserts (writes) the given argument to the
1091/// given ipstream object.
1092/// The data type of the argument determines the form of write operation employed.
1093inline opstream& operator << ( opstream& ps, signed long l ){
1094 ps.writeBytes( &l, sizeof(l) );
1095 return ps;
1096}
1097
1098/// This friend operator of opstream inserts (writes) the given argument to the
1099/// given ipstream object.
1100/// The data type of the argument determines the form of write operation employed.
1101inline opstream& operator << ( opstream& ps, unsigned long l ){
1102 ps.writeBytes( &l, sizeof(l) );
1103 return ps;
1104}
1105
1107{
1108 ps.writeBytes(&v, sizeof v);
1109 return ps;
1110}
1111
1113{
1114 ps.writeBytes(&v, sizeof v);
1115 return ps;
1116}
1117
1118/// This friend operator of opstream inserts (writes) the given argument to the
1119/// given ipstream object.
1120/// The data type of the argument determines the form of write operation employed.
1121inline opstream& operator << ( opstream& ps, float f ){
1122 ps.writeBytes( &f, sizeof(f) );
1123 return ps;
1124}
1125
1126/// This friend operator of opstream inserts (writes) the given argument to the
1127/// given ipstream object.
1128/// The data type of the argument determines the form of write operation employed.
1129inline opstream& operator << ( opstream& ps, double d ){
1130 ps.writeBytes( &d, sizeof(d) );
1131 return ps;
1132}
1133
1134/// This friend operator of opstream inserts (writes) the given argument to the
1135/// given ipstream object.
1136/// The data type of the argument determines the form of write operation employed.
1137inline opstream& operator << ( opstream& ps, long double l ){
1138 ps.writeBytes( &l, sizeof(l) );
1139 return ps;
1140}
1141
1142/// This friend operator of opstream inserts (writes) the given argument to the
1143/// given ipstream object.
1144/// The data type of the argument determines the form of write operation employed.
1146 ps.writeWord32( b );
1147 return ps;
1148}
1149
1150template <class Base> void WriteBaseObject( Base *base, opstream& out )
1151{
1152 typedef typename Base::Streamer Base_Streamer;
1153
1154 Base_Streamer strmr(base);
1155 out << strmr.ClassVersion();
1156 strmr.Write( out );
1157}
1158
1159template <class Base> void ReadBaseObject( Base *base, ipstream& in )
1160{
1161 typedef typename Base::Streamer Base_Streamer;
1162
1163 uint32 version = 0;
1164 if( in.getVersion() > 0 )
1165 in >> version;
1166 Base_Streamer(base).Read( in, version );
1167}
1168
1169template <class Base> void WriteVirtualBase( Base *base, opstream& out )
1170{
1171 typedef typename Base::Streamer Base_Streamer;
1172
1173 if( !out.good() )
1174 return;
1175 if( out.findVB( base ) != 0 ){
1176 out.writeByte( pstream::ptIndexed ); // use ptIndexed to indicate
1177 // that we've already seen
1178 // this virtual base. Don't
1179 // need to actually write it.
1180 }
1181 else{
1182 Base_Streamer strmr(base);
1183 out.registerObject( (TStreamableBase *)((char*)base + 1) );
1184 out.writeByte( pstream::ptObject );
1185 out.writeWord32( strmr.ClassVersion() );
1186 strmr.Write( out );
1187 }
1188}
1189
1190template <class Base> void ReadVirtualBase( Base *base, ipstream& in )
1191{
1192 typedef typename Base::Streamer Base_Streamer;
1193
1194 char ch;
1195 in >> ch;
1196 switch( ch ){
1197 case pstream::ptIndexed:
1198 break; // We've already read this virtual base
1199 case pstream::ptObject: {
1200 uint32 ver = 0;
1201 if( in.getVersion() > 0 )
1202 ver = in.readWord32();
1203 Base_Streamer strmr(base);
1204 // register the address
1205 in.registerObject(strmr.GetObject());
1206 strmr.Read( in, ver );
1207 }
1208 break;
1209 }
1210}
1211
1212//
1213// Individual Components for Streamable Declarations
1214//
1215
1216#if defined(__clang__)
1217#define READBASEOBJECT(cls) ReadBaseObject<cls>( cls *, ::owl::ipstream& )
1218#define WRITEBASEOBJECT(cls) WriteBaseObject<cls>( cls *, ::owl::opstream& )
1219#define READVIRTUALBASE(cls) ReadVirtualBase<cls>( cls *, ::owl::ipstream& )
1220#define WRITEVIRTUALBASE(cls) WriteVirtualBase<cls>( cls *, ::owl::opstream& )
1221#else
1222#define READBASEOBJECT(cls) ReadBaseObject( cls *, ::owl::ipstream& )
1223#define WRITEBASEOBJECT(cls) WriteBaseObject( cls *, ::owl::opstream& )
1224#define READVIRTUALBASE(cls) ReadVirtualBase( cls *, ::owl::ipstream& )
1225#define WRITEVIRTUALBASE(cls) WriteVirtualBase( cls *, ::owl::opstream& )
1226#endif
1227
1228
1229
1230#define DECLARE_STREAMERS(cls, ver ) \
1231public: \
1232 class Streamer : public ::owl::TNewStreamer \
1233 { \
1234 public: \
1235 \
1236 Streamer( ::owl::TStreamableBase *obj ); \
1237 \
1238 virtual ::owl::uint32 ClassVersion() const \
1239 { return ver; } \
1240 \
1241 virtual void Write( ::owl::opstream& ) const; \
1242 virtual void *Read( ::owl::ipstream&, ::owl::uint32 ) const; \
1243 \
1244 cls *GetObject() const \
1245 { \
1246 return object; \
1247 } \
1248 \
1249 static ::owl::TStreamer *Build( ::owl::TStreamableBase *obj ) \
1250 { \
1251 return new Streamer( obj ? obj : new cls(::owl::streamableInit) ); \
1252 } \
1253 \
1254 private: \
1255 cls *object; \
1256 \
1257 }; \
1258 friend class Streamer; \
1259 friend void ::owl:: READBASEOBJECT( cls ); \
1260 friend void ::owl:: WRITEBASEOBJECT( cls );\
1261 friend void ::owl:: READVIRTUALBASE( cls );\
1262 friend void ::owl:: WRITEVIRTUALBASE( cls )
1263
1264
1265#define DECLARE_STREAMER( exp, cls, ver ) \
1266public: \
1267 class exp Streamer : public ::owl::TNewStreamer \
1268 { \
1269 public: \
1270 \
1271 Streamer( ::owl::TStreamableBase *obj ); \
1272 \
1273 virtual ::owl::uint32 ClassVersion() const \
1274 { return ver; } \
1275 \
1276 virtual void Write( ::owl::opstream& ) const; \
1277 virtual void *Read( ::owl::ipstream&, ::owl::uint32 ) const; \
1278 \
1279 cls *GetObject() const \
1280 { \
1281 return object; \
1282 } \
1283 \
1284 static ::owl::TStreamer *Build( ::owl::TStreamableBase *obj ) \
1285 { \
1286 return new Streamer( obj ? obj : new cls(::owl::streamableInit) ); \
1287 } \
1288 \
1289 private: \
1290 cls *object; \
1291 \
1292 }; \
1293 friend class exp Streamer; \
1294 friend void ::owl:: READBASEOBJECT( cls ); \
1295 friend void ::owl:: WRITEBASEOBJECT( cls ); \
1296 friend void ::owl:: READVIRTUALBASE( cls ); \
1297 friend void ::owl:: WRITEVIRTUALBASE( cls )
1298
1299
1300#define DECLARE_STREAMER_FROM_BASES(cls, base ) \
1301public: \
1302 class Streamer : public base::Streamer \
1303 { \
1304 public: \
1305 \
1306 Streamer( ::owl::TStreamableBase *obj ) : base::Streamer(obj){} \
1307 \
1308 cls *GetObject() const \
1309 { \
1310 return object; \
1311 } \
1312 \
1313 static ::owl::TStreamer *Build( ::owl::TStreamableBase *obj ) \
1314 { \
1315 return new Streamer( obj ? obj : new cls(::owl::streamableInit) ); \
1316 } \
1317 \
1318 private: \
1319 cls *object; \
1320 \
1321 }; \
1322 friend class Streamer; \
1323 friend void ::owl:: READBASEOBJECT( cls ); \
1324 friend void ::owl:: WRITEBASEOBJECT( cls ); \
1325 friend void ::owl:: READVIRTUALBASE( cls ); \
1326 friend void ::owl:: WRITEVIRTUALBASE( cls )
1327
1328
1329#define DECLARE_STREAMER_FROM_BASE( exp, cls, base ) \
1330public: \
1331 class exp Streamer : public base::Streamer \
1332 { \
1333 public: \
1334 \
1335 Streamer( ::owl::TStreamableBase *obj ) : base::Streamer(obj){} \
1336 \
1337 cls *GetObject() const \
1338 { \
1339 return object; \
1340 } \
1341 \
1342 static ::owl::TStreamer *Build( ::owl::TStreamableBase *obj ) \
1343 { \
1344 return new Streamer( obj ? obj : new cls(::owl::streamableInit) ); \
1345 } \
1346 \
1347 private: \
1348 cls *object; \
1349 \
1350 }; \
1351 friend class exp Streamer; \
1352 friend void ::owl:: READBASEOBJECT( cls ); \
1353 friend void ::owl:: WRITEBASEOBJECT( cls );\
1354 friend void ::owl:: READVIRTUALBASE( cls );\
1355 friend void ::owl:: WRITEVIRTUALBASE( cls )
1356
1357#define DECLARE_ABSTRACT_STREAMERS(cls, ver ) \
1358public: \
1359 class Streamer : public ::owl::TNewStreamer \
1360 { \
1361 public: \
1362 \
1363 Streamer( ::owl::TStreamableBase *obj ); \
1364 \
1365 virtual ::owl::uint32 ClassVersion() const \
1366 { return ver; } \
1367 \
1368 virtual void Write( ::owl::opstream& ) const; \
1369 virtual void *Read( ::owl::ipstream&, ::owl::uint32 ) const; \
1370 \
1371 cls *GetObject() const \
1372 { \
1373 return object; \
1374 } \
1375 \
1376 private: \
1377 cls *object; \
1378 \
1379 }; \
1380 friend class Streamer; \
1381 friend void ::owl:: READBASEOBJECT( cls ); \
1382 friend void ::owl:: WRITEBASEOBJECT( cls );\
1383 friend void ::owl:: READVIRTUALBASE( cls );\
1384 friend void ::owl:: WRITEVIRTUALBASE( cls )
1385
1386#define DECLARE_ABSTRACT_STREAMER( exp, cls, ver ) \
1387public: \
1388 class exp Streamer : public ::owl::TNewStreamer \
1389 { \
1390 public: \
1391 \
1392 Streamer( ::owl::TStreamableBase *obj ); \
1393 \
1394 virtual ::owl::uint32 ClassVersion() const \
1395 { return ver; } \
1396 \
1397 virtual void Write( ::owl::opstream& ) const; \
1398 virtual void *Read( ::owl::ipstream&, ::owl::uint32 ) const; \
1399 \
1400 cls *GetObject() const \
1401 { \
1402 return object; \
1403 } \
1404 \
1405 private: \
1406 cls *object; \
1407 \
1408 }; \
1409 friend class exp Streamer; \
1410 friend void ::owl:: READBASEOBJECT( cls ); \
1411 friend void ::owl:: WRITEBASEOBJECT( cls );\
1412 friend void ::owl:: READVIRTUALBASE( cls );\
1413 friend void ::owl:: WRITEVIRTUALBASE( cls )
1414
1415
1416#define DECLARE_STREAMABLE_OPS( cls ) \
1417static ::owl::ipstream& readRef( ::owl::ipstream& is, cls& cl ); \
1418friend inline ::owl::ipstream& operator >> ( ::owl::ipstream& is, cls& cl ) \
1419 { return cls::readRef( is, cl ); } \
1420static ::owl::ipstream& readPtr( ::owl::ipstream& is, cls*& cl ); \
1421friend inline ::owl::ipstream& operator >> ( ::owl::ipstream& is, cls*& cl ) \
1422 { return cls::readPtr( is, cl ); } \
1423static ::owl::opstream& writeRef( ::owl::opstream& is, const cls& cl ); \
1424friend inline ::owl::opstream& operator << ( ::owl::opstream& os, const cls& cl ) \
1425 { return cls::writeRef( os, cl ); } \
1426static ::owl::opstream& writePtr( ::owl::opstream& is, const cls* cl ); \
1427friend inline ::owl::opstream& operator << ( ::owl::opstream& os, const cls* cl ) \
1428 { return cls::writePtr( os, cl ); }
1429
1430#define DECLARE_STREAMABLE_INLINES_I( cls )
1431
1432
1433#define DECLARE_STREAMABLE_CTOR( cls ) \
1434public: \
1435 cls ( ::owl::StreamableInit )
1436
1437//
1438// Castable declaration macros
1439//
1440# define DECLARE_CASTABLE friend class std::type_info
1441
1442//
1443// Streamable declaration macros
1444//
1445#if OWL_PERSISTENT_STREAMS
1446
1447#define DECLARE_STREAMABLE( exp, cls, ver ) \
1448 DECLARE_CASTABLE ; \
1449 DECLARE_STREAMER( exp, cls, ver ); \
1450 DECLARE_STREAMABLE_OPS( cls ); \
1451 DECLARE_STREAMABLE_CTOR( cls )
1452
1453#define DECLARE_STREAMABLES(cls, ver ) \
1454 DECLARE_CASTABLE ; \
1455 DECLARE_STREAMERS(cls, ver ); \
1456 DECLARE_STREAMABLE_OPS( cls ); \
1457 DECLARE_STREAMABLE_CTOR( cls )
1458
1459#define DECLARE_STREAMABLE_FROM_BASE( exp, cls, base ) \
1460 DECLARE_CASTABLE; \
1461 DECLARE_STREAMER_FROM_BASE( exp, cls, base ); \
1462 DECLARE_STREAMABLE_OPS( cls ); \
1463 DECLARE_STREAMABLE_CTOR( cls )
1464
1465#define DECLARE_STREAMABLE_FROM_BASES(cls, base ) \
1466 DECLARE_CASTABLE; \
1467 DECLARE_STREAMER_FROM_BASES(cls, base ); \
1468 DECLARE_STREAMABLE_OPS( cls ); \
1469 DECLARE_STREAMABLE_CTOR( cls )
1470
1471#define DECLARE_ABSTRACT_STREAMABLE( exp, cls, ver ) \
1472 DECLARE_CASTABLE; \
1473 DECLARE_ABSTRACT_STREAMER( exp, cls, ver ); \
1474 DECLARE_STREAMABLE_OPS( cls ); \
1475 DECLARE_STREAMABLE_CTOR( cls )
1476
1477#define DECLARE_ABSTRACT_STREAMABLES(cls, ver ) \
1478 DECLARE_CASTABLE; \
1479 DECLARE_ABSTRACT_STREAMERS(cls, ver ); \
1480 DECLARE_STREAMABLE_OPS( cls ); \
1481 DECLARE_STREAMABLE_CTOR( cls )
1482
1483// only for OWL
1484#if defined(_BUILDOWLDLL) || defined(_OWLDLL)
1485# define DECLARE_STREAMABLE_OWL( cls, ver ) \
1486 DECLARE_STREAMABLE( _OWLCLASS, cls, ver )
1487# define DECLARE_STREAMABLE_FROM_BASE_OWL( cls, base ) \
1488 DECLARE_STREAMABLE_FROM_BASE( _OWLCLASS, cls, base )
1489#define DECLARE_ABSTRACT_STREAMABLE_OWL(cls, ver ) \
1490 DECLARE_ABSTRACT_STREAMABLE( _OWLCLASS, cls, ver )
1491
1492#define DECLARE_STREAMABLE_INLINES( cls ) \
1493 DECLARE_STREAMABLE_INLINES_I( cls )
1494
1495#else
1496# define DECLARE_STREAMABLE_OWL(cls, ver ) \
1497 DECLARE_STREAMABLES( cls, ver )
1498# define DECLARE_STREAMABLE_FROM_BASE_OWL( cls, base ) \
1499 DECLARE_STREAMABLE_FROM_BASES(cls, base )
1500#define DECLARE_ABSTRACT_STREAMABLE_OWL(cls, ver ) \
1501 DECLARE_ABSTRACT_STREAMABLES(cls, ver )
1502
1503#define DECLARE_STREAMABLE_INLINES( cls ) \
1504 DECLARE_STREAMABLE_INLINES_I( cls )
1505
1506#endif
1507
1508
1509#else
1510
1511#define DECLARE_STREAMABLE( exp, cls, ver ) \
1512 DECLARE_CASTABLE
1513
1514#define DECLARE_STREAMABLE_S(cls, ver ) \
1515 DECLARE_CASTABLE
1516
1517#define DECLARE_STREAMABLE_FROM_BASE( exp, cls, base ) \
1518 DECLARE_CASTABLE
1519
1520#define DECLARE_STREAMABLE_FROM_BASE_S( cls, base ) \
1521 DECLARE_CASTABLE
1522
1523#define DECLARE_ABSTRACT_STREAMABLE( exp, cls, ver ) \
1524 DECLARE_CASTABLE
1525
1526#define DECLARE_ABSTRACT_STREAMABLE_S( cls, ver ) \
1527 DECLARE_CASTABLE
1528
1529#define DECLARE_STREAMABLE_OWL(cls, ver ) \
1530 DECLARE_CASTABLE
1531
1532# define DECLARE_STREAMABLE_FROM_BASE_OWL( cls, base ) \
1533 DECLARE_CASTABLE
1534
1535#define DECLARE_ABSTRACT_STREAMABLE_OWL( cls, ver ) \
1536 DECLARE_CASTABLE
1537
1538#define DECLARE_STREAMABLE_INLINES( cls )
1539
1540#endif
1541
1542//
1543// Castable implementation macros
1544//
1545
1546// These macros are obsolete, since all modern compilers support RTTI. They will be moved to backward compatibility section
1547#define IMPLEMENT_CASTABLE( cls )
1548#define IMPLEMENT_CASTABLE1( cls, base1 )
1549#define IMPLEMENT_CASTABLE2( cls, base1, base2 )
1550#define IMPLEMENT_CASTABLE3( cls, base1, base2, base3 )
1551#define IMPLEMENT_CASTABLE4( cls, base1, base2, base3, base4 )
1552#define IMPLEMENT_CASTABLE5( cls, base1, base2, base3, base4, base5 )
1553
1554
1555
1556//
1557// Streamable implementation mactos
1558//
1559#if OWL_PERSISTENT_STREAMS
1560# if defined(BI_COMP_MSC) && !defined(UNIX) && !defined(__EDG__)
1561# if defined(BI_COMPATIBLE_STREAMING)
1562# define IMPLEMENT_STREAMABLE_CLASS( cls ) \
1563 ::owl::TStreamableClass r ## cls( typeid(cls).name() + 6, &cls::Streamer::Build )
1564# else
1565# define IMPLEMENT_STREAMABLE_CLASS( cls ) \
1566 ::owl::TStreamableClass r ## cls( typeid(cls).raw_name(), &cls::Streamer::Build )
1567# endif
1568# else
1569# define IMPLEMENT_STREAMABLE_CLASS( cls ) \
1570 ::owl::TStreamableClass r ## cls( typeid(cls).name(), &cls::Streamer::Build )
1571# endif
1572#else
1573# define IMPLEMENT_STREAMABLE_CLASS( cls )
1574#endif
1575
1576#if OWL_PERSISTENT_STREAMS
1577
1578#define IMPLEMENT_STREAMABLE_POINTER_IMPL(template_prefix, cls)\
1579 template_prefix owl::ipstream& cls::readPtr(::owl::ipstream& is, cls*& cl)\
1580 {::owl::TStreamableBase *t = 0; cl = dynamic_cast<cls*>(is.readObjectPointer(t)); return is;}\
1581 \
1582 template_prefix owl::ipstream& cls::readRef(::owl::ipstream& is, cls& cl)\
1583 {::owl::TStreamableBase* p = &cl; is.readObject(p); return is;}\
1584 \
1585 template_prefix owl::opstream& cls::writeRef(::owl::opstream& os, const cls& cl)\
1586 {os.writeObject(&cl); return os;}\
1587 \
1588 template_prefix owl::opstream& cls::writePtr(::owl::opstream& os, const cls* cl)\
1589 {os.writeObjectPointer(cl); return os;}
1590
1591#define IMPLEMENT_STREAMABLE_POINTER(cls)\
1592 IMPLEMENT_STREAMABLE_POINTER_IMPL(, cls)
1593
1594#else
1595#define IMPLEMENT_STREAMABLE_POINTER_IMPL(template_prefix, cls)
1596#define IMPLEMENT_STREAMABLE_POINTER( cls )
1597#endif
1598
1599#if OWL_PERSISTENT_STREAMS
1600
1601#define IMPLEMENT_STREAMER( cls ) \
1602cls::Streamer::Streamer( ::owl::TStreamableBase *obj ) : \
1603 ::owl::TNewStreamer(obj), object(TYPESAFE_DOWNCAST(obj,cls)){}
1604
1605#define IMPLEMENT_STREAMABLE_CTOR( cls ) \
1606cls::cls ( ::owl::StreamableInit ) {}
1607
1608#define IMPLEMENT_STREAMABLE_CTOR1_IMPL(template_prefix, cls, constructor, base1)\
1609 template_prefix cls::constructor(::owl::StreamableInit) : base1(::owl::streamableInit) {}
1610
1611#define IMPLEMENT_STREAMABLE_CTOR1(cls, base1)\
1612 IMPLEMENT_STREAMABLE_CTOR1_IMPL(, cls, cls, base1)
1613
1614#define IMPLEMENT_STREAMABLE_CTOR2( cls, base1, base2 ) \
1615cls::cls ( ::owl::StreamableInit ) : \
1616 base1 ( ::owl::streamableInit ), \
1617 base2 ( ::owl::streamableInit ) {}
1618
1619#define IMPLEMENT_STREAMABLE_CTOR3( cls, base1, base2, base3 ) \
1620cls::cls ( ::owl::StreamableInit ) : \
1621 base1 ( ::owl::streamableInit ), \
1622 base2 ( ::owl::streamableInit ), \
1623 base3 ( ::owl::streamableInit ) {}
1624
1625#define IMPLEMENT_STREAMABLE_CTOR4( cls, base1, base2, base3, base4 )\
1626cls::cls ( ::owl::StreamableInit ) : \
1627 base1 ( ::owl::streamableInit ), \
1628 base2 ( ::owl::streamableInit ), \
1629 base3 ( ::owl::streamableInit ), \
1630 base4 ( ::owl::streamableInit ) {}
1631
1632#define IMPLEMENT_STREAMABLE_CTOR5( cls, base1,base2,base3,base4,base5)\
1633cls::cls ( ::owl::StreamableInit ) : \
1634 base1 ( ::owl::streamableInit ), \
1635 base2 ( ::owl::streamableInit ), \
1636 base3 ( ::owl::streamableInit ), \
1637 base4 ( ::owl::streamableInit ), \
1638 base5 ( ::owl::streamableInit ) {}
1639
1640#else
1641# define IMPLEMENT_STREAMER( cls )
1642# define IMPLEMENT_STREAMABLE_CTOR( cls )
1643# define IMPLEMENT_STREAMABLE_CTOR1_IMPL(template_prefix, cls, constructor, base1)
1644# define IMPLEMENT_STREAMABLE_CTOR1( cls, base1 )
1645# define IMPLEMENT_STREAMABLE_CTOR2( cls, base1, base2 )
1646# define IMPLEMENT_STREAMABLE_CTOR3( cls, base1, base2, base3 )
1647# define IMPLEMENT_STREAMABLE_CTOR4( cls, base1, base2, base3, base4 )
1648# define IMPLEMENT_STREAMABLE_CTOR5( cls, base1,base2,base3,base4,base5)
1649#endif
1650 \
1651
1652//
1653// Standard Combinations of Streamable Implementations
1654//
1655
1656#if OWL_PERSISTENT_STREAMS
1657#define IMPLEMENT_ABSTRACT_STREAMABLE( cls ) \
1658IMPLEMENT_STREAMER( cls ); \
1659IMPLEMENT_STREAMABLE_CTOR( cls ); \
1660IMPLEMENT_STREAMABLE_POINTER( cls )
1661
1662#define IMPLEMENT_ABSTRACT_STREAMABLE1( cls, base1 ) \
1663IMPLEMENT_STREAMER( cls ); \
1664IMPLEMENT_STREAMABLE_CTOR1( cls, base1 ); \
1665IMPLEMENT_STREAMABLE_POINTER( cls )
1666
1667#define IMPLEMENT_ABSTRACT_STREAMABLE2( cls, base1, base2 ) \
1668IMPLEMENT_STREAMER( cls ); \
1669IMPLEMENT_STREAMABLE_CTOR2( cls, base1, base2 ); \
1670IMPLEMENT_STREAMABLE_POINTER( cls )
1671
1672#define IMPLEMENT_ABSTRACT_STREAMABLE3( cls, base1, base2, base3 ) \
1673IMPLEMENT_STREAMER( cls ); \
1674IMPLEMENT_STREAMABLE_CTOR3( cls, base1, base2, base3 ); \
1675IMPLEMENT_STREAMABLE_POINTER( cls )
1676
1677#define IMPLEMENT_ABSTRACT_STREAMABLE4( cls, base1, base2, base3, base4 )\
1678IMPLEMENT_STREAMER( cls ); \
1679IMPLEMENT_STREAMABLE_CTOR4( cls, base1, base2, base3, base4 ); \
1680IMPLEMENT_STREAMABLE_POINTER( cls )
1681
1682#define IMPLEMENT_ABSTRACT_STREAMABLE5( cls, base1, base2, base3, base4, base5 )\
1683IMPLEMENT_STREAMER( cls ); \
1684IMPLEMENT_STREAMABLE_CTOR5( cls, base1, base2, base3, base4, base5 );\
1685IMPLEMENT_STREAMABLE_POINTER( cls )
1686
1687#define IMPLEMENT_STREAMABLE( cls ) \
1688IMPLEMENT_STREAMABLE_CLASS( cls ); \
1689IMPLEMENT_ABSTRACT_STREAMABLE( cls )
1690
1691#define IMPLEMENT_STREAMABLE1( cls, base1 ) \
1692IMPLEMENT_STREAMABLE_CLASS( cls ); \
1693IMPLEMENT_ABSTRACT_STREAMABLE1( cls, base1 )
1694
1695#define IMPLEMENT_STREAMABLE2( cls, base1, base2 ) \
1696IMPLEMENT_STREAMABLE_CLASS( cls ); \
1697IMPLEMENT_ABSTRACT_STREAMABLE2( cls, base1, base2 )
1698
1699#define IMPLEMENT_STREAMABLE3( cls, base1, base2, base3 ) \
1700IMPLEMENT_STREAMABLE_CLASS( cls ); \
1701IMPLEMENT_ABSTRACT_STREAMABLE3( cls, base1, base2, base3 )
1702
1703#define IMPLEMENT_STREAMABLE4( cls, base1, base2, base3, base4 ) \
1704IMPLEMENT_STREAMABLE_CLASS( cls ); \
1705IMPLEMENT_ABSTRACT_STREAMABLE4( cls, base1, base2, base3, base4 )
1706
1707#define IMPLEMENT_STREAMABLE5( cls, base1, base2, base3, base4, base5 )\
1708IMPLEMENT_STREAMABLE_CLASS( cls ); \
1709IMPLEMENT_ABSTRACT_STREAMABLE5( cls, base1, base2, base3, base4, base5 )
1710
1711#define IMPLEMENT_STREAMABLE_FROM_BASE( cls, base1 ) \
1712IMPLEMENT_STREAMABLE_CLASS( cls ); \
1713IMPLEMENT_STREAMABLE_CTOR1( cls, base1 ); \
1714IMPLEMENT_STREAMABLE_POINTER( cls )
1715
1716#else
1717
1718#define IMPLEMENT_ABSTRACT_STREAMABLE( cls )
1719#define IMPLEMENT_ABSTRACT_STREAMABLE1( cls, base1 )
1720#define IMPLEMENT_ABSTRACT_STREAMABLE2( cls, base1, base2 )
1721#define IMPLEMENT_ABSTRACT_STREAMABLE3( cls, base1, base2, base3 )
1722#define IMPLEMENT_ABSTRACT_STREAMABLE4( cls, base1, base2, base3, base4 )
1723#define IMPLEMENT_ABSTRACT_STREAMABLE5( cls, base1, base2, base3, base4, base5 )
1724#define IMPLEMENT_STREAMABLE( cls )
1725#define IMPLEMENT_STREAMABLE1( cls, base1 )
1726#define IMPLEMENT_STREAMABLE2( cls, base1, base2 )
1727#define IMPLEMENT_STREAMABLE3( cls, base1, base2, base3 )
1728#define IMPLEMENT_STREAMABLE4( cls, base1, base2, base3, base4 )
1729#define IMPLEMENT_STREAMABLE5( cls, base1, base2, base3, base4, base5 )
1730#define IMPLEMENT_STREAMABLE_FROM_BASE( cls, base1 )
1731
1732#endif
1733
1734/// @}
1735
1736} // OWL namespace
1737
1738
1739#endif // OWL_OBJSTRM_H
TNewStreamer(TStreamableBase *obj)
Constructs the TNewStreamer object, and initializes the streamable object pointer.
Definition objstrm.h:226
virtual LPCSTR StreamableName() const
Definition objstrm.h:230
Provides a base class for all streamable objects.
Definition objstrm.h:174
virtual void * Read(ipstream &is, uint32) const
This pure virtual member function must be redefined for every streamable class.
Definition objstrm.h:196
virtual LPCSTR StreamableName() const
This pure virtual member function must be redefined for every streamable class.
Definition objstrm.h:188
TOldStreamer(TStreamable *obj)
Constructs the TOldStreamer object, and initializes the streamable object pointer.
Definition objstrm.h:180
virtual void Write(opstream &os) const
This pure virtual function must be redefined for every streamable class.
Definition objstrm.h:206
TPWObj(const void *adr, P_id_type id)
Definition objstrm.h:265
Classes that inherit from TStreamableBase are known as streamable classes (their objects can be writt...
Definition objstrm.h:108
TStreamableClass is used by the private database class and pstream in the registration of streamable ...
Definition streambl.h:75
virtual LPCSTR streamableName() const =0
virtual void * read(ipstream &)=0
virtual void write(opstream &)=0
Provides a base class for all streamable objects.
Definition objstrm.h:130
virtual void Write(opstream &) const =0
This pure virtual function must be redefined for every streamable class.
TStreamer(TStreamableBase *obj)
Constructs the TStreamer object, and initializes the streamable object pointer.
Definition objstrm.h:145
virtual ~TStreamer()
Definition objstrm.h:137
virtual void * Read(ipstream &, uint32) const =0
This pure virtual member function must be redefined for every streamable class.
TStreamableBase * GetObject() const
Returns the address of the TStreamableBase component of the streamable object.
Definition objstrm.h:140
Provides the basic operations common to all object file stream I/O.
Definition objstrm.h:548
void open(LPCSTR, int, int=openprot)
Opens the named file in the given mode (app, ate, in, out, binary, trunc, nocreate,...
Definition objstrm.cpp:909
ifpstream is a simple "mix" of its bases, fpbase and ipstream.
Definition objstrm.h:574
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
Definition objstrm.h:391
ipstream & seekg(std::streamoff, std::ios::seekdir)
void readVersion()
Reads the version number of the input stream.
Definition objstrm.cpp:540
ipstream & seekg(std::streampos)
Provides the base class for writing (inserting) streamable objects to file streams.
Definition objstrm.h:605
Base class for writing streamable objects.
Definition objstrm.h:480
opstream(std::streambuf *)
opstream & seekp(std::streamoff, std::ios::seekdir)
void writeByte(uint8)
Writes the byte ch to the stream.
Definition objstrm.cpp:753
void writeVersion()
Definition objstrm.cpp:736
opstream & seekp(std::streampos)
void writeWord32(uint32)
Writes the 32-bit word us to the stream.
Definition objstrm.cpp:783
Base class for handling streamable objects.
Definition objstrm.h:330
std::streambuf * bp
Definition objstrm.h:356
PointerTypes
Enumerates object pointer types.
Definition objstrm.h:336
unsigned P_id_type
Definition objstrm.h:54
int good() const
Returns nonzero if no error states have been recorded for the stream (that is, no errors have occurre...
Definition objstrm.h:666
void registerVB(TStreamableBase *adr)
Registers a virtual base class.
Definition objstrm.h:767
int operator!() const
Overloads the NOT operator.
Definition objstrm.h:682
void registerObject(TStreamableBase *adr)
Registers the class of the object pointed to by adr.
Definition objstrm.h:757
std::filebuf * rdbuf()
Returns a pointer to the current file buffer.
Definition objstrm.h:791
void registerObject(TStreamableBase *adr)
Registers the object pointed to by adr.
Definition objstrm.h:727
std::streambuf * rdbuf() const
Returns the pb pointer to the buffer assigned to the stream.
Definition objstrm.h:687
P_id_type findObject(TStreamableBase *adr)
Returns the type ID for the object pointed to by adr.
Definition objstrm.h:752
ifpstream()
Creates a buffered ifpstream object using a default buffer.
Definition objstrm.h:796
P_id_type findVB(TStreamableBase *adr)
Returns a pointer to the virtual base.
Definition objstrm.h:762
void open(LPCSTR, int=std::ios::out, int=fpbase::openprot)
Opens the named file in the given mode (app, ate, in, out, binary, trunc, nocreate,...
Definition objstrm.h:874
int bad() const
Returns nonzero if an error occurs.
Definition objstrm.h:660
std::filebuf * rdbuf()
Definition objstrm.h:866
void writeSuffix(const TStreamableBase *)
Writes the class name suffix to the stream.
Definition objstrm.h:747
void clear(int=0)
Sets the stream state to the given value (defaults to 0).
Definition objstrm.h:671
ipstream()
Creates a buffered ipstream without initializing the buffer pointer, bp.
Definition objstrm.h:716
#define _OBJ_TYPENAME(obj)
Definition objstrm.h:86
void writeWord(uint32)
Writes the 32-bit word us to the stream.
Definition objstrm.h:740
pstream()
Creates a pstream without initializing the buffer pointer bp or state.
Definition objstrm.h:693
uint32 getVersion() const
Returns the object version number.
Definition objstrm.h:732
void ReadBaseObject(Base *base, ipstream &in)
Definition objstrm.h:1159
void open(LPCSTR, int=std::ios::in, int=fpbase::openprot)
It opens the named file in the given mode (app, ate, in, out, binary, trunc, nocreate,...
Definition objstrm.h:824
TStreamableBase * find(P_id_type)
Returns a pointer to the object corresponding to Id.
Definition objstrm.h:722
void setstate(int)
Updates the state data member with state |= (b & 0xFF).
Definition objstrm.h:704
fpbase()
Creates a buffered fpbase object.
Definition objstrm.h:772
void ReadVirtualBase(Base *base, ipstream &in)
Definition objstrm.h:1190
void WriteVirtualBase(Base *base, opstream &out)
Definition objstrm.h:1169
virtual ~opstream()
Definition objstrm.h:735
StreamableInit
Definition objstrm.h:98
ofpstream()
Creates a buffered ofpstream object using a default buffer.
Definition objstrm.h:845
int eof() const
Returns nonzero on end of stream.
Definition objstrm.h:650
int rdstate() const
Returns the current state value.
Definition objstrm.h:645
int fail() const
Returns nonzero if a previous stream operation failed.
Definition objstrm.h:655
std::filebuf * rdbuf()
Returns a pointer to the current file buffer.
Definition objstrm.h:816
void WriteBaseObject(Base *base, opstream &out)
Definition objstrm.h:1150
void init(std::streambuf *)
The init member function initializes the stream and sets state to 0 and bp to sbp.
Definition objstrm.h:698
@ streamableInit
Definition objstrm.h:98
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
__int64 int64
Definition number.h:36
ModuleId GetModuleId()
Definition streambl.h:53
unsigned ModuleId
Definition streambl.h:52
owl::opstream & operator<<(owl::opstream &os, const TColor &c)
Insert the color value into a persistent output stream.
Definition color.h:498
signed char int8
Definition number.h:28
unsigned char uint8
Definition number.h:32
unsigned long uint32
Definition number.h:34
unsigned __int64 uint64
Definition number.h:43
unsigned short uint16
Definition number.h:33
std::string tstring
Definition defs.h:79
owl::ipstream & operator>>(owl::ipstream &is, TColor &c)
Extract the color value from a persistent input stream.
Definition color.h:489
General definitions used by all ObjectWindows programs.
#define _RTTI
Definition defs.h:223
#define _OWLCFUNC(p)
Definition defs.h:342
#define _OWLCLASS
Definition defs.h:338
#define STATIC_CAST(targetType, object)
Definition defs.h:271
Class definitions for object streaming.