ProtectedObject.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.ibm.com/developerworks/oss/CPLv1.0.htm */
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 #ifndef ProtectedObject_Included
39 #define ProtectedObject_Included
40 
41 #include "RexxActivity.hpp"
42 #include "ActivityManager.hpp"
43 
44 class RexxInstruction;
45 
47 {
48 friend class RexxActivity;
49 public:
51  {
52  // save the activity
54 
55  // it would be better to have the activity class do this, but because
56  // we're doing this with inline methods, we run into a bit of a
57  // circular reference problem
59  activity->protectedObjects = this;
60  }
61 
63  {
64  // it would be better to have the activity class do this, but because
65  // we're doing this with inline methods, we run into a bit of a
66  // circular reference problem
68  activity->protectedObjects = this;
69  }
70 
72  {
73  // save the activity
76  activity->protectedObjects = this;
77  }
78 
80  {
82  activity->protectedObjects = this;
83  }
84 
86  {
87  // save the activity
90  activity->protectedObjects = this;
91  }
92 
94  {
96  activity->protectedObjects = this;
97  }
98 
100  {
101  // remove ourselves from the list and give this object a
102  // little hold protection.
104  if (protectedObject != OREF_NULL)
105  {
107  }
108  }
109 
111  {
112  protectedObject = o;
113  return *this;
114  }
115 
116  inline bool operator == (RexxObject *o)
117  {
118  return protectedObject == o;
119  }
120 
121  inline bool operator != (RexxObject *o)
122  {
123  return protectedObject != o;
124  }
125 
126  // cast conversion operators for some very common uses of protected object.
127  inline operator RexxObject *()
128  {
129  return protectedObject;
130  }
131 
132  inline operator RexxObjectPtr ()
133  {
135  }
136 
137  inline operator RexxString *()
138  {
139  return (RexxString *)protectedObject;
140  }
141 
142  inline operator RexxText *()
143  {
144  return (RexxText *)protectedObject;
145  }
146 
147  inline operator RexxMethod *()
148  {
149  return (RexxMethod *)protectedObject;
150  }
151 
152  inline operator RexxArray *()
153  {
154  return (RexxArray *)protectedObject;
155  }
156 
157  // this conversion helps the parsing process protect objects
158  inline operator RexxInstruction *()
159  {
161  }
162 
163  inline operator void *()
164  {
165  return (void *)protectedObject;
166  }
167 
168 // To let the compiler tell you it's forbidden !
169 // You want to assign a rexx object, not an other protected object.
170 // The list of protected objects is broken if such an assignement is done
171 // because the attribute next is overwritten.
172 private:
175 
176 
177 protected:
178  RexxObject *protectedObject; // next in the chain of protected object
179  ProtectedObject *next; // the pointer protected by the object
180  RexxActivity *activity; // the activity we're running on
181 };
182 
183 
185 {
186 public:
187  inline ProtectedSet() : ProtectedObject() { }
189  inline ~ProtectedSet() { }
190 
191  void add(RexxObject *);
192 };
193 
194 
195 #endif
#define OREF_NULL
Definition: RexxCore.h:61
void holdObject(RexxInternalObject *o)
Definition: RexxMemory.hpp:432
static RexxActivity *volatile currentActivity
ProtectedObject(const ProtectedObject &)
ProtectedObject(RexxObject *o)
ProtectedObject(RexxInternalObject *o)
bool operator!=(RexxObject *o)
RexxActivity * activity
RexxObject * protectedObject
ProtectedObject & operator=(const ProtectedObject &)
bool operator==(RexxObject *o)
ProtectedObject & operator=(RexxObject *o)
ProtectedObject * next
ProtectedObject(RexxActivity *a)
ProtectedObject(RexxObject *o, RexxActivity *a)
ProtectedObject(RexxInternalObject *o, RexxActivity *a)
void add(RexxObject *)
ProtectedSet(RexxActivity *a)
ProtectedObject * protectedObjects
struct _RexxObjectPtr * RexxObjectPtr
Definition: rexx.h:127