MutableBufferClass.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 MutableBufferClass.hpp */
40 /* */
41 /* Primitive MutableBuffer Class Definition */
42 /* */
43 /******************************************************************************/
44 #ifndef Included_RexxMutableBuffer
45 #define Included_RexxMutableBuffer
46 
47 #include "StringClass.hpp"
48 #include "IntegerClass.hpp"
49 #include "BufferClass.hpp"
50 
51 class RexxMutableBuffer;
52 class RexxClass;
53 
55  public:
56  RexxMutableBufferClass(RESTORETYPE restoreType) { ; };
57  void *operator new(size_t size, void *ptr) { return ptr; };
58  RexxMutableBuffer *newRexx(RexxObject**, size_t, size_t); // in behaviour
59 };
60 
61  class RexxMutableBuffer : public RexxObject {
62  friend class RexxMutableBufferClass;
63  public:
64  inline void *operator new(size_t size, void *ptr){return ptr;};
65  void *operator new(size_t size, RexxClass *bufferClass);
66  void *operator new(size_t size);
68  RexxMutableBuffer(size_t, size_t);
69  inline RexxMutableBuffer(RESTORETYPE restoreType) { ; };
70 
71  void live(size_t);
72  void liveGeneral(int reason);
73  void flatten(RexxEnvelope *envelope);
74 
75  RexxObject *copy();
76  void ensureCapacity(size_t addedLength);
77 
78  RexxObject *lengthRexx(); // in behaviour
79 
80  RexxMutableBuffer *append(RexxObject*); // in behaviour
81  RexxMutableBuffer *appendCstring(const char*, size_t blength); // Must not overload append : would generate error cannot convert from 'overloaded-function' to 'PCPPM' in memory/setup.cpp
84  RexxMutableBuffer *replaceAt(RexxObject *str, RexxObject *pos, RexxObject *len, RexxObject *pad); // in behaviour
85  RexxMutableBuffer *mydelete(RexxObject*, RexxObject*); // in behaviour
86  RexxString *substr(RexxInteger *startPosition, RexxInteger *len, RexxString *pad); // in behaviour
87  RexxInteger *lastPos(RexxString *needle, RexxInteger *_start, RexxInteger *_range); // in behaviour
88  RexxInteger *posRexx(RexxString *needle, RexxInteger *_start, RexxInteger *_range); // in behaviour
89  RexxInteger *caselessLastPos(RexxString *needle, RexxInteger *_start, RexxInteger *_range); // in behaviour
90  RexxInteger *caselessPos(RexxString *needle, RexxInteger *_start, RexxInteger *_range); // in behaviour
91  RexxString *subchar(RexxInteger *startPosition); // in behaviour
92 
93  RexxInteger *getBufferSize() { return new_integer(bufferLength); } // in behaviour
94  RexxObject *setBufferSize(RexxInteger*); // in behaviour
95  RexxArray *makeArrayRexx(RexxString *div); // in behaviour
99  RexxInteger *countStrRexx(RexxString *needle); // in behaviour
100  RexxInteger *caselessCountStrRexx(RexxString *needle); // in behaviour
101  RexxMutableBuffer *changeStr(RexxString *needle, RexxString *newNeedle, RexxInteger *countArg); // in behaviour
102  RexxMutableBuffer *caselessChangeStr(RexxString *needle, RexxString *newNeedle, RexxInteger *countArg); // in behaviour
103  RexxMutableBuffer *upper(RexxInteger *_start, RexxInteger *_length); // in behaviour
104  RexxMutableBuffer *lower(RexxInteger *_start, RexxInteger *_length); // in behaviour
105  RexxMutableBuffer *translate(RexxString *tableo, RexxString *tablei, RexxString *pad, RexxInteger *, RexxInteger *); // in behaviour
106  RexxInteger *match(RexxInteger *start_, RexxString *other, RexxInteger *offset_, RexxInteger *len_); // in behaviour
107  RexxInteger *caselessMatch(RexxInteger *start_, RexxString *other, RexxInteger *offset_, RexxInteger *len_); // in behaviour
110  RexxInteger *matchChar(RexxInteger *position_, RexxString *matchSet); // in behaviour
111  RexxInteger *caselessMatchChar(RexxInteger *position_, RexxString *matchSet); // in behaviour
112  RexxInteger *verify(RexxString *, RexxString *, RexxInteger *, RexxInteger *); // in behaviour
113  RexxString *subWord(RexxInteger *, RexxInteger *); // in behaviour
114  RexxArray *subWords(RexxInteger *, RexxInteger *); // in behaviour
115  RexxString *word(RexxInteger *); // in behaviour
116  RexxInteger *wordIndex(RexxInteger *); // in behaviour
117  RexxInteger *wordLength(RexxInteger *); // in behaviour
118  RexxInteger *words(); // in behaviour
119  RexxInteger *wordPos(RexxString *, RexxInteger *); // in behaviour
120  RexxInteger *caselessWordPos(RexxString *, RexxInteger *); // in behaviour
121  RexxMutableBuffer *delWord(RexxInteger *position, RexxInteger *plength); // in behaviour
122  RexxMutableBuffer *space(RexxInteger *space_count, RexxString *pad);
123 
124  inline const char *getStringData() { return data->getData(); }
125  inline size_t getLength() { return dataLength; }
126  inline void setLength(size_t l) { dataLength = l; data->setDataLength(l);};
127  inline size_t getBufferLength() { return bufferLength; }
128  RexxObject *setBufferLength(size_t);
129  inline char * getData() { return data->getData(); }
130  inline void copyData(size_t offset, const char *string, size_t l) { data->copyData(offset, string, l); }
131  inline void openGap(size_t offset, size_t _size, size_t tailSize) { data->openGap(offset, _size, tailSize); }
132  inline void closeGap(size_t offset, size_t _size, size_t tailSize) { data->closeGap(offset, _size, tailSize); }
133  inline void adjustGap(size_t offset, size_t _size, size_t _newSize) { data->adjustGap(offset, _size, _newSize); }
134  inline void setData(size_t offset, codepoint_t character, size_t l) { data->setData(offset, (char)character, l); }
135  inline char getCharB(size_t offset) { return getData()[offset]; }
136  size_t setDataLength(size_t l);
137  inline size_t getCapacity() { return bufferLength; }
138  char *setCapacity(size_t newLength);
139 
140  bool checkIsASCII();
142  inline bool isASCIIChecked() {return (this->Attributes & STRING_ISASCII_CHECKED) != 0;};
143  inline void setIsASCIIChecked(bool value=true)
144  {
145  if (value) this->Attributes |= STRING_ISASCII_CHECKED;
146  else
147  {
149  this->setIsASCII(false); // isASCII() can be true only when isASCIIChecked() is true
150  }
151  }
152  // if isASCII() is true then it's really ASCII
153  // if isASCII() is false then it's really not ASCII only when isASCIIChecked() is true, otherwise can't tell
154  inline bool isASCII() {return (this->Attributes & STRING_ISASCII) != 0;};
155  inline void setIsASCII(bool value=true)
156  {
157  if (value) this->Attributes |= STRING_ISASCII;
158  else this->Attributes &= ~STRING_ISASCII;
159  }
160 
161  inline RexxObject *getEncoding() { return this->encoding; }
162  inline void setEncoding(RexxObject *e)
163  {
164  OrefSet(this, this->encoding, e);
165  if (e != OREF_NULL) this->setHasReferences();
166  }
168  {
169  RexxObject *previousEncoding = this->getEncoding();
170  this->setEncoding(e);
171  return previousEncoding;
172  }
173 
174  static void createInstance();
176 
177  protected:
178  size_t bufferLength; /* buffer length in bytes */
179  size_t defaultSize; /* default size when emptied */
180  size_t dataLength; // current length of data in bytes
181  size_t Attributes; /* buffer attributes */
182  RexxObject *encoding; // mutable buffer encoding or OREF_NULL
183  RexxBuffer *data; /* buffer used for the data */
184  };
185 
186 #endif
RexxInteger * new_integer(wholenumber_t v)
RESTORETYPE
Definition: ObjectClass.hpp:82
#define OREF_NULL
Definition: RexxCore.h:61
#define OrefSet(o, r, v)
Definition: RexxCore.h:101
#define STRING_ISASCII
Definition: StringClass.hpp:66
#define STRING_ISASCII_CHECKED
Definition: StringClass.hpp:65
void setData(size_t offset, char character, size_t l)
Definition: BufferClass.hpp:83
void closeGap(size_t offset, size_t _size, size_t tailSize)
Definition: BufferClass.hpp:64
void openGap(size_t offset, size_t _size, size_t tailSize)
Definition: BufferClass.hpp:60
void setDataLength(size_t l)
Definition: BufferClass.hpp:55
void copyData(size_t offset, const char *string, size_t l)
Definition: BufferClass.hpp:57
void adjustGap(size_t offset, size_t _size, size_t _newSize)
Definition: BufferClass.hpp:69
virtual char * getData()
RexxMutableBuffer * newRexx(RexxObject **, size_t, size_t)
RexxMutableBufferClass(RESTORETYPE restoreType)
RexxInteger * isASCIIRexx()
RexxInteger * caselessLastPos(RexxString *needle, RexxInteger *_start, RexxInteger *_range)
RexxMutableBuffer * caselessChangeStr(RexxString *needle, RexxString *newNeedle, RexxInteger *countArg)
RexxMutableBuffer * translate(RexxString *tableo, RexxString *tablei, RexxString *pad, RexxInteger *, RexxInteger *)
RexxMutableBuffer * appendCstring(const char *, size_t blength)
void closeGap(size_t offset, size_t _size, size_t tailSize)
bool primitiveCaselessMatch(stringsize_t start, RexxString *other, stringsize_t offset, stringsize_t len)
RexxString * subchar(RexxInteger *startPosition)
void setData(size_t offset, codepoint_t character, size_t l)
void openGap(size_t offset, size_t _size, size_t tailSize)
void setIsASCII(bool value=true)
RexxMutableBuffer * mydelete(RexxObject *, RexxObject *)
RexxArray * subWords(RexxInteger *, RexxInteger *)
RexxObject * setEncodingRexx(RexxObject *e)
RexxMutableBuffer * changeStr(RexxString *needle, RexxString *newNeedle, RexxInteger *countArg)
void liveGeneral(int reason)
RexxObject * getEncoding()
RexxInteger * verify(RexxString *, RexxString *, RexxInteger *, RexxInteger *)
RexxMutableBuffer * lower(RexxInteger *_start, RexxInteger *_length)
static void createInstance()
void flatten(RexxEnvelope *envelope)
const char * getStringData()
RexxMutableBuffer * append(RexxObject *)
RexxInteger * posRexx(RexxString *needle, RexxInteger *_start, RexxInteger *_range)
RexxMutableBuffer(RESTORETYPE restoreType)
RexxMutableBuffer * space(RexxInteger *space_count, RexxString *pad)
RexxMutableBuffer * delWord(RexxInteger *position, RexxInteger *plength)
RexxInteger * wordPos(RexxString *, RexxInteger *)
bool primitiveMatch(stringsize_t start, RexxString *other, stringsize_t offset, stringsize_t len)
void setEncoding(RexxObject *e)
void setIsASCIIChecked(bool value=true)
size_t setDataLength(size_t l)
RexxInteger * caselessWordPos(RexxString *, RexxInteger *)
RexxObject * setBufferLength(size_t)
RexxInteger * caselessMatch(RexxInteger *start_, RexxString *other, RexxInteger *offset_, RexxInteger *len_)
RexxMutableBuffer * upper(RexxInteger *_start, RexxInteger *_length)
RexxInteger * countStrRexx(RexxString *needle)
RexxInteger * matchChar(RexxInteger *position_, RexxString *matchSet)
void copyData(size_t offset, const char *string, size_t l)
RexxString * makeString()
void adjustGap(size_t offset, size_t _size, size_t _newSize)
RexxObject * lengthRexx()
RexxInteger * caselessCountStrRexx(RexxString *needle)
RexxInteger * getBufferSize()
RexxInteger * wordLength(RexxInteger *)
RexxInteger * wordIndex(RexxInteger *)
RexxObject * setBufferSize(RexxInteger *)
static RexxClass * classInstance
void ensureCapacity(size_t addedLength)
RexxInteger * lastPos(RexxString *needle, RexxInteger *_start, RexxInteger *_range)
RexxMutableBuffer * overlay(RexxObject *, RexxObject *, RexxObject *, RexxObject *)
RexxInteger * caselessMatchChar(RexxInteger *position_, RexxString *matchSet)
char * setCapacity(size_t newLength)
RexxMutableBuffer * replaceAt(RexxObject *str, RexxObject *pos, RexxObject *len, RexxObject *pad)
char getCharB(size_t offset)
RexxString * subWord(RexxInteger *, RexxInteger *)
RexxString * primitiveMakeString()
RexxInteger * match(RexxInteger *start_, RexxString *other, RexxInteger *offset_, RexxInteger *len_)
RexxInteger * caselessPos(RexxString *needle, RexxInteger *_start, RexxInteger *_range)
RexxString * word(RexxInteger *)
RexxString * substr(RexxInteger *startPosition, RexxInteger *len, RexxString *pad)
void setLength(size_t l)
RexxMutableBuffer * insert(RexxObject *, RexxObject *, RexxObject *, RexxObject *)
RexxMessage * start(RexxObject **, size_t, size_t)
RexxObject * makeArrayRexx()
ssize_t codepoint_t
Definition: rexx.h:232
size_t stringsize_t
Definition: rexx.h:228