~ubuntu-branches/ubuntu/wily/afnix/wily

« back to all changes in this revision

Viewing changes to src/lib/std/shl/obj/Object.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2011-03-16 21:31:18 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110316213118-gk4k3ez3e5d2huna
Tags: 2.0.0-1
* QA upload.
* New upstream release
* Debian source format is 3.0 (quilt)
* Fix debhelper-but-no-misc-depends
* Fix ancient-standards-version
* Fix package-contains-linda-override
* debhelper compatibility is 7
* Fix dh-clean-k-is-deprecated

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// ---------------------------------------------------------------------------
2
 
// - Object.hpp                                                              -
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.                  -
7
 
// -                                                                         -
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
 
// ---------------------------------------------------------------------------
16
 
 
17
 
#ifndef  AFNIX_OBJECT_HPP
18
 
#define  AFNIX_OBJECT_HPP
19
 
 
20
 
#ifndef  AFNIX_CCNF_HPP
21
 
#include "ccnf.hpp"
22
 
#endif
23
 
 
24
 
namespace afnix {
25
 
 
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
47
 
 
48
 
  class Object {
49
 
  public:
50
 
    /// the operator enumeration
51
 
    enum t_oper {
52
 
      ADD, // add 
53
 
      SUB, // subtract
54
 
      MUL, // multiply
55
 
      DIV, // divide
56
 
      UMN, // unary minus
57
 
      EQL, // equal
58
 
      NEQ, // not equal
59
 
      GEQ, // greater equal
60
 
      LEQ, // less equal
61
 
      GTH, // greater than
62
 
      LTH  // less than
63
 
    };
64
 
 
65
 
    /// increment the object reference count
66
 
    /// @param object the object to process
67
 
    static Object* iref (Object* object);
68
 
 
69
 
    /// decrement the reference count and destroy the object if null
70
 
    /// @param object the object to process
71
 
    static void dref (Object* object);
72
 
 
73
 
    /// clean this object if the reference count is null
74
 
    /// @param object the object to process
75
 
    static void cref (Object* object);
76
 
 
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);
80
 
 
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);
84
 
 
85
 
  private:
86
 
    /// object reference count
87
 
    long d_rcount;
88
 
 
89
 
  protected:
90
 
    /// the shared object structure
91
 
    struct s_shared* p_shared;
92
 
 
93
 
  public:
94
 
    /// create a new object
95
 
    Object (void);
96
 
 
97
 
    /// destroy this object.
98
 
    virtual ~Object (void);
99
 
 
100
 
    /// @return the class name
101
 
    virtual class String repr (void) const =0;
102
 
 
103
 
    /// @return an object class name or nil
104
 
    static const class String repr (Object* object);
105
 
      
106
 
    /// @return a clone of this object
107
 
    virtual Object* clone (void) const;
108
 
 
109
 
    /// make this object shared
110
 
    virtual void mksho (void);
111
 
 
112
 
    /// clean the shared structure
113
 
    virtual void rmsho (void);
114
 
 
115
 
    /// @return true if the object is shared
116
 
    virtual bool issho (void) const;
117
 
 
118
 
    /// get a read lock for this object
119
 
    virtual void rdlock (void) const;
120
 
 
121
 
    /// get a write lock for this object
122
 
    virtual void wrlock (void) const;
123
 
 
124
 
    /// unlock this object
125
 
    virtual void unlock (void) const;
126
 
 
127
 
    /// @return the minimal object associated with this one
128
 
    virtual Object* mini (void) const;
129
 
 
130
 
    /// @return true if the given quark is defined
131
 
    virtual bool isquark (const long quark, const bool hflg) const;
132
 
 
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);
137
 
 
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, 
143
 
                          Object* object);
144
 
 
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);
152
 
 
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, 
158
 
                          Object* object);
159
 
 
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);
167
 
 
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);
172
 
 
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, 
178
 
                          const long quark);
179
 
 
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, 
185
 
                           class Cons* args);
186
 
 
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);
194
 
 
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);
202
 
 
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);
210
 
 
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);
218
 
 
219
 
  public:
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);
227
 
  };
228
 
}
229
 
 
230
 
#endif