15#if defined(BI_MULTI_THREAD_RTL)
22#if defined(__BORLANDC__)
52#if defined(BI_MULTI_THREAD_RTL)
56 static TMRSWSection
lock;
60#define LOCK_TYPES_(s) TMRSWSection::TLock lock__(GetLock_(), s, false)
70class TStreamableBaseArray:
public TPtrArray<TStreamableBase*>{
73 TStreamableBaseArray(){}
76class TStreamableClassArray:
public TISortedPtrArray<TStreamableClass*>{
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;
98int TStreamableClassArray::Add(TStreamableClass* t)
107 Data[
loc] = (TStreamableClass*)t;
110int TStreamableClassArray::Find(TStreamableClass* t)
const
113 auto upper =
static_cast<int>(
Size()) - 1;
131class TSortedTPWObjObjectArray
135 TSortedTPWObjObjectArray(
int = 0) {}
137 void Flush() { m_Items.clear(); }
138 void Add(TPWrittenObjects::TPWObj
obj) { m_Items.insert(
obj); }
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;
200 GetTypes_().UnRegisterType(ModId, *
this);
207 Types =
new TStreamableClassArray(30);
228 Types->DetachItem(&
ts);
236 const auto loc = Types->Find(&
sc);
242 msg =
_T(
"Attempt to stream unregistered type '");
247 return (*Types)[
loc];
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));
308 return Data->Find(TPWObj(((
tchar*)(
void*)
d)+1,0));
313 return Data->Find(TPWObj(
d,0));
327 res =
bp->pubseekoff(0, ios::cur, ios::in );
329 clear( ios::failbit );
341 clear( ios::failbit );
362 clear( ios::failbit );
376 clear( ios::failbit );
387 if(
bp->sgetn( (
char*)
data,
sz ) !=
static_cast<int>(
sz) )
388 clear( ios::failbit );
400 if(
bp->sgetn( (
char*)buf,
sz ) !=
static_cast<int>(
sz))
401 clear( ios::failbit );
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()
545 int res =
bp->sgetc();
547 clear( ios::eofbit );
581 clear( ios::failbit );
589 clear( ios::failbit );
600 clear( ios::failbit );
633 clear( ios::failbit );
660 clear( ios::failbit );
691 res =
bp->pubseekoff(0, ios::cur, ios::out );
693 clear( ios::failbit );
706 streampos p =
bp->pubseekoff((ios::off_type)
pos, (ios::seekdir)ios::beg,
707 (ios::openmode)ios::out);
710 clear( ios::failbit );
731 clear( ios::failbit );
747 if(
bp->pubsync() ==
EOF )
748 clear( ios::badbit );
757 clear( ios::failbit );
767 if(
bp->sputn( (
char*)
data,
sz ) !=
static_cast<int>(
sz) )
768 clear( ios::failbit );
777 static_cast<int>(
sizeof(
word16)) )
778 clear( ios::failbit );
787 static_cast<int>(
sizeof(
word32)) )
788 clear( ios::failbit );
799 char* buf =
new char[
sz];
802 if(
bp->sputn( (
char*)buf,
sz ) !=
static_cast<int>(
sz) )
803 clear( ios::failbit );
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) )
957 os.writeString(
_W2A(str.c_str()) );
#define WARNX(group, condition, level, message)
#define PRECONDITION(condition)
#define CHECKX(condition, message)
#define TRACEX(group, level, message)
#define DIAG_DEFINE_GROUP_INIT(f, g, e, l)
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.
Derived from xmsg, TXBase is the base class for ObjectWindows and ObjectComponents exception-handling...
virtual void Throw()
Throws the exception object.
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.
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)
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)
owl::opstream & operator<<(owl::opstream &os, const TColor &c)
Insert the color value into a persistent output stream.
class _OWLFASTTHIS _RTTI TStreamableBase
TStreamer *(* BUILDER)(TStreamableBase *)
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.
Definition of container classes used and made available by OWL.