1
// ---------------------------------------------------------------------------
3
// - standard object library - base object declaration -
4
// ---------------------------------------------------------------------------
5
// - This program is free software; you can redistribute it and/or modify -
6
// - it provided that this copyright notice is kept intact. -
8
// - This program is distributed in the hope that it will be useful, but -
9
// - without any warranty; without even the implied warranty of -
10
// - merchantability or fitness for a particular purpose. In no event shall -
11
// - the copyright holder be liable for any direct, indirect, incidental or -
12
// - special damages arising in any way out of the use of this software. -
13
// ---------------------------------------------------------------------------
14
// - copyright (c) 1999-2007 amaury darsch -
15
// ---------------------------------------------------------------------------
17
#ifndef AFNIX_OBJECT_HPP
18
#define AFNIX_OBJECT_HPP
20
#ifndef AFNIX_CCNF_HPP
26
/// The Object class is the foundation of the standard object library .
27
/// The object class defines a reference count ana a shared control
28
/// structure. The reference count field is used to control the life of
29
/// a particular object. When an object is created, the reference count
30
/// is set to 0. Such object is said to be transient. The "iref" static
31
/// method increments the reference count. The "dref" method decrements
32
/// and eventually destroy the object. The "cref" method eventually destroy
33
/// an object if its reference count is null. The object class is an
34
/// abstract class. For each derived object, the "repr" method
35
/// is defined to return the class name. Additionally, the object class
36
/// defines a set of methods which are used by the runnable to virtually
37
/// modify or evaluate an object. There are two sets of methods. The first
38
/// set operates directly on the object. The second set operates by name
39
/// on the object. Working by name is equivalent to access a member of a
40
/// a particular object. The "cdef" method creates or set a constant object
41
/// to the calling object. The "vdef" method create or set an object to the
42
/// calling object. The "eval" method evaluates an object in the current
43
/// runnable nameset. The "apply" method evaluates a set of arguments
44
/// and apply them to the calling object. It is somehow equivalent to a
45
/// function call. When called by name, it is equivalent to a method call.
46
/// @author amaury darsch
50
/// the operator enumeration
65
/// increment the object reference count
66
/// @param object the object to process
67
static Object* iref (Object* object);
69
/// decrement the reference count and destroy the object if null
70
/// @param object the object to process
71
static void dref (Object* object);
73
/// clean this object if the reference count is null
74
/// @param object the object to process
75
static void cref (Object* object);
77
/// decrement the object reference count but do not detroy if null
78
/// @param object the object to process
79
static void tref (Object* object);
81
/// return true if the object has a reference count of 0 or 1
82
/// @param object the object to process
83
static bool uref (Object* object);
86
/// object reference count
90
/// the shared object structure
91
struct s_shared* p_shared;
94
/// create a new object
97
/// destroy this object.
98
virtual ~Object (void);
100
/// @return the class name
101
virtual class String repr (void) const =0;
103
/// @return an object class name or nil
104
static const class String repr (Object* object);
106
/// @return a clone of this object
107
virtual Object* clone (void) const;
109
/// make this object shared
110
virtual void mksho (void);
112
/// clean the shared structure
113
virtual void rmsho (void);
115
/// @return true if the object is shared
116
virtual bool issho (void) const;
118
/// get a read lock for this object
119
virtual void rdlock (void) const;
121
/// get a write lock for this object
122
virtual void wrlock (void) const;
124
/// unlock this object
125
virtual void unlock (void) const;
127
/// @return the minimal object associated with this one
128
virtual Object* mini (void) const;
130
/// @return true if the given quark is defined
131
virtual bool isquark (const long quark, const bool hflg) const;
133
/// operate this object with another one
134
/// @param type the operator type
135
/// @param object the operand object
136
virtual Object* oper (t_oper type, Object* object);
138
/// set an object as a const object
139
/// @param robj the current runnable
140
/// @param nset the current nameset
141
/// @param object the object to set
142
virtual Object* cdef (class Runnable* robj, class Nameset* nset,
145
/// set an object as a const object by quark
146
/// @param robj the current runnable
147
/// @param nset the current nameset
148
/// @param quark the quark to define as const
149
/// @param object the object to set
150
virtual Object* cdef (class Runnable* robj, class Nameset* nset,
151
const long quark, Object* object);
153
/// set an object to this object
154
/// @param robj the current runnable
155
/// @param nset the current nameset
156
/// @param object the object to set
157
virtual Object* vdef (class Runnable* robj, class Nameset* nset,
160
/// set an object to this object by quark
161
/// @param robj the current runnable
162
/// @param nset the current nameset
163
/// @param quark the quark to set this object
164
/// @param object the object to set
165
virtual Object* vdef (class Runnable* robj, class Nameset* nset,
166
const long quark, Object* object);
168
/// evaluate an object in the current nameset
169
/// @param robj the current runnable
170
/// @param nset the current nameset
171
virtual Object* eval (class Runnable* robj, class Nameset* nset);
173
/// evaluate an object in the current nameset by quark
174
/// @param robj the current runnable
175
/// @param nset the current nameset
176
/// @param quark the quark to evaluate in this object
177
virtual Object* eval (class Runnable* robj, class Nameset* nset,
180
/// apply an object with a set of arguments
181
/// @param robj the current runnable
182
/// @param nset the current nameset
183
/// @param args the arguments to apply
184
virtual Object* apply (class Runnable* robj, class Nameset* nset,
187
/// apply an object by quark with a set of arguments
188
/// @param robj the current runnable
189
/// @param nset the current nameset
190
/// @param quark the quark to apply this arguments
191
/// @param args the arguments to apply
192
virtual Object* apply (class Runnable* robj, class Nameset* nset,
193
const long quark, class Cons* args);
195
/// apply an object by object with a set of arguments
196
/// @param robj the current runnable
197
/// @param nset the current nameset
198
/// @param object the object to apply this arguments
199
/// @param args the arguments to apply
200
virtual Object* apply (class Runnable* robj, class Nameset* nset,
201
Object* object, class Cons* args);
203
/// apply an object by object with a vector of arguments
204
/// @param robj the current runnable
205
/// @param nset the current nameset
206
/// @param object the object to apply this arguments
207
/// @param argv the vector arguments to apply
208
virtual Object* apply (class Runnable* robj, class Nameset* nset,
209
Object* object, class Vector* argv);
211
/// apply an object with a vector of arguments by quark
212
/// @param robj the current runnable
213
/// @param nset the current nameset
214
/// @param quark the quark to apply these arguments
215
/// @param argv the vector arguments to apply
216
virtual Object* apply (class Runnable* robj, class Nameset* nset,
217
const long quark, class Vector* argv);
220
// the memory allocation
221
void* operator new (const t_size size);
222
void* operator new [] (const t_size size);
223
void operator delete (void* handle);
224
void operator delete [] (void* handle);
225
// the memory debug (for internal use please...)
226
static void setmdbg (const bool flag);