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  {
156  size_t rc = length - name->getLength();
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
#define OREF_NULL
Definition: RexxCore.h:61
const int MAX_SYMBOL_LENGTH
Definition: RexxCore.h:77
RexxCompoundTail(RexxString *tailString)
RexxCompoundTail(RexxActivation *context, RexxObject **tails, size_t tailCount)
void ensureCapacity(size_t needed)
ProtectedObject p
const char * getTail()
RexxCompoundTail(RexxObject **tails, size_t count)
RexxString * makeString()
int compare(RexxString *name)
void expandCapacity(size_t needed)
RexxCompoundTail(RexxVariableDictionary *dictionary, RexxObject **tails, size_t tailCount)
char buffer[MAX_SYMBOL_LENGTH]
RexxCompoundTail(const char *tailString)
void append(const char *newData, size_t stringLen)
void buildUnresolvedTail(RexxObject **tails, size_t count)
RexxCompoundTail(RexxObject **tails, size_t count, bool resolve)
void append(char newData)
RexxCompoundTail(RexxString *tails, size_t count)
void buildTail(RexxVariableDictionary *dictionary, RexxObject **tails, size_t tailCount)
RexxCompoundTail(size_t index)
RexxString * createCompoundName(RexxString *)
size_t getLength()
const char * getStringData()