Dillo v3.2.0-88-g47ab7c70
Loading...
Searching...
No Matches
object.hh
Go to the documentation of this file.
1/*
2 * Dillo Widget
3 *
4 * Copyright 2005-2007 Sebastian Geerken <sgeerken@dillo.org>
5 * Copyright 2025 Rodrigo Arias Mallo <rodarima@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef __LOUT_OBJECT_HH__
22#define __LOUT_OBJECT_HH__
23
24#include <stdlib.h>
25#include <string.h>
26
27#include "misc.hh"
28
29namespace lout {
30
35namespace object {
36
44class Object
45{
46public:
47 virtual ~Object();
48 virtual bool equals(Object *other);
49 virtual int hashValue();
50 virtual Object *clone();
51 virtual void intoStringBuffer(misc::StringBuffer *sb);
52 char *toString();
53 virtual size_t sizeOf();
54};
55
61class Comparable: public Object
62{
63public:
78 virtual int compareTo(Comparable *other) = 0;
79};
80
86class Comparator: public Object
87{
88public:
102 virtual int compare(Object *o1, Object *o2) = 0;
103
105 static int compareFun(const void *p1, const void *p2);
106};
107
109{
110public:
111 int compare(Object *o1, Object *o2);
112};
113
115
119class Pointer: public Object
120{
121private:
122 void *value;
123
124public:
125 Pointer(void *value) { this->value = value; }
126 bool equals(Object *other);
127 int hashValue();
129 inline void *getValue() { return value; }
130};
131
135template <class T> class TypedPointer: public Pointer
136{
137public:
138 inline TypedPointer(T *value) : Pointer ((void*)value) { }
139 inline T *getTypedValue() { return (T*)getValue(); }
140};
141
142
146class Integer: public Comparable
147{
148 int value;
149
150public:
151 Integer(int value) { this->value = value; }
152 bool equals(Object *other);
153 int hashValue();
155 int compareTo(Comparable *other);
156 inline int getValue() { return value; }
157};
158
159
163class Boolean: public Comparable
164{
165 bool value;
166
167public:
168 Boolean(bool value) { this->value = value; }
169 bool equals(Object *other);
170 int hashValue();
172 int compareTo(Comparable *other);
173 inline bool getValue() { return value; }
174};
175
176
183{
184protected:
185 const char *str;
186
187public:
188 ConstString(const char *str) { this->str = str; }
189 bool equals(Object *other);
190 int hashValue();
191 int compareTo(Comparable *other);
193
194 inline const char *chars() { return str; }
195
196 static int hashValue(const char *str);
197};
198
199
205class String: public ConstString
206{
207public:
208 String(const char *str);
209 ~String();
210};
211
215class PairBase: public Object
216{
217protected:
219
220public:
222 ~PairBase();
223
224 bool equals(Object *other);
225 int hashValue();
227 size_t sizeOf();
228};
229
233class Pair: public PairBase
234{
235public:
237
238 inline Object *getFirst () { return first; }
239 inline Object *getSecond () { return second; }
240};
241
245template <class F, class S> class TypedPair: public PairBase
246{
247public:
249
250 inline F *getFirst () { return first; }
251 inline S *getSecond () { return second; }
252};
253
254} // namespace object
255
256} // namespace lout
257
258#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:164
int compareTo(Comparable *other)
Compare two objects, this and other.
Definition object.cc:236
Boolean(bool value)
Definition object.hh:168
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:62
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:87
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:104
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:183
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:188
const char * chars()
Definition object.hh:194
int compareTo(Comparable *other)
Compare two objects, this and other.
Definition object.cc:261
An object::Object wrapper for int's.
Definition object.hh:147
Integer(int value)
Definition object.hh:151
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:45
virtual Object * clone()
Return an exact copy of the object.
Definition object.cc:70
char * toString()
Use object::Object::intoStringBuffer to return a textual representation of the object.
Definition object.cc:83
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:41
virtual void intoStringBuffer(misc::StringBuffer *sb)
Store a textual representation of the object in a misc::StringBuffer.
Definition object.cc:96
virtual int hashValue()
Return a hash value for the object.
Definition object.cc:61
virtual bool equals(Object *other)
Returns, whether two objects are equal.
Definition object.cc:52
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:236
Object * getFirst()
Definition object.hh:238
Object * getSecond()
Definition object.hh:239
An object::Object wrapper for void pointers.
Definition object.hh:120
int hashValue()
Return a hash value for the object.
Definition object.cc:160
Pointer(void *value)
Definition object.hh:125
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:206
TypedPair(F *first, S *second)
Definition object.hh:248
A typed version of object::Pointer.
Definition object.hh:136
#define F(x, y, z)
StandardComparator standardComparator
Definition object.cc:149