wavelength 1.0.0
Loading...
Searching...
No Matches
rndobject.h
Go to the documentation of this file.
1#pragma once
2
3#include <list>
4
5#include "os/binstream.h"
6#include "os/prnstream.h"
7#include "os/string.h"
8
20class RndObject {
21public:
31 explicit RndObject(const char *pszName);
32
42 virtual ~RndObject();
43
53 virtual void DumpText(PrnStream &stream);
54
60 virtual void Save(BinStream &stream) = 0;
61
70 virtual void Replace(RndObject *pFrom, RndObject *pTo) = 0;
71
77 virtual const char *ClassName() const = 0;
78
85 virtual void Copy(const RndObject *pSource, int nFlags) = 0;
86
92 virtual void Load(BinStream &stream) = 0;
93
104 void SetName(const char *pszName);
105
115 void AddRef(RndObject *pReferrer);
116
127 void RemoveRef(RndObject *pReferrer);
128
130 static constexpr int kCopyChildLists = 0x200;
131
133 const char *GetName() const {
134 return mName.c_str();
135 }
136
138 const std::list<RndObject *> &GetRefs() const {
139 return mRefs;
140 }
141
143 int GetInternal() const {
144 return mInternal;
145 }
146
148 void SetInternal(int nInternal) {
149 mInternal = nInternal;
150 }
151
152protected:
153 std::list<RndObject *> mRefs;
155
156private:
157 int mInternal;
158 int mDeleting;
159};
160
170PrnStream &operator<<(PrnStream &stream, const RndObject *pObject);
Stream of raw bytes, the base of the memory, file, and network streams.
Definition binstream.h:22
Text output stream.
Definition prnstream.h:16
Base of every object the renderer can load, resolve by name, and serialise.
Definition rndobject.h:20
RndObject(const char *pszName)
Construct an object and register it under a name.
virtual void DumpText(PrnStream &stream)
Write a description of the object.
void SetName(const char *pszName)
Register the object under a different name.
void RemoveRef(RndObject *pReferrer)
Drop the first registration AddRef() made for a referrer.
virtual const char * ClassName() const =0
Report the name of the object's most derived class.
std::list< RndObject * > mRefs
Definition rndobject.h:153
virtual void Copy(const RndObject *pSource, int nFlags)=0
Copy the state of another object into this one.
void SetInternal(int nInternal)
Definition rndobject.h:148
const std::list< RndObject * > & GetRefs() const
Definition rndobject.h:138
virtual void Save(BinStream &stream)=0
Write the object's serialised form.
static constexpr int kCopyChildLists
The bit of the Copy() flags that copies the child lists of the mix-ins.
Definition rndobject.h:130
int GetInternal() const
Definition rndobject.h:143
virtual void Replace(RndObject *pFrom, RndObject *pTo)=0
Replace every stored pointer to one object with another.
String mName
Definition rndobject.h:154
void AddRef(RndObject *pReferrer)
Register an object as a store of a pointer to this one.
const char * GetName() const
Definition rndobject.h:133
virtual ~RndObject()
Notify every referrer, then erase the registration.
virtual void Load(BinStream &stream)=0
Read the object's serialised form.
Growable text buffer that is also a PrnStream.
Definition string.h:19
PrnStream & operator<<(PrnStream &stream, const RndObject *pObject)
Write an object's name, or "no object" for null.