ooRexx  4.2.0-source
About: ooRexx (Open Object Rexx) is a free implementation of Object Rexx. Object Rexx is an enhancement of the classic Rexx interpreter; a full-featured programming language with a human-oriented syntax.
  Fossies Dox: ooRexx-4.2.0-source.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

TableClass.cpp
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
4 /* Copyright (c) 2005-2009 Rexx Language Association. All rights reserved. */
5 /* */
6 /* This program and the accompanying materials are made available under */
7 /* the terms of the Common Public License v1.0 which accompanies this */
8 /* distribution. A copy is also available at the following address: */
9 /* http://www.oorexx.org/license.html */
10 /* */
11 /* Redistribution and use in source and binary forms, with or */
12 /* without modification, are permitted provided that the following */
13 /* conditions are met: */
14 /* */
15 /* Redistributions of source code must retain the above copyright */
16 /* notice, this list of conditions and the following disclaimer. */
17 /* Redistributions in binary form must reproduce the above copyright */
18 /* notice, this list of conditions and the following disclaimer in */
19 /* the documentation and/or other materials provided with the distribution. */
20 /* */
21 /* Neither the name of Rexx Language Association nor the names */
22 /* of its contributors may be used to endorse or promote products */
23 /* derived from this software without specific prior written permission. */
24 /* */
25 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
26 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
27 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
28 /* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
29 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
30 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
31 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
32 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
33 /* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
34 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
35 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
36 /* */
37 /*----------------------------------------------------------------------------*/
38 /****************************************************************************/
39 /* REXX Kernel TableClass.cpp */
40 /* */
41 /* Primitive Table Class */
42 /* */
43 /****************************************************************************/
44 #include "RexxCore.h"
45 #include "IntegerClass.hpp"
46 #include "TableClass.hpp"
47 #include "RexxActivity.hpp"
48 #include "ActivityManager.hpp"
49 #include "ProtectedObject.hpp"
50 
51 // singleton class instance
53 
54 
59 {
60  CLASS_CREATE(Table, "Table", RexxClass);
61 }
62 
63 
65  size_t _value, /* object to add */
66  RexxObject *_index) /* added index */
67 /******************************************************************************/
68 /* Function: This add method is used by the envelope packing/copybuffer */
69 /* processing. it is used to maintain the nodupTable. The value argument */
70 /* is not really an OREF but rather a offSet into the smartBuffer. */
71 /* This routine will do the same function as Add except that we won't verify */
72 /* any arguments and f we need to grow the hashtab we mark it as */
73 /* having to references. This is needed to so that we don't try and Mark */
74 /* (Collect) the offset values. */
75 /******************************************************************************/
76 {
77  memoryObject.disableOrefChecks(); /* Turn off OrefSet Checking. */
78  /* try to place in existing hashtab */
79  RexxHashTable *newHash = this->contents->primitiveAdd((RexxObject *)_value, _index);
80  if (newHash != OREF_NULL)
81  { /* have a reallocation occur? */
82  /* mark the hash as not having refere*/
83  /* even though the indices are objs */
84  /* we don't need to mark this Hash. */
85  /* Trust me !!! */
86  newHash->setHasNoReferences();
87  /* hook on the new hash table */
88  OrefSet(this, this->contents, newHash);
89  }
90  memoryObject.enableOrefChecks(); /* Turn OrefSet Checking. */
91  return OREF_NULL; /* always return nothing */
92 }
93 
95  RexxObject *_value, /* object to add */
96  RexxString *_index) /* added index */
97 /******************************************************************************/
98 /* Function: Add an object to a table using a string index. */
99 /******************************************************************************/
100 {
101  requiredArgument(_value, ARG_ONE); /* make sure we have an value */
102  requiredArgument(_index, ARG_TWO); /* make sure we have an index */
103  /* try to place in existing hashtab */
104  RexxHashTable *newHash = this->contents->stringAdd(_value, _index);
105  if (newHash != OREF_NULL) /* have a reallocation occur? */
106  {
107  /* hook on the new hash table */
108  OrefSet(this, this->contents, newHash);
109  }
110  return OREF_NULL; /* always return nothing */
111 }
112 
114  RexxObject *_value, /* value to insert */
115  RexxString *_index) /* item index */
116 /******************************************************************************/
117 /* Function: Put an object into the table using a string index */
118 /******************************************************************************/
119 {
120  requiredArgument(_value, ARG_ONE); /* make sure we have an value */
121  requiredArgument(_index, ARG_TWO); /* make sure we have an index */
122  /* try to place in existing hashtab */
123  RexxHashTable *newHash = this->contents->stringPut(_value, _index);
124  if (newHash != OREF_NULL) /* have a reallocation occur? */
125  {
126  /* hook on the new hash table */
127  OrefSet(this, this->contents, newHash);
128  }
129  return OREF_NULL; /* always return nothing */
130 }
131 
133 /******************************************************************************/
134 /* Function: Primitive level request('ARRAY') fast path */
135 /******************************************************************************/
136 {
137  if (isOfClass(Table, this)) /* primitive level object? */
138  {
139  return this->makeArray(); /* just do the makearray */
140  }
141  else /* need to so full request mechanism */
142  {
143  return(RexxArray *)this->sendMessage(OREF_REQUEST, OREF_ARRAYSYM);
144  }
145 }
146 
148 /******************************************************************************/
149 /* Function: Return the count of items in the table */
150 /******************************************************************************/
151 {
152  size_t numEntries = this->contents->totalEntries();
153  return(RexxObject *)new_integer(numEntries);
154 }
155 
157 /******************************************************************************/
158 /* Function: Reset a table by clearing out the old contents table */
159 /******************************************************************************/
160 {
162 }
163 
165 /******************************************************************************/
166 /* Function: Put an object into a table, ensuring no duplicates. */
167 /******************************************************************************/
168 {
169  /* try to place in existing hashtab */
170  RexxHashTable *newHash = this->contents->putNodupe(_value, _index);
171  if (newHash != OREF_NULL) /* have a reallocation occur? */
172  {
173  /* hook on the new hash table */
174  OrefSet(this, this->contents, newHash);
175  }
176  return OREF_NULL;
177 }
178 
180 /******************************************************************************/
181 /* Function: Create an instance of a table */
182 /******************************************************************************/
183 {
184  OrefSet(this, this->contents, this->contents->reHash());
185 }
186 
188  RexxObject **args, /* subclass init arguments */
189  size_t argCount) /* count of arguments */
190 /******************************************************************************/
191 /* Function: Create an instance of a table */
192 /******************************************************************************/
193 {
194  RexxTable *newObj = new_table(); /* get a new table */
195  ProtectedObject p(newObj);
196  newObj->setBehaviour(((RexxClass *)this)->getInstanceBehaviour());
197  /* does object have an UNINT method */
198  if (((RexxClass *)this)->hasUninitDefined())
199  {
200  newObj->hasUninit(); /* Make sure everyone is notified. */
201  }
202  /* call any rexx level init's */
203  newObj->sendMessage(OREF_INIT, args, argCount);
204  return newObj; /* return the new object */
205 }
206 
208 /******************************************************************************/
209 /* Function: Create an instance of a table */
210 /******************************************************************************/
211 {
213 }
214 
215 
RexxObject::sendMessage
void sendMessage(RexxString *, RexxArray *, ProtectedObject &)
Definition: ObjectClass.cpp:668
RexxArray
Definition: ArrayClass.hpp:100
RexxHashTable::DEFAULT_HASH_SIZE
Definition: RexxHashTable.hpp:64
new_integer
RexxInteger * new_integer(wholenumber_t v)
Definition: IntegerClass.hpp:198
memoryObject
RexxMemory memoryObject
Definition: RexxMemory.cpp:84
OrefSet
#define OrefSet(o, r, v)
Definition: RexxCore.h:94
RexxTable::reset
void reset()
Definition: TableClass.cpp:156
IntegerClass.hpp
RexxHashTable::stringPut
RexxHashTable * stringPut(RexxObject *value, RexxString *key)
Definition: RexxHashTable.cpp:1300
T_Table
Definition: ClassTypeCodes.h:83
ActivityManager.hpp
RexxHashTable::stringAdd
RexxHashTable * stringAdd(RexxObject *value, RexxString *key)
Definition: RexxHashTable.cpp:1248
RexxTable::addOffset
RexxObject * addOffset(size_t, RexxObject *)
Definition: TableClass.cpp:64
requiredArgument
void requiredArgument(RexxObject *object, size_t position)
Definition: RexxCore.h:284
RexxHashTableCollection::makeArray
RexxArray * makeArray()
Definition: RexxCollection.cpp:132
new_hashCollection
RexxTable * new_hashCollection(size_t s, size_t s2, size_t t)
Definition: RexxHashTable.hpp:156
RexxMemory::disableOrefChecks
void disableOrefChecks()
Definition: RexxMemory.hpp:258
ARG_TWO
const int ARG_TWO
Definition: RexxCore.h:81
RexxTable::createInstance
static void createInstance()
Definition: TableClass.cpp:58
TableClass.hpp
RexxInternalObject::hasUninit
void hasUninit()
Definition: ObjectClass.cpp:1873
RexxTable::reHash
void reHash()
Definition: TableClass.cpp:179
RexxTable::requestArray
RexxArray * requestArray()
Definition: TableClass.cpp:132
isOfClass
#define isOfClass(t, r)
Definition: RexxCore.h:211
ARG_ONE
const int ARG_ONE
Definition: RexxCore.h:80
OREF_NULL
#define OREF_NULL
Definition: RexxCore.h:60
RexxTable::stringAdd
RexxObject * stringAdd(RexxObject *, RexxString *)
Definition: TableClass.cpp:94
new_hashtab
RexxHashTable * new_hashtab(size_t s)
Definition: RexxHashTable.hpp:157
RexxMemory::enableOrefChecks
void enableOrefChecks()
Definition: RexxMemory.hpp:259
RexxClass
Definition: ClassClass.hpp:49
RexxInternalObject::setBehaviour
void setBehaviour(RexxBehaviour *b)
Definition: ObjectClass.hpp:265
ProtectedObject.hpp
RexxHashTable::totalEntries
size_t totalEntries()
Definition: RexxHashTable.cpp:1465
ProtectedObject
Definition: ProtectedObject.hpp:46
RexxHashTable
Definition: RexxHashTable.hpp:60
CLASS_CREATE
#define CLASS_CREATE(name, id, className)
Definition: RexxMemory.hpp:445
new_table
RexxTable * new_table()
Definition: TableClass.hpp:76
RexxTable::newInstance
static RexxTable * newInstance()
Definition: TableClass.cpp:207
RexxInternalObject::setHasNoReferences
void setHasNoReferences()
Definition: ObjectClass.hpp:240
RexxHashTable::primitiveAdd
RexxHashTable * primitiveAdd(RexxObject *value, RexxObject *key)
Definition: RexxHashTable.cpp:235
RexxTable
Definition: TableClass.hpp:49
RexxHashTableCollection::contents
RexxHashTable * contents
Definition: RexxCollection.hpp:91
RexxTable::newRexx
RexxObject * newRexx(RexxObject **, size_t)
Definition: TableClass.cpp:187
RexxTable::itemsRexx
RexxObject * itemsRexx()
Definition: TableClass.cpp:147
RexxHashTable::reHash
RexxHashTable * reHash()
Definition: RexxHashTable.cpp:1819
RexxTable::putNodupe
RexxObject * putNodupe(RexxObject *, RexxObject *)
Definition: TableClass.cpp:164
RexxActivity.hpp
RexxTable::classInstance
static RexxClass * classInstance
Definition: TableClass.hpp:72
RexxCore.h
RexxTable::stringPut
RexxObject * stringPut(RexxObject *, RexxString *)
Definition: TableClass.cpp:113
RexxHashTable::putNodupe
RexxHashTable * putNodupe(RexxObject *value, RexxObject *key)
Definition: RexxHashTable.cpp:1413
RexxObject
Definition: ObjectClass.hpp:311
RexxString
Definition: StringClass.hpp:119