libUTL++
Object.h
1 #pragma once
2 
4 
5 UTL_NS_BEGIN;
6 
8 
9 class Stream;
10 class String;
11 
13 
50 
52 class Object
53 {
56 
57 public:
59  void clear();
60 
70  virtual int compare(const Object& rhs) const;
71 
77  virtual void copy(const Object& rhs);
78 
84  virtual void vclone(const Object& rhs);
85 
90  virtual void steal(Object& rhs);
91 
98  virtual void dump(Stream& os, uint_t level = uint_t_max) const;
99 
106  void dumpWithClassName(Stream& os, uint_t indent = 4, uint_t level = uint_t_max) const;
107 
116  virtual const Object& getKey() const;
117 
123  bool
124  hasKey() const
125  {
126  return (&(getKey()) != this);
127  }
128 
130  virtual const Object& getProxiedObject() const;
131 
133  virtual Object& getProxiedObject();
134 
141  virtual size_t hash(size_t size) const;
142 
150  bool
151  _isA(const RunTimeClass* runTimeClass) const
152  {
153  return getClass()->_isA(runTimeClass);
154  }
155 
157 
158 
163  void
165  {
166  serialize(is, io_rd, mode);
167  }
168 
174  void
176  {
177  const_cast_this->serialize(os, io_wr, mode);
178  }
179 
188  virtual void serialize(Stream& stream, uint_t io, uint_t mode = ser_default);
189 
197  static Object* serializeInNullable(Stream& is, uint_t mode = ser_default);
198 
206  static void serializeOutNullable(const Object* object, Stream& os, uint_t mode = ser_default);
207 
216  static void
217  serializeNullable(Object*& object, Stream& stream, uint_t io, uint_t mode = ser_default);
218 
226  static Object* serializeInBoxed(Stream& is, uint_t mode = ser_default);
227 
234  void serializeOutBoxed(Stream& os, uint_t mode = ser_default) const;
235 
243  static void
244  serializeBoxed(Object*& object, Stream& stream, uint_t io, uint_t mode = ser_default)
245  {
246  if (io == io_rd)
247  object = serializeInBoxed(stream, mode);
248  else
249  object->serializeOutBoxed(stream, mode);
250  }
252 
254  virtual String toString() const;
255 
257  operator String() const;
258 
260  size_t allocatedSize() const;
261 
263  virtual size_t innerAllocatedSize() const;
264 
266 
267 
268  bool operator<(const Object& rhs) const
269  {
270  return (compare(rhs) < 0);
271  }
273  bool operator<=(const Object& rhs) const
274  {
275  return (compare(rhs) <= 0);
276  }
278  bool operator>(const Object& rhs) const
279  {
280  return (compare(rhs) > 0);
281  }
283  bool operator>=(const Object& rhs) const
284  {
285  return (compare(rhs) >= 0);
286  }
288  bool operator==(const Object& rhs) const
289  {
290  return (compare(rhs) == 0);
291  }
293  bool operator!=(const Object& rhs) const
294  {
295  return (compare(rhs) != 0);
296  }
298 
299 #ifdef DEBUG
300 
301  virtual void addOwnedIt(const class FwdIt* it) const;
302 
304  virtual void removeOwnedIt(const class FwdIt* it) const;
305 #endif
306 };
307 
309 
310 UTL_NS_END;
size_t allocatedSize(const Object *object)
Compute the allocated size of an object.
Definition: util_inl.h:191
void serializeIn(Stream &is, uint_t mode=ser_default)
Serialize from an input stream.
Definition: Object.h:164
#define UTL_CLASS_DEFID
Default init() and deInit() (which are merely place-holders).
Definition: macros.h:532
String toString(const FwdIt &begin, const FwdIt &end, const String &sep, bool key=false)
Obtain a string representation of a sequence (via Object::toString()).
void serialize(bool &b, Stream &stream, uint_t io, uint_t mode=ser_default)
Serialize a boolean.
#define const_cast_this
Pointer to the object the method was invoked on (casting away const).
Definition: macros.h:41
bool operator<(const Object &rhs) const
Less-than operator.
Definition: Object.h:268
bool hasKey() const
Determine whether or not the object has a key.
Definition: Object.h:124
bool _isA(const RunTimeClass *runTimeClass) const
Determine whether self&#39;s class is a descendent of the given class.
Definition: Object.h:151
static void serializeBoxed(Object *&object, Stream &stream, uint_t io, uint_t mode=ser_default)
Serialize a boxed object to or from a stream.
Definition: Object.h:244
default representation (via getSerializeMode())
Definition: util.h:75
Store information about a class.
Definition: RunTimeClass.h:23
Character string.
Definition: String.h:31
write
Definition: util.h:59
void copy(T *dest, const T *src, size_t len)
Copy one array of objects to another.
Definition: util_inl.h:690
bool operator!=(const Object &rhs) const
Unequal-to operator.
Definition: Object.h:293
read
Definition: util.h:58
Forward iterator abstraction.
Definition: FwdIt.h:26
void serializeOut(Stream &os, uint_t mode=ser_default) const
Serialize to an output stream.
Definition: Object.h:175
#define UTL_CLASS_DECL_ABC(DC, BC)
Declaration of standard UTL++ functionality for an abstract base class (ABC).
Definition: macros.h:650
bool operator==(const Object &rhs) const
Equal-to operator.
Definition: Object.h:288
unsigned int uint_t
Unsigned integer.
Definition: types.h:59
bool operator<=(const Object &rhs) const
Less-than-or-equal-to operator.
Definition: Object.h:273
const uint_t uint_t_max
Maximum uint_t value.
Stream I/O abstraction.
Definition: Stream.h:68
bool operator>(const Object &rhs) const
Greater-than operator.
Definition: Object.h:278
void serializeNullable(T *&object, Stream &stream, uint_t io, uint_t mode=ser_default)
Serialize a nullable object.
Definition: util_inl.h:825
Root of UTL++ class hierarchy.
Definition: Object.h:52
int compare(bool lhs, bool rhs)
Compare two boolean values.
bool operator>=(const Object &rhs) const
Greater-than-or-equal-to operator.
Definition: Object.h:283
void dump(const FwdIt &begin, const FwdIt &end, Stream &os, uint_t level=uint_t_max, bool key=false, bool printClassName=false, uint_t indent=0, const char *separator=nullptr)
Dump objects to the given stream (with Object::dump()).