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)  

PointerClass.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.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 /******************************************************************************/
39 /* REXX Kernel RexxPointer.cpp */
40 /* */
41 /* Primitive Pointer Class */
42 /* */
43 /******************************************************************************/
44 #include <stdlib.h>
45 #include <string.h>
46 #include "RexxCore.h"
47 #include "PointerClass.hpp"
48 #include "ActivityManager.hpp"
49 
50 
51 RexxClass *RexxPointer::classInstance = OREF_NULL; // singleton class instance
52 RexxPointer *RexxPointer::nullPointer = OREF_NULL; // single version of a null pointer
53 
54 
56 /******************************************************************************/
57 /* Function: Create initial bootstrap objects */
58 /******************************************************************************/
59 {
60  CLASS_CREATE(Pointer, "Pointer", RexxClass);
61  TheNullPointer = new_pointer(NULL); // a NULL pointer object
62 }
63 
64 
73 {
74  requiredArgument(other, ARG_ONE); /* must have the other argument */
75 
76  if (!isOfClass(Pointer, other))
77  {
78  return TheFalseObject;
79  }
80 
81  return this->pointer() == ((RexxPointer *)other)->pointer() ? TheTrueObject : TheFalseObject;
82 }
83 
84 
93 {
94  requiredArgument(other, ARG_ONE); /* must have the other argument */
95 
96  if (!isOfClass(Pointer, other))
97  {
98  return TheTrueObject;
99  }
100 
101  return this->pointer() != ((RexxPointer *)other)->pointer() ? TheTrueObject : TheFalseObject;
102 }
103 
104 
109 {
110  // generate a hash from the pointer value...but obscure this a touch to get
111  // a better bit distribution
112  return (HashCode)(~((uintptr_t)pointerData));
113 }
114 
115 
116 void *RexxPointer::operator new(size_t size)
117 /******************************************************************************/
118 /* Function: Create a new pointer object */
119 /******************************************************************************/
120 {
121  /* Get new object */
122  RexxObject *newObject = new_object(size, T_Pointer);
123  newObject->setHasNoReferences(); /* this has no references */
124  return (void *)newObject; /* return the new object */
125 }
126 
127 
129 /******************************************************************************/
130 /* Function: Allocate a pointer object from Rexx code. */
131 /******************************************************************************/
132 {
133  // we do not allow these to be allocated from Rexx code...
135  return TheNilObject;
136 }
137 
138 
145 {
147 }
148 
149 
156 {
157  return pointer() == NULL ? TheTrueObject : TheFalseObject;
158 }
TheFalseObject
#define TheFalseObject
Definition: RexxCore.h:184
RexxPointer::pointer
void * pointer()
Definition: PointerClass.hpp:60
RexxPointer::equal
RexxObject * equal(RexxObject *)
Definition: PointerClass.cpp:72
ActivityManager.hpp
PointerClass.hpp
RexxPointer::createInstance
static void createInstance()
Definition: PointerClass.cpp:55
requiredArgument
void requiredArgument(RexxObject *object, size_t position)
Definition: RexxCore.h:284
RexxPointer
Definition: PointerClass.hpp:49
RexxPointer::nullPointer
static RexxPointer * nullPointer
Definition: PointerClass.hpp:74
reportException
void reportException(wholenumber_t error)
Definition: ActivityManager.hpp:136
TheTrueObject
#define TheTrueObject
Definition: RexxCore.h:185
isOfClass
#define isOfClass(t, r)
Definition: RexxCore.h:211
Numerics::pointerToString
static RexxString * pointerToString(void *)
Definition: Numerics.cpp:888
T_Pointer
Definition: ClassTypeCodes.h:89
HashCode
size_t HashCode
Definition: ObjectClass.hpp:77
ARG_ONE
const int ARG_ONE
Definition: RexxCore.h:80
OREF_NULL
#define OREF_NULL
Definition: RexxCore.h:60
RexxClass
Definition: ClassClass.hpp:49
RexxPointer::classInstance
static RexxClass * classInstance
Definition: PointerClass.hpp:73
RexxPointer::newRexx
RexxObject * newRexx(RexxObject **args, size_t argc)
Definition: PointerClass.cpp:128
RexxPointer::pointerData
void * pointerData
Definition: PointerClass.hpp:77
CLASS_CREATE
#define CLASS_CREATE(name, id, className)
Definition: RexxMemory.hpp:445
RexxPointer::notEqual
RexxObject * notEqual(RexxObject *other)
Definition: PointerClass.cpp:92
RexxInternalObject::setHasNoReferences
void setHasNoReferences()
Definition: ObjectClass.hpp:240
RexxPointer::isNull
RexxObject * isNull()
Definition: PointerClass.cpp:155
RexxPointer::stringValue
virtual RexxString * stringValue()
Definition: PointerClass.cpp:144
TheNilObject
#define TheNilObject
Definition: RexxCore.h:180
new_pointer
RexxPointer * new_pointer(void *p)
Definition: PointerClass.hpp:81
RexxCore.h
Error_Unsupported_new_method
#define Error_Unsupported_new_method
Definition: RexxErrorCodes.h:513
RexxPointer::getHashValue
virtual HashCode getHashValue()
Definition: PointerClass.cpp:108
new_object
RexxObject * new_object(size_t s)
Definition: RexxMemory.hpp:422
RexxObject
Definition: ObjectClass.hpp:311
RexxString
Definition: StringClass.hpp:119
TheNullPointer
#define TheNullPointer
Definition: RexxCore.h:186