RexxVariableDictionary.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 RexxVariableDictionary.hpp */
40 /* */
41 /* Primitive Variable Dictionary Class Definition */
42 /* */
43 /******************************************************************************/
44 #ifndef Included_RexxVariableDictionary
45 #define Included_RexxVariableDictionary
46 
47 #include "RexxVariable.hpp"
48 #include "StemClass.hpp"
49 #include "RexxHashTable.hpp"
50 
51 class RexxSupplier;
52 
53 #define DEFAULT_OBJECT_DICTIONARY_SIZE 7
54 
56  public:
57  inline void *operator new(size_t size, void *ptr) { return ptr; };
58  inline void operator delete(void *) { }
59  inline void operator delete(void *, void *) { }
60 
61  inline RexxVariableDictionary(RESTORETYPE restoreType) { ; };
62 
63  void live(size_t);
64  void liveGeneral(int reason);
65  void flatten(RexxEnvelope *envelope);
66  RexxObject *copy();
67  void copyValues();
68 
70  void add(RexxVariable *, RexxString *);
71  void put(RexxVariable *, RexxString *);
72  inline RexxStem *getStem(RexxString *stemName) { return (RexxStem *)getStemVariable(stemName)->getVariableValue(); }
75 
77  {
78  return (RexxVariable *)contents->stringGet(name);
79  }
80 
82  {
83  RexxVariable *variable; /* resolved variable item */
84 
85  /* find the entry */
86  variable = resolveVariable(name);
87  if (variable == OREF_NULL) { /* not in the table? */
88  /* create a new one */
89  variable = createVariable(name);
90  }
91  return variable; /* return the stem */
92  }
93 
95  {
96  RexxVariable *variable; /* resolved variable item */
97 
98  /* find the stem entry */
99  variable = resolveVariable(stemName);
100  if (variable == OREF_NULL) { /* not in the table? */
101  /* create a new one */
102  variable = createStemVariable(stemName);
103  }
104  return variable; /* return the stem */
105  }
106 
107  void setCompoundVariable(RexxString *stemName, RexxObject **tail, size_t tailCount, RexxObject *value);
108  void dropCompoundVariable(RexxString *stemName, RexxObject **tail, size_t tailCount);
110  inline void remove(RexxString *n) { contents->remove(n); }
111 
113  void set(RexxString *, RexxObject *);
114  void drop(RexxString *);
116  void reserve(RexxActivity *);
117  unsigned short getReserveCount() { return reserveCount; } // for trace
118  void release(RexxActivity *);
119  bool transfer(RexxActivity *);
120 
121  RexxCompoundElement *getCompoundVariable(RexxString *stemName, RexxObject **tail, size_t tailCount);
122  RexxObject *getCompoundVariableValue(RexxString *stemName, RexxObject **tail, size_t tailCount);
123  RexxObject *getCompoundVariableRealValue(RexxString *stem, RexxObject **tail, size_t tailCount);
124 
125  RexxObject *realStemValue(RexxString *stemName);
126 
127  inline bool isScope(RexxObject *otherScope) { return this->scope == otherScope; }
130 
132 
135  static RexxObject *buildCompoundVariable(RexxString * variable_name, bool direct);
136 
137  static RexxVariableDictionary *newInstance(size_t);
139 
140 protected:
141 
142  RexxActivity *reservingActivity; /* current reserving activity */
143  RexxHashTable *contents; /* vdict hashtable */
144  RexxList *waitingActivities; /* list of waiting activities */
145  unsigned short flags; /* dictionary control flags */
146  unsigned short reserveCount; /* number of times reserved */
147  RexxVariableDictionary *next; /* chained object dictionary */
148  RexxObject *scope; /* scopy of this object dictionary */
149 };
150 
151 
154 #endif
RESTORETYPE
Definition: ObjectClass.hpp:80
#define OREF_NULL
Definition: RexxCore.h:60
RexxVariableDictionary * new_objectVariableDictionary(RexxObject *s)
RexxVariableDictionary * new_variableDictionary(size_t s)
RexxObject * remove(RexxObject *key)
RexxObject * stringGet(RexxString *key)
void setNextDictionary(RexxVariableDictionary *next)
void add(RexxVariable *, RexxString *)
RexxObject * realValue(RexxString *name)
RexxVariable * resolveVariable(RexxString *name)
RexxStem * getStem(RexxString *stemName)
RexxVariable * createVariable(RexxString *stemName)
bool isScope(RexxObject *otherScope)
RexxVariableDictionary(RESTORETYPE restoreType)
static RexxVariableBase * getVariableRetriever(RexxString *variable)
static RexxObject * buildCompoundVariable(RexxString *variable_name, bool direct)
void dropStemVariable(RexxString *)
RexxVariable * getVariable(RexxString *name)
void set(RexxString *, RexxObject *)
void setCompoundVariable(RexxString *stemName, RexxObject **tail, size_t tailCount, RexxObject *value)
RexxVariableDictionary * getNextDictionary()
RexxObject * getCompoundVariableValue(RexxString *stemName, RexxObject **tail, size_t tailCount)
RexxCompoundElement * getCompoundVariable(RexxString *stemName, RexxObject **tail, size_t tailCount)
void flatten(RexxEnvelope *envelope)
static RexxVariableBase * getDirectVariableRetriever(RexxString *variable)
RexxVariable * getStemVariable(RexxString *stemName)
RexxObject * getCompoundVariableRealValue(RexxString *stem, RexxObject **tail, size_t tailCount)
RexxVariableDictionary * next
static RexxVariableDictionary * newInstance(size_t)
RexxVariable * nextVariable(RexxNativeActivation *)
RexxVariable * createStemVariable(RexxString *stemName)
void dropCompoundVariable(RexxString *stemName, RexxObject **tail, size_t tailCount)
RexxObject * realStemValue(RexxString *stemName)
void put(RexxVariable *, RexxString *)
RexxObject * getVariableValue()