ListClass.hpp
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 ListClass.hpp */
40 /* */
41 /* Primitive List Class Definitions */
42 /* */
43 /******************************************************************************/
44 #ifndef Included_RexxList
45 #define Included_RexxList
46 
47 #include "RexxListTable.hpp"
48 
49 #define INITIAL_LIST_SIZE 5 /* initial list allocation */
50 #define EXTEND_LIST_SIZE 5 /* amount to extend by each time */
51  /* size of buffer for a given number */
52  /* of list entries */
53 #define TABLE_SIZE(n) ((n)*sizeof(LISTENTRY))
54  /* number of list entries in a given */
55  /* buffer size */
56 #define ENTRY_COUNT(n) ((n)/sizeof(LISTENTRY))
57  /* address of a given buffer entry */
58 #define ENTRY_POINTER(n) (this->table->getData() + n)
59 #define ENTRY_INDEX(p) (p - this->table->getData())
60 #define LIST_END ((size_t)-1) /* end of list marker */
61 #define NOT_ACTIVE ((size_t)-2) /* free element marker */
62 
63  class RexxList : public RexxObject {
64  friend class RexxListTable;
65  public:
66  void * operator new(size_t);
67  inline void * operator new(size_t size, void *objectPtr) { return objectPtr; };
68  inline RexxList(RESTORETYPE restoreType) { ; };
69  inline RexxList() { ; }
70 
71  void init();
72  void live(size_t);
73  void liveGeneral(int reason);
74  void flatten(RexxEnvelope *);
75  RexxObject *copy();
80 
84  size_t firstIndex() { return first; }
85  size_t lastIndex() { return last; }
86  size_t nextIndex(size_t i);
87  size_t previousIndex(size_t i);
88  RexxObject *getValue(size_t i);
89 
97  inline size_t items() { return count; };
103  RexxObject *lastItem();
105  void partitionBuffer(size_t, size_t);
107  size_t getFree();
110  RexxObject *removeLast() { return (this->last != LIST_END) ? this->primitiveRemove(ENTRY_POINTER(this->last)) : TheNilObject; }
112  RexxObject *removeLastItem() { return (this->last != LIST_END) ? this->primitiveRemove(ENTRY_POINTER(this->last)) : OREF_NULL; }
113  RexxObject *removeIndex(size_t i) { return this->primitiveRemove(ENTRY_POINTER(i)); }
115  LISTENTRY *getEntry(size_t);
117  RexxObject *empty();
118  RexxObject *isEmpty();
123 
124  void addLast(RexxObject *value);
125  void addFirst(RexxObject *value);
126  inline size_t getSize() {return this->count;}
129 
130  RexxList *newRexx(RexxObject **, size_t, size_t);
131  RexxList *classOf(RexxObject **, size_t, size_t);
132 
133  static void createInstance();
135 
136  protected:
137 
138  RexxListTable *table; /* list table item */
139  size_t first; /* first real element index */
140  size_t last; /* last real element index */
141  size_t count; /* count of items in the list */
142  size_t size; /* element slots in the buffer */
143  size_t free; /* start of free element chain */
144  };
145 
146 
147 inline RexxList *new_list() { return new RexxList; }
148 
149 #endif
#define ENTRY_POINTER(n)
Definition: ListClass.hpp:58
#define LIST_END
Definition: ListClass.hpp:60
RexxList * new_list()
Definition: ListClass.hpp:147
RESTORETYPE
Definition: ObjectClass.hpp:80
#define OREF_NULL
Definition: RexxCore.h:60
#define TheNilObject
Definition: RexxCore.h:181
RexxObject * removeIndex(size_t i)
Definition: ListClass.hpp:113
size_t previousIndex(size_t i)
Definition: ListClass.cpp:830
RexxObject * lastRexx()
Definition: ListClass.cpp:728
RexxObject * append(RexxObject *)
Definition: ListClass.cpp:538
RexxObject * value(RexxObject *)
Definition: ListClass.cpp:246
RexxArray * allIndexes()
Definition: ListClass.cpp:938
void partitionBuffer(size_t, size_t)
Definition: ListClass.cpp:92
RexxArray * makeArrayIndices()
Definition: ListClass.cpp:1112
RexxArray * allItems()
Definition: ListClass.cpp:888
size_t firstIndex()
Definition: ListClass.hpp:84
size_t getFree()
Definition: ListClass.cpp:115
RexxObject * next(RexxObject *)
Definition: ListClass.cpp:744
void live(size_t)
Definition: ListClass.cpp:153
size_t lastIndex()
Definition: ListClass.hpp:85
RexxObject * removeObject(RexxObject *)
Definition: ListClass.cpp:1058
RexxObject * sectionSubclass(LISTENTRY *, size_t)
Definition: ListClass.cpp:354
size_t free
Definition: ListClass.hpp:143
RexxArray * makeArray()
Definition: ListClass.cpp:873
size_t nextIndex(size_t i)
Definition: ListClass.cpp:804
RexxObject * hasIndex(RexxObject *)
Definition: ListClass.cpp:845
size_t getSize()
Definition: ListClass.hpp:126
void flatten(RexxEnvelope *)
Definition: ListClass.cpp:171
RexxObject * lastItem()
Definition: ListClass.cpp:697
RexxObject * insert(RexxObject *, RexxObject *)
Definition: ListClass.cpp:546
RexxObject * removeLast()
Definition: ListClass.hpp:110
size_t size
Definition: ListClass.hpp:142
size_t items()
Definition: ListClass.hpp:97
RexxObject * previous(RexxObject *)
Definition: ListClass.cpp:769
RexxObject * removeItem(RexxObject *)
Definition: ListClass.cpp:1023
size_t last
Definition: ListClass.hpp:140
size_t count
Definition: ListClass.hpp:141
RexxObject * primitiveRemove(LISTENTRY *)
Definition: ListClass.cpp:640
LISTENTRY * getEntry(RexxObject *, RexxObject *)
Definition: ListClass.cpp:184
RexxList * classOf(RexxObject **, size_t, size_t)
Definition: ListClass.cpp:1242
RexxArray * weakReferenceArray()
Definition: ListClass.cpp:1158
RexxObject * add(RexxObject *, RexxObject *)
Definition: ListClass.cpp:381
RexxObject * removeLastItem()
Definition: ListClass.hpp:112
RexxObject * hasItem(RexxObject *)
Definition: ListClass.cpp:994
void liveGeneral(int reason)
Definition: ListClass.cpp:162
RexxObject * put(RexxObject *, RexxObject *)
Definition: ListClass.cpp:289
RexxObject * itemsRexx()
Definition: ListClass.cpp:1148
RexxObject * index(RexxObject *)
Definition: ListClass.cpp:964
RexxObject * firstRexx()
Definition: ListClass.cpp:712
RexxObject * remove(RexxObject *)
Definition: ListClass.cpp:630
RexxList * newRexx(RexxObject **, size_t, size_t)
Definition: ListClass.cpp:1215
RexxObject * isEmpty()
Definition: ListClass.cpp:926
RexxArray * requestArray()
Definition: ListClass.cpp:857
RexxObject * section(RexxObject *, RexxObject *)
Definition: ListClass.cpp:309
static RexxClass * classInstance
Definition: ListClass.hpp:134
RexxObject * empty()
Definition: ListClass.cpp:908
RexxList(RESTORETYPE restoreType)
Definition: ListClass.hpp:68
RexxObject * removeFirst()
Definition: ListClass.hpp:109
RexxObject * indexOfValue(RexxObject *)
Definition: ListClass.cpp:1082
RexxListTable * table
Definition: ListClass.hpp:138
static void createInstance()
Definition: ListClass.cpp:60
RexxObject * insertRexx(RexxObject *, RexxObject *)
Definition: ListClass.cpp:518
RexxObject * firstItem()
Definition: ListClass.cpp:682
RexxObject * getValue(size_t i)
Definition: ListClass.cpp:276
void addLast(RexxObject *value)
Definition: ListClass.cpp:455
RexxObject * copy()
Definition: ListClass.cpp:78
RexxSupplier * supplier()
Definition: ListClass.cpp:1131
void addFirst(RexxObject *value)
Definition: ListClass.cpp:486
size_t first
Definition: ListClass.hpp:139
void init()
Definition: ListClass.cpp:66
RexxObject * removeFirstItem()
Definition: ListClass.hpp:111