Dillo v3.1.1-117-gc0464026
Loading...
Searching...
No Matches
object.hh
Go to the documentation of this file.
1#ifndef __LOUT_OBJECT_HH__
2#define __LOUT_OBJECT_HH__
3
4#include <stdlib.h>
5#include <string.h>
6
7#include "misc.hh"
8
9namespace lout {
10
15namespace object {
16
24class Object
25{
26public:
27 virtual ~Object();
28 virtual bool equals(Object *other);
29 virtual int hashValue();
30 virtual Object *clone();
31 virtual void intoStringBuffer(misc::StringBuffer *sb);
32 const char *toString();
33 virtual size_t sizeOf();
34};
35
41class Comparable: public Object
42{
43public:
58 virtual int compareTo(Comparable *other) = 0;
59};
60
66class Comparator: public Object
67{
68public:
82 virtual int compare(Object *o1, Object *o2) = 0;
83
85 static int compareFun(const void *p1, const void *p2);
86};
87
89{
90public:
91 int compare(Object *o1, Object *o2);
92};
93
95
99class Pointer: public Object
100{
101private:
102 void *value;
103
104public:
105 Pointer(void *value) { this->value = value; }
106 bool equals(Object *other);
107 int hashValue();
109 inline void *getValue() { return value; }
110};
111
115template <class T> class TypedPointer: public Pointer
116{
117public:
118 inline TypedPointer(T *value) : Pointer ((void*)value) { }
119 inline T *getTypedValue() { return (T*)getValue(); }
120};
121
122
126class Integer: public Comparable
127{
128 int value;
129
130public:
131 Integer(int value) { this->value = value; }
132 bool equals(Object *other);
133 int hashValue();
135 int compareTo(Comparable *other);
136 inline int getValue() { return value; }
137};
138
139
143class Boolean: public Comparable
144{
145 bool value;
146
147public:
148 Boolean(bool value) { this->value = value; }
149 bool equals(Object *other);
150 int hashValue();
152 int compareTo(Comparable *other);
153 inline bool getValue() { return value; }
154};
155
156
163{
164protected:
165 const char *str;
166
167public:
168 ConstString(const char *str) { this->str = str; }
169 bool equals(Object *other);
170 int hashValue();
171 int compareTo(Comparable *other);
173
174 inline const char *chars() { return str; }
175
176 static int hashValue(const char *str);
177};
178
179
185class String: public ConstString
186{
187public:
188 String(const char *str);
189 ~String();
190};
191
195class PairBase: public Object
196{
197protected:
199
200public:
202 ~PairBase();
203
204 bool equals(Object *other);
205 int hashValue();
207 size_t sizeOf();
208};
209
213class Pair: public PairBase
214{
215public:
217
218 inline Object *getFirst () { return first; }
219 inline Object *getSecond () { return second; }
220};
221
225template <class F, class S> class TypedPair: public PairBase
226{
227public:
229
230 inline F *getFirst () { return first; }
231 inline S *getSecond () { return second; }
232};
233
234} // namespace object
235
236} // namespace lout
237
238#endif // __LOUT_OBJECT_HH__
A class for fast concatenation of a large number of strings.
Definition misc.hh:570
An object::Object wrapper for bool's.
Definition object.hh:144
int compareTo(Comparable *other)
Compare two objects, this and other.
Definition object.cc:236
Boolean(bool value)
Definition object.hh:148
void intoStringBuffer(misc::StringBuffer *sb)
Store a textual representation of the object in a misc::StringBuffer.
Definition object.cc:231
int hashValue()
Return a hash value for the object.
Definition object.cc:226
bool equals(Object *other)
Returns, whether two objects are equal.
Definition object.cc:219
Instances of a sub class of may be compared (less, greater).
Definition object.hh:42
virtual int compareTo(Comparable *other)=0
Compare two objects, this and other.
Used for other orders as the one defined by Comparable.
Definition object.hh:67
static int compareFun(const void *p1, const void *p2)
This static method may be used as compare function for qsort(3) and bsearch(3), for an array of Objec...
Definition object.cc:128
static Comparator * compareFunComparator
Definition object.hh:84
virtual int compare(Object *o1, Object *o2)=0
Compare two objects o1 and o2.
An object::Object wrapper for constant strings (char*).
Definition object.hh:163
int hashValue()
Return a hash value for the object.
Definition object.cc:255
void intoStringBuffer(misc::StringBuffer *sb)
Store a textual representation of the object in a misc::StringBuffer.
Definition object.cc:286
bool equals(Object *other)
Returns, whether two objects are equal.
Definition object.cc:245
ConstString(const char *str)
Definition object.hh:168
const char * chars()
Definition object.hh:174
int compareTo(Comparable *other)
Compare two objects, this and other.
Definition object.cc:261
An object::Object wrapper for int's.
Definition object.hh:127
Integer(int value)
Definition object.hh:131
void intoStringBuffer(misc::StringBuffer *sb)
Store a textual representation of the object in a misc::StringBuffer.
Definition object.cc:203
int compareTo(Comparable *other)
Compare two objects, this and other.
Definition object.cc:210
bool equals(Object *other)
Returns, whether two objects are equal.
Definition object.cc:193
int hashValue()
Return a hash value for the object.
Definition object.cc:198
This is the base class for many other classes, which defines very common virtual methods.
Definition object.hh:25
virtual Object * clone()
Return an exact copy of the object.
Definition object.cc:69
virtual size_t sizeOf()
Return the number of bytes, this object totally uses.
Definition object.cc:106
virtual ~Object()
The destructor is defined as virtual (but not abstract), so that destruction of Object's works proper...
Definition object.cc:40
virtual void intoStringBuffer(misc::StringBuffer *sb)
Store a textual representation of the object in a misc::StringBuffer.
Definition object.cc:96
const char * toString()
Use object::Object::intoStringBuffer to return a textual representation of the object.
Definition object.cc:82
virtual int hashValue()
Return a hash value for the object.
Definition object.cc:60
virtual bool equals(Object *other)
Returns, whether two objects are equal.
Definition object.cc:51
size_t sizeOf()
Return the number of bytes, this object totally uses.
Definition object.cc:372
int hashValue()
Return a hash value for the object.
Definition object.cc:341
void intoStringBuffer(misc::StringBuffer *sb)
Store a textual representation of the object in a misc::StringBuffer.
Definition object.cc:353
bool equals(Object *other)
Returns, whether two objects are equal.
Definition object.cc:323
Pair(Object *first, Object *second)
Definition object.hh:216
Object * getFirst()
Definition object.hh:218
Object * getSecond()
Definition object.hh:219
An object::Object wrapper for void pointers.
Definition object.hh:100
int hashValue()
Return a hash value for the object.
Definition object.cc:160
Pointer(void *value)
Definition object.hh:105
bool equals(Object *other)
Returns, whether two objects are equal.
Definition object.cc:155
void intoStringBuffer(misc::StringBuffer *sb)
Store a textual representation of the object in a misc::StringBuffer.
Definition object.cc:182
int compare(Object *o1, Object *o2)
Compare two objects o1 and o2.
Definition object.cc:137
An object::Object wrapper for strings (char*).
Definition object.hh:186
TypedPair(F *first, S *second)
Definition object.hh:228
A typed version of object::Pointer.
Definition object.hh:116
#define F(x, y, z)
StandardComparator standardComparator
Definition object.cc:149