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)  

RexxCompoundTail.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 /******************************************************************************/
39 /* REXX Kernel RexxCompoundTail.hpp */
40 /* */
41 /* Primitive Compound Tail Class Definitions */
42 /* */
43 /******************************************************************************/
44 
45 #ifndef Included_RexxCompoundTail
46 #define Included_RexxCompoundTail
47 
48 #include "ProtectedObject.hpp"
49 
50 class RexxBuffer;
51 
53 
54  enum { ALLOCATION_PAD = 100 } ; /* amount of padding added when the buffer size is increased */
55 
56  public:
57  inline RexxCompoundTail(RexxVariableDictionary *dictionary, RexxObject **tails, size_t tailCount)
58  {
59  init(); /* do the common initialization */
60  buildTail(dictionary, tails, tailCount); /* build the full tail up */
61  }
62 
63  inline RexxCompoundTail(RexxActivation *context, RexxObject **tails, size_t tailCount)
64  {
65  init(); /* do the common initialization */
66  buildTail(context, tails, tailCount); /* build the full tail up */
67  }
68 
69  inline RexxCompoundTail(RexxObject **tails, size_t count)
70  {
71  init(); /* do the common initialization */
72  buildTail(tails, count); /* build the full tail up */
73  }
74  inline RexxCompoundTail(RexxString *tails, size_t count)
75  {
76  init(); /* do the common initialization */
77  buildTail(tails, count); /* build the full tail up */
78  }
79 
80  inline RexxCompoundTail(RexxString *tailString)
81  {
82  init(); /* do the common initialization */
83  buildTail(tailString); /* build the full tail up */
84  }
85 
86  inline RexxCompoundTail(const char *tailString)
87  {
88  init(); /* do the common initialization */
89  buildTail(tailString); /* build the full tail up */
90  }
91 
92  inline RexxCompoundTail(size_t index)
93  {
94  init(); /* do the common initialization */
95  buildTail(index); /* build the full tail up */
96  }
97 
98 
99  inline RexxCompoundTail(RexxObject **tails, size_t count, bool resolve) {
100  init(); /* do the common initialization */
101  if (resolve)
102  {
103  buildTail(tails, count); /* build the full tail up */
104  }
105  else
106  {
107  buildUnresolvedTail(tails, count); /* build the full tail up */
108  }
109  }
110 
112  {
113  }
114 
115  inline void ensureCapacity(size_t needed) { if (remainder < needed) expandCapacity(needed); }
116  void expandCapacity(size_t needed);
117  inline void append(const char *newData, size_t stringLen)
118  {
119  ensureCapacity(stringLen); /* make sure have have space */
120  memcpy(current, newData, stringLen); /* copy this into the buffer */
121  current += stringLen; /* step the pointer */
122  remainder -= stringLen; /* adjust the lengths */
123  }
124  inline void append(char newData)
125  {
126  ensureCapacity(1); /* make sure have have space */
127  *current = newData; /* store the character */
128  current++; /* step the pointer */
129  remainder--; /* adjust the lengths */
130  }
131 
134  void init()
135  {
136  length = 0; /* set the initial lengths */
138  tail = buffer; /* the default tail is the buffer */
139  current = tail; /* the current pointer is the beginning */
140  temp = OREF_NULL; /* we don't have a temporary here */
141  value = OREF_NULL; /* and no string value yet */
142  }
143 
144  void buildTail(RexxVariableDictionary *dictionary, RexxObject **tails, size_t tailCount);
145  void buildTail(RexxActivation *context, RexxObject **tails, size_t tailCount);
146  void buildTail(RexxObject **tails, size_t count);
147  void buildTail(RexxString *tail);
148  void buildTail(RexxString *tail, size_t index);
149  void buildTail(size_t index);
150  void buildTail(const char *index);
151  void buildUnresolvedTail(RexxObject **tails, size_t count);
152 
153  inline void addDot() { append('.'); }
154  inline int compare(RexxString *name)
155  {
157  if (rc == 0)
158  {
159  rc = memcmp(tail, name->getStringData(), length);
160  }
161  return (int)rc;
162  }
163 
164  inline size_t getLength() { return length; }
165  inline const char *getTail() { return tail; }
166 
167  protected:
168 
169  size_t length; /* length of the buffer (current) */
170  size_t remainder; /* remaining length in the buffer */
171  char *tail; /* the start of the tail buffer */
172  char *current; /* current write position */
173  char buffer[MAX_SYMBOL_LENGTH]; /* the default buffer */
174  RexxString *value; /* a created string value */
175  RexxBuffer *temp; // potential temporary buffer
176  ProtectedObject p; // used to protect the temp buffer
177  };
178 #endif
RexxCompoundTail::remainder
size_t remainder
Definition: RexxCompoundTail.hpp:170
RexxCompoundTail::tail
char * tail
Definition: RexxCompoundTail.hpp:171
RexxCompoundTail::current
char * current
Definition: RexxCompoundTail.hpp:172
RexxCompoundTail::ensureCapacity
void ensureCapacity(size_t needed)
Definition: RexxCompoundTail.hpp:115
RexxString::getLength
size_t getLength()
Definition: StringClass.hpp:330
RexxCompoundTail::p
ProtectedObject p
Definition: RexxCompoundTail.hpp:176
RexxVariableDictionary
Definition: RexxVariableDictionary.hpp:55
RexxCompoundTail::RexxCompoundTail
RexxCompoundTail(RexxObject **tails, size_t count, bool resolve)
Definition: RexxCompoundTail.hpp:99
RexxString::getStringData
const char * getStringData()
Definition: StringClass.hpp:333
RexxBuffer
Definition: BufferClass.hpp:91
RexxCompoundTail::append
void append(char newData)
Definition: RexxCompoundTail.hpp:124
RexxCompoundTail::RexxCompoundTail
RexxCompoundTail(RexxObject **tails, size_t count)
Definition: RexxCompoundTail.hpp:69
RexxCompoundTail::buildUnresolvedTail
void buildUnresolvedTail(RexxObject **tails, size_t count)
Definition: RexxCompoundTail.cpp:53
OREF_NULL
#define OREF_NULL
Definition: RexxCore.h:60
RexxCompoundTail::ALLOCATION_PAD
Definition: RexxCompoundTail.hpp:54
RexxCompoundTail::getLength
size_t getLength()
Definition: RexxCompoundTail.hpp:164
RexxCompoundTail::~RexxCompoundTail
~RexxCompoundTail()
Definition: RexxCompoundTail.hpp:111
ProtectedObject.hpp
RexxCompoundTail::RexxCompoundTail
RexxCompoundTail(size_t index)
Definition: RexxCompoundTail.hpp:92
ProtectedObject
Definition: ProtectedObject.hpp:46
RexxCompoundTail::RexxCompoundTail
RexxCompoundTail(RexxString *tailString)
Definition: RexxCompoundTail.hpp:80
RexxCompoundTail::expandCapacity
void expandCapacity(size_t needed)
Definition: RexxCompoundTail.cpp:289
RexxCompoundTail::addDot
void addDot()
Definition: RexxCompoundTail.hpp:153
RexxCompoundTail::buffer
char buffer[MAX_SYMBOL_LENGTH]
Definition: RexxCompoundTail.hpp:173
RexxCompoundTail::value
RexxString * value
Definition: RexxCompoundTail.hpp:174
RexxCompoundTail::append
void append(const char *newData, size_t stringLen)
Definition: RexxCompoundTail.hpp:117
RexxCompoundTail::buildTail
void buildTail(RexxVariableDictionary *dictionary, RexxObject **tails, size_t tailCount)
Definition: RexxCompoundTail.cpp:89
RexxCompoundTail::makeString
RexxString * makeString()
Definition: RexxCompoundTail.cpp:343
RexxCompoundTail::RexxCompoundTail
RexxCompoundTail(RexxString *tails, size_t count)
Definition: RexxCompoundTail.hpp:74
RexxCompoundTail::createCompoundName
RexxString * createCompoundName(RexxString *)
Definition: RexxCompoundTail.cpp:319
RexxCompoundTail::getTail
const char * getTail()
Definition: RexxCompoundTail.hpp:165
RexxActivation
Definition: RexxActivation.hpp:156
wholenumber_t
ssize_t wholenumber_t
Definition: rexx.h:229
RexxCompoundTail::temp
RexxBuffer * temp
Definition: RexxCompoundTail.hpp:175
RexxCompoundTail::RexxCompoundTail
RexxCompoundTail(const char *tailString)
Definition: RexxCompoundTail.hpp:86
RexxCompoundTail::length
size_t length
Definition: RexxCompoundTail.hpp:169
RexxCompoundTail::init
void init()
Definition: RexxCompoundTail.hpp:134
RexxCompoundTail
Definition: RexxCompoundTail.hpp:52
MAX_SYMBOL_LENGTH
const int MAX_SYMBOL_LENGTH
Definition: RexxCore.h:74
RexxCompoundTail::compare
int compare(RexxString *name)
Definition: RexxCompoundTail.hpp:154
RexxCompoundTail::RexxCompoundTail
RexxCompoundTail(RexxVariableDictionary *dictionary, RexxObject **tails, size_t tailCount)
Definition: RexxCompoundTail.hpp:57
RexxObject
Definition: ObjectClass.hpp:311
RexxString
Definition: StringClass.hpp:119
RexxCompoundTail::RexxCompoundTail
RexxCompoundTail(RexxActivation *context, RexxObject **tails, size_t tailCount)
Definition: RexxCompoundTail.hpp:63