15#if defined(BI_MULTI_THREAD_RTL)
22#if defined(__BORLANDC__)
34 const uint32 streamVersion = 0x0101;
35 const tchar versionIndicator =
_T(
':');
38 const uint8 oldNullStringLen = UCHAR_MAX;
39 const uint32 nullStringLen = ULONG_MAX;
52#if defined(BI_MULTI_THREAD_RTL)
54 TMRSWSection& GetLock_()
56 static TMRSWSection lock;
60#define LOCK_TYPES_(s) TMRSWSection::TLock lock__(GetLock_(), s, false)
70class TStreamableBaseArray:
public TPtrArray<TStreamableBase*>{
73 TStreamableBaseArray(){}
78 TStreamableClassArray(
int a,
int b=0,
int c=0):
TISortedPtrArray<TStreamableClass*>(a,b,c){}
79 TStreamableClassArray(){}
81 int Add(TStreamableClass* t);
82 bool DetachItem(TStreamableClass* t)
84 const auto index = Find(t);
92 int Find(TStreamableClass* t)
const;
94 int Add(
const TStreamableClass* t);
95 bool DetachItem(
const TStreamableClass* t);
96 int Find(
const TStreamableClass* t)
const;
103 while( loc > 0 && *t < *(
Data[loc-1])) {
107 Data[loc] = (TStreamableClass*)t;
113 auto upper =
static_cast<int>(
Size()) - 1;
114 while (lower <= upper)
116 const auto middle = (lower + upper) / 2;
117 if (*(
Data[middle]) == *t)
119 if (*(
Data[middle]) < *t)
131class TSortedTPWObjObjectArray
135 TSortedTPWObjObjectArray(
int = 0) {}
137 void Flush() { m_Items.clear(); }
138 void Add(TPWrittenObjects::TPWObj obj) { m_Items.insert(obj); }
139 P_id_type Find(TPWrittenObjects::TPWObj obj)
const
141 std::set<TPWrittenObjects::TPWObj>::const_iterator i = m_Items.find(obj);
142 return (i != m_Items.end()) ? i->Ident : 0;
147 std::set<TPWrittenObjects::TPWObj> m_Items;
194 GetTypes_().RegisterType(
id, *
this);
200 GetTypes_().UnRegisterType(ModId, *
this);
207 Types =
new TStreamableClassArray(30);
228 Types->DetachItem(&ts);
236 const auto loc = Types->Find(&sc);
237 if (loc == Types->NPOS)
242 msg =
_T(
"Attempt to stream unregistered type '");
247 return (*Types)[loc];
263 if(id < Data->Size())
268TPReadObjects::TPReadObjects()
270 Data =
new TStreamableBaseArray;
273TPReadObjects::~TPReadObjects()
279TPWrittenObjects::TPWrittenObjects()
283 Data =
new TSortedTPWObjObjectArray(10);
285TPWrittenObjects::~TPWrittenObjects()
298 Data->Add(
TPWObj(((
tchar*)(
void*)adr)+1, ++CurId));
303 Data->Add(
TPWObj(adr,++CurId));
313 return Data->Find(
TPWObj(d,0));
325 res = streampos(EOF);
327 res =
bp->pubseekoff(0, ios::cur, ios::in );
328 if( res == streampos(EOF) )
329 clear( ios::failbit );
339 streampos p =
bp->pubseekoff(pos, ios::beg, ios::in );
340 if( p == streampos(EOF) )
341 clear( ios::failbit );
357 streampos p =
bp->pubseekoff(off, dir, ios::in );
359 streampos p =
bp->pubseekoff((ios::off_type)off, dir, (ios::openmode)ios::in );
361 if( p == streampos(EOF) )
362 clear( ios::failbit );
376 clear( ios::failbit );
385 if(
good() && sz > 0 )
387 if(
bp->sgetn( (
char*)data, sz ) !=
static_cast<int>(sz) )
388 clear( ios::failbit );
397 if(
good() && sz > 0){
400 if(
bp->sgetn( (
char*)buf, sz ) !=
static_cast<int>(sz))
401 clear( ios::failbit );
403 memcpy( data, (
char*)buf, sz);
423 if(
bp->sgetn( (
char*)&temp,
sizeof( temp ) ) !=
424 static_cast<int>(
sizeof( temp )) )
425 clear( ios::failbit );
437 if(
bp->sgetn( (
char*)&temp,
sizeof( temp ) ) !=
438 static_cast<int>(
sizeof( temp )) )
439 clear( ios::failbit );
444uint32 ipstream::readStringLength()
452 if( len == oldNullStringLen )
466 uint32 len = readStringLength();
467 if( len == nullStringLen )
470 char* buf =
new char[size_t(len+1)];
474 buf[size_t(len)] = EOS;
490 uint32 len = readStringLength();
491 if( len == nullStringLen || len > maxLen-1 )
494 buf[size_t(len)] = EOS;
508 uint32 len = readStringLength();
509 if( len == nullStringLen )
512 char* buf =
new char[size_t(len)+1];
514 buf[size_t(len)] = EOS;
529 uint32 len = readStringLength();
530 if( len == nullStringLen || len > maxLen-1 )
534 buf[size_t(len)] = EOS;
545 int res =
bp->sgetc();
547 clear( ios::eofbit );
551 if( res != versionIndicator )
581 clear( ios::failbit );
588 if( name[0] == EOS ){
589 clear( ios::failbit );
598 WARNX(Objstrm,res==0,0,
_T(
"Unrecognized class identifier: ") <<
_A2W(name));
600 clear( ios::failbit );
614 mem = strmr->GetObject();
623 strmr->Read( *
this, classVer );
633 clear( ios::failbit );
660 clear( ios::failbit );
689 res = streampos(EOF);
691 res =
bp->pubseekoff(0, ios::cur, ios::out );
692 if( res == streampos(EOF) )
693 clear( ios::failbit );
704 streampos p =
bp->pubseekoff(pos, ios::beg, ios::out);
706 streampos p =
bp->pubseekoff((ios::off_type)pos, (ios::seekdir)ios::beg,
707 (ios::openmode)ios::out);
709 if( p == streampos(EOF) )
710 clear( ios::failbit );
726 streampos p =
bp->pubseekoff(off, dir, ios::out );
728 streampos p =
bp->pubseekoff((ios::off_type)off, dir, (ios::openmode)ios::out );
730 if( p == streampos(EOF) )
731 clear( ios::failbit );
747 if(
bp->pubsync() == EOF )
748 clear( ios::badbit );
756 if(
bp->sputc( ch ) == EOF )
757 clear( ios::failbit );
766 if(
good() && sz > 0 ){
767 if(
bp->sputn( (
char*)data, sz ) !=
static_cast<int>(sz) )
768 clear( ios::failbit );
776 if(
bp->sputn( (
char*)&word16,
sizeof(word16) ) !=
777 static_cast<int>(
sizeof(word16)) )
778 clear( ios::failbit );
786 if(
bp->sputn( (
char*)&word32,
sizeof(word32) ) !=
787 static_cast<int>(
sizeof(word32)) )
788 clear( ios::failbit );
798 if(
good() && sz > 0 ){
799 char* buf =
new char[sz];
801 memcpy( buf, data, sz );
802 if(
bp->sputn( (
char*)buf, sz ) !=
static_cast<int>(sz) )
803 clear( ios::failbit );
819 size_t len = strlen( str );
834 size_t len = strlen( str );
839#if !defined(BI_COMP_GNUC)
850 _T(
"Pointer written before object: ") \
858#if !defined(BI_COMP_GNUC)
902 strmr->Write( *
this );
913 else if (buf.open(b,
static_cast<ios::openmode
>(m)))
926 else if (buf.open(b,
static_cast<ios::openmode
>(m)))
944 if( buf.pubsetbuf(b, len) )
967 uint32 len = is.readStringLength();
968 if( len == nullStringLen )
971 char *temp =
new char[size_t(len)+1];
973 temp[size_t(len)] = EOS;
#define WARNX(group, condition, level, message)
#define PRECONDITION(condition)
#define CHECKX(condition, message)
#define TRACEX(group, level, message)
Smart pointer to a single object. Provides member access operator ->.
Array of pointers of simple types.
Classes that inherit from TStreamableBase are known as streamable classes (their objects can be writt...
TStreamableClass is used by the private database class and pstream in the registration of streamable ...
TStreamableClass(LPCSTR n, BUILDER b, int d=NoDelta, ModuleId mid=GetModuleId())
Creates a TStreamableClass object with the given name (n) and the given builder function (b),...
const ObjectBuilder * Lookup(ModuleId id, LPCSTR name) const
void UnRegisterType(ModuleId id, TStreamableClass &)
void RegisterType(ModuleId id, TStreamableClass &)
virtual LPCSTR StreamableName() const =0
This pure virtual member function must be redefined for every streamable class.
TXBase(const tstring &msg)
Calls the xmsg class's constructor that takes a string parameter and initializes xmsg with the value ...
void open(LPCSTR, int, int=openprot)
Opens the named file in the given mode (app, ate, in, out, binary, trunc, nocreate,...
void close()
Closes the stream and associated file.
void setbuf(LPSTR, int)
Sets the location of the buffer to buf and the buffer size to len.
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
std::streampos tellg()
Returns the (absolute) current stream position.
TStreamableBase * readObjectPointer(TStreamableBase *&mem, ModuleId mid=GetModuleId())
const ObjectBuilder * readPrefix(ModuleId mid)
Returns the TStreamableClass object corresponding to the class name stored at the current position in...
LPSTR readString()
Allocates a buffer large enough to contain the string at the current stream position and reads the st...
uint32 readWord32()
Returns the 32-bit word at the current stream position.
void readSuffix()
Reads and checks the suffix of the object.
void readVersion()
Reads the version number of the input stream.
void readData(const ObjectBuilder *, TStreamableBase *&)
If mem is 0, it calls the appropriate build function to allocate memory and initialize the virtual ta...
char * freadString()
Reads a string from the stream.
ipstream & seekg(std::streampos)
uint16 readWord16()
Returns the 16-bit word at the current stream position.
void freadBytes(void *data, size_t sz)
Reads the number of bytes specified by sz into the supplied buffer (data).
TStreamableBase * readObject(TStreamableBase *&mem, ModuleId mid=GetModuleId())
uint32 readWord()
Returns the word at the current stream position.
uint8 readByte()
Returns the byte at the current stream position.
void readBytes(void *, size_t)
Reads sz bytes from current stream position, and writes them to data.
Base class for writing streamable objects.
void writeWord16(uint16)
Writes the 16-bit word us to the stream.
opstream & flush()
Flushes the stream.
void writeString(const char *)
Writes str to the stream.
void fwriteBytes(const void *data, size_t sz)
Writes the specified number of bytes (sz) from the supplied buffer (data) to the stream.
void writeObject(const TStreamableBase *t, int isPtr=0, ModuleId mid=GetModuleId())
Writes the object, pointed to by t, to the output stream.
opstream(std::streambuf *)
void writeBytes(const void *, size_t)
Writes sz bytes from the data buffer to the stream.
void writeByte(uint8)
Writes the byte ch to the stream.
opstream()
Creates a buffered opstream with the given buffer and sets the bp data member to buf.
void fwriteString(const char *str)
Writes the specified far character string (str) to the stream.
void writeData(const TStreamableBase *, ModuleId mid)
Writes data to the stream by calling the write member function of the appropriate class for the objec...
opstream & seekp(std::streampos)
void writeWord32(uint32)
Writes the 32-bit word us to the stream.
void writeObjectPointer(const TStreamableBase *t, ModuleId mid=GetModuleId())
Writes the object pointer t to the output stream.
std::streampos tellp()
Returns the (absolute) current stream position.
void writePrefix(const TStreamableBase *)
Writes the class name prefix to the stream.
int good() const
Returns nonzero if no error states have been recorded for the stream (that is, no errors have occurre...
void registerObject(TStreamableBase *adr)
Registers the class of the object pointed to by adr.
void registerObject(TStreamableBase *adr)
Registers the object pointed to by adr.
P_id_type findObject(TStreamableBase *adr)
Returns the type ID for the object pointed to by adr.
void writeSuffix(const TStreamableBase *)
Writes the class name suffix to the stream.
void clear(int=0)
Sets the stream state to the given value (defaults to 0).
#define _OBJ_TYPENAME(obj)
void writeWord(uint32)
Writes the 32-bit word us to the stream.
uint32 getVersion() const
Returns the object version number.
TStreamableBase * find(P_id_type)
Returns a pointer to the object corresponding to Id.
#define _OBJ_FULLTYPENAME(obj)
ipstream(std::streambuf *)
Creates a buffered ipstream with the given buffer. The state is set to 0.
void init(std::streambuf *)
The init member function initializes the stream and sets state to 0 and bp to sbp.
Reliable platform independent header for common memory and string functions.
char * strnewdup(const char *s, size_t minAllocSize=0)
Object Windows Library (OWLNext Core).
TStreamer *(*) BUILDER(TStreamableBase *)
owl::opstream & operator<<(owl::opstream &os, const TColor &c)
Insert the color value into a persistent output stream.
class _OWLFASTTHIS _RTTI TStreamableBase
DIAG_DEFINE_GROUP_INIT(OWL_INI, OwlApp, 1, 0)
owl::ipstream & operator>>(owl::ipstream &is, TColor &c)
Extract the color value from a persistent input stream.
General definitions used by all ObjectWindows programs.
ObjectWindows exception class & function definitions.
#define CONST_CAST(targetType, object)
Various types of smart pointer templatized classes.
Class definitions for object streaming.
ObjectBuilder(BUILDER b, int d)
Definition of container classes used and made available by OWL.