Dillo v3.1.1-14-g8f67d6e0
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:566
An object::Object wrapper for bool's.
Definition object.hh:144
int compareTo(Comparable *other)
Compare two objects, this and other.
Definition object.cc:235
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:230
int hashValue()
Return a hash value for the object.
Definition object.cc:225
bool equals(Object *other)
Returns, whether two objects are equal.
Definition object.cc:218
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:127
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:254
void intoStringBuffer(misc::StringBuffer *sb)
Store a textual representation of the object in a misc::StringBuffer.
Definition object.cc:285
bool equals(Object *other)
Returns, whether two objects are equal.
Definition object.cc:244
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:260
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:202
int compareTo(Comparable *other)
Compare two objects, this and other.
Definition object.cc:209
bool equals(Object *other)
Returns, whether two objects are equal.
Definition object.cc:192
int hashValue()
Return a hash value for the object.
Definition object.cc:197
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:68
virtual size_t sizeOf()
Return the number of bytes, this object totally uses.
Definition object.cc:105
virtual ~Object()
The destructor is defined as virtual (but not abstract), so that destruction of Object's works proper...
Definition object.cc:39
virtual void intoStringBuffer(misc::StringBuffer *sb)
Store a textual representation of the object in a misc::StringBuffer.
Definition object.cc:95
const char * toString()
Use object::Object::intoStringBuffer to return a textual representation of the object.
Definition object.cc:81
virtual int hashValue()
Return a hash value for the object.
Definition object.cc:59
virtual bool equals(Object *other)
Returns, whether two objects are equal.
Definition object.cc:50
size_t sizeOf()
Return the number of bytes, this object totally uses.
Definition object.cc:371
int hashValue()
Return a hash value for the object.
Definition object.cc:340
void intoStringBuffer(misc::StringBuffer *sb)
Store a textual representation of the object in a misc::StringBuffer.
Definition object.cc:352
bool equals(Object *other)
Returns, whether two objects are equal.
Definition object.cc:322
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:159
Pointer(void *value)
Definition object.hh:105
bool equals(Object *other)
Returns, whether two objects are equal.
Definition object.cc:154
void intoStringBuffer(misc::StringBuffer *sb)
Store a textual representation of the object in a misc::StringBuffer.
Definition object.cc:181
int compare(Object *o1, Object *o2)
Compare two objects o1 and o2.
Definition object.cc:136
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:148