arraylist 42777 241 0 0 11556344752 10240 5 ustar 00IUSR0001 arraylist/arraylist_h.rpgle 100666 241 0 30213 11556346035 14001 0 ustar 00IUSR0001 /if not defined (ARRAYLIST_H)
/define ARRAYLIST_H
*-------------------------------------------------------------------------
*
* Copyright (c) 2011 Mihael Schmidt
* All rights reserved.
*
* This file is part of the ARRAYLIST service program.
*
* ARRAYLIST is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* ARRAYLIST is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with ARRAYLIST. If not, see http://www.gnu.org/licenses/.
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
* Prototypen
*-------------------------------------------------------------------------
D arraylist_create...
D PR * extproc('arraylist_create')
D initSize 10U 0 const options(*nopass)
D incSize 10U 0 const options(*nopass)
*
D arraylist_dispose...
D PR extproc('arraylist_dispose')
D vector *
*
D arraylist_add...
D PR extproc('arraylist_add')
D arraylist * const
D value * const
D valueLength 10U 0 const
D pos 10U 0 const options(*nopass)
*
D arraylist_addFirst...
D PR extproc('arraylist_addFirst')
D arraylist * const
D value * const
D valueLength 10U 0 const
*
D arraylist_addLast...
D PR extproc('arraylist_addLast')
D arraylist * const
D value * const
D valueLength 10U 0 const
*
D arraylist_get...
D PR * extproc('arraylist_get')
D arraylist * const
D index 10U 0 const
*
D arraylist_getFirst...
D PR * extproc('arraylist_getFirst')
D arraylist * const
*
D arraylist_getLast...
D PR * extproc('arraylist_getLast')
D arraylist * const
*
D arraylist_isEmpty...
D PR N extproc('arraylist_isEmpty')
D arraylist * const
*
D arraylist_getSize...
D PR 10U 0 extproc('arraylist_getSize')
D arraylist * const
*
D arraylist_getCapacity...
D PR 10U 0 extproc('arraylist_getCapacity')
D arraylist * const
*
D arraylist_clear...
D PR extproc('arraylist_clear')
D arraylist * const
*
D arraylist_remove...
D PR extproc('arraylist_remove')
D arraylist * const
D index 10U 0 const
*
D arraylist_removeFirst...
D PR extproc('arraylist_removeFirst')
D arraylist * const
*
D arraylist_removeLast...
D PR extproc('arraylist_removeLast')
D arraylist * const
*
D arraylist_removeRange...
D PR extproc('arraylist_removeRange')
D arraylist * const
D index 10U 0 const
D count 10U 0 const
*
D arraylist_contains...
D PR N extproc('arraylist_contains')
D arraylist * const
D value * const
D valueLength 10U 0 const
*
D arraylist_indexOf...
D PR 10I 0 extproc('arraylist_indexOf')
D arraylist * const
D value * const
D valueLength 10U 0 const
*
D arraylist_lastIndexOf...
D PR 10I 0 extproc('arraylist_lastIndexOf')
D arraylist * const
D valuePtr * const
D valueLength 10U 0 const
*
D arraylist_frequency...
D PR 10U 0 extproc('arraylist_frequency')
D arraylist * const
D value * const
D valueLength 10U 0 const
*
D arraylist_replace...
D PR extproc('arraylist_replace')
D arraylist * const
D index 10U 0 const
D value * const
D valueLength 10U 0 const
*
D arraylist_copy...
D PR * extproc('arraylist_copy')
D arraylist * const
*
D arraylist_sublist...
D PR * extproc('arraylist_sublist')
D arraylist * const
D startIndex 10U 0 const
D length 10U 0 const options(*nopass)
*
D arraylist_swap...
D PR extproc('arraylist_swap')
D arraylist * const
D itemPos1 10U 0 const
D itemPos2 10U 0 const
*
D arraylist_addAll...
D PR extproc('arraylist_addAll')
D destArraylist...
D * const
D sourceArraylist...
D * const
*
D arraylist_addInteger...
D PR extproc('arraylist_addInteger')
D arraylist * const
D value 10I 0 const
D index 10U 0 const options(*nopass)
*
D arraylist_addShort...
D PR extproc('arraylist_addShort')
D arraylist * const
D value 5I 0 const
D index 10U 0 const options(*nopass)
*
D arraylist_addLong...
D PR extproc('arraylist_addLong')
D arraylist * const
D value 20I 0 const
D index 10U 0 const options(*nopass)
*
D arraylist_addDecimal...
D PR extproc('arraylist_addDecimal')
D arraylist * const
D value 15P 5 const
D index 10U 0 const options(*nopass)
*
D arraylist_addFloat...
D PR extproc('arraylist_addFloat')
D arraylist * const
D value 4F const
D index 10U 0 const options(*nopass)
*
D arraylist_addDouble...
D PR extproc('arraylist_addDouble')
D arraylist * const
D value 8F const
D index 10U 0 const options(*nopass)
*
D arraylist_addDate...
D PR extproc('arraylist_addDate')
D arraylist * const
D value D const
D index 10U 0 const options(*nopass)
*
D arraylist_addBoolean...
D PR extproc('arraylist_addBoolean')
D arraylist * const
D value N const
D index 10U 0 const options(*nopass)
*
D arraylist_addString...
D PR extproc('arraylist_addString')
D arraylist * const
D value 65535A const varying
D index 10U 0 const options(*nopass)
*
D arraylist_getInteger...
D PR 10I 0 extproc('arraylist_getInteger')
D arraylist * const
D index 10U 0 const
*
D arraylist_getShort...
D PR 5I 0 extproc('arraylist_getShort')
D arraylist * const
D index 10U 0 const
*
D arraylist_getLong...
D PR 20I 0 extproc('arraylist_getLong')
D arraylist * const
D index 10U 0 const
*
D arraylist_getDecimal...
D PR 15P 5 extproc('arraylist_getDecimal')
D arraylist * const
D index 10U 0 const
*
D arraylist_getFloat...
D PR 4F extproc('arraylist_getFloat')
D arraylist * const
D index 10U 0 const
*
D arraylist_getDouble...
D PR 8F extproc('arraylist_getDouble')
D arraylist * const
D index 10U 0 const
*
D arraylist_getDate...
D PR D extproc('arraylist_getDate')
D arraylist * const
D index 10U 0 const
*
D arraylist_getBoolean...
D PR N extproc('arraylist_getBoolean')
D arraylist * const
D index 10U 0 const
*
D arraylist_getString...
D PR 65535A extproc('arraylist_getString')
D arraylist * const
D index 10U 0 const
*
D arraylist_foreach...
D PR extproc('arraylist_foreach')
D arraylist * const
D procPtr * const procptr
D userData * const
*
D arraylist_toCharArray...
D PR extproc('arraylist_toCharArray')
D arraylist * const
D arrayPtr * const
D count 10U 0 const
D length 10U 0 const
*
D arraylist_reverse...
D PR extproc('arraylist_reverse')
D arraylist * const
*
D arraylist_split...
D PR * extproc('arraylist_split')
D string 65535A const varying
D separator 1A const options(*nopass)
*
D arraylist_toString...
D PR 65535A varying extproc('arraylist_toString')
D arraylist * const
D separator 1A const options(*omit : *nopass)
D enclosing 100A const varying options(*nopass)
D enclosingEnd 100A const varying options(*nopass)
/endif
arraylist/arraylist.rpgle 100666 241 0 211077 11556073645 13527 0 ustar 00IUSR0001 /**
* \brief List Implementation : ArrayList
*
* A list implementation with a memory block as backend. The memory for
* will be dynamically allocated and deallocated. Therefore the list
* can grow and shrink dynamically as requested.
*
*
*
* This list implementation works with a head data structure.
*
*
*
* The entries are stored in an "array" which consists of pointers.
* The pointers of the array store the start address of the memory
* of the values.
*
*
*
* All values are internally null-terminated. So a value of x'00'
* won't work as expected and should be avoided.
*
*
*
* Access to the element is accomplished through accessing the arraylist
* with an index (position). The index is 0-based. So the first element
* has an index of 0 (zero).
*
* \author Mihael Schmidt
* \date 16.04.2011
*/
*------------------------------------------------------------------------
*
* Copyright (c) 2011 Mihael Schmidt
* All rights reserved.
*
* This file is part of the ARRAYLIST service program.
*
* ARRAYLIST is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* ARRAYLIST is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with ARRAYLIST. If not, see http://www.gnu.org/licenses/.
*
*------------------------------------------------------------------------
H nomain
HCOPYRIGHT('Copyright (c) 2011 Mihael Schmidt. All rights reserved.')
*---------------------------------------------------------------
* Prototypen
*---------------------------------------------------------------
D increment PR
D arraylist * const
D size 10U 0 const options(*nopass)
*
D sendEscapeMessage...
D PR
D message 65535A const varying
*
D getEntry...
D PR *
D arraylist * const
D pos 10I 0 const
*
D moveElements...
D PR
D arraylist * const
D pos 10U 0 const
D pDownBy 10I 0 const options(*nopass)
/include 'arraylist_h.rpgle'
/include 'libc_h.rpgle'
*-------------------------------------------------------------------------
* Constants
*-------------------------------------------------------------------------
*
* Incrementation size of 0 (zero) doubles the size of the array.
*
D DEFAULT_INCREMENT_SIZE...
D C 0
D DEFAULT_INIT_SIZE...
D C 10
*-------------------------------------------------------------------------
* Variables
*-------------------------------------------------------------------------
D tmpl_header DS qualified based(nullPointer) align
D elementsAllocated...
D 10I 0
D elementCount 10I 0
D elementData *
D incrementSize...
D 10U 0
*
D tmpl_entry DS qualified align based(nullPointer)
D value *
D length 10I 0
// so that the pointer is aligned on a 16-byte boundary we need to fill
// this data structure up to the next 16 byte
D reserved 12A
*
D hexNull S 1A inz(x'00')
*-------------------------------------------------------------------------
* Procedures
*-------------------------------------------------------------------------
/**
* \brief Create arraylist
*
* Creates an arraylist.
*
*
*
* The initial size is 10. The default increment size
* is 0 which means with each incrementation the arraylist will double its
* size.
*
* \author Mihael Schmidt
* \date 16.04.2011
*
* \param Initial arraylist size (default: 10)
* \param Incrementation size (default: 0 - double)
*
* \return Pointer to arraylist
*/
P arraylist_create...
P B export
D PI *
D initSize 10U 0 const options(*nopass)
D incSize 10U 0 const options(*nopass)
*
D arraylist S *
D header DS likeds(tmpl_header) based(arraylist)
/free
arraylist = %alloc(%size(tmpl_header));
header.elementCount = 0;
header.elementData = *null;
// init arraylist size if passed
if (%parms() = 0);
header.elementsAllocated = DEFAULT_INIT_SIZE;
header.incrementSize = DEFAULT_INCREMENT_SIZE;
elseif (%parms() = 1);
header.incrementSize = DEFAULT_INCREMENT_SIZE;
header.elementsAllocated = initSize;
elseif (%parms() = 2);
header.incrementSize = incSize;
header.elementsAllocated = initSize;
endif;
// alloc memory for entries
header.elementData =
%alloc(header.elementsAllocated * %size(tmpl_entry));
return arraylist;
/end-free
P E
/**
* \brief Dispose arraylist
*
* Disposes the arraylist and all its elements. The pointer will be set
* to *null.
*
* \author Mihael Schmidt
* \date 16.04.2011
*
* \param Pointer to arraylist
*/
P arraylist_dispose...
P B export
D PI
D arraylist *
*
D header DS likeds(tmpl_header) based(arraylist)
D i S 10I 0
/free
if (arraylist <> *null);
arraylist_clear(arraylist);
dealloc(n) arraylist;
endif;
/end-free
P E
/**
* \brief Add element
*
* Adds an element to the arraylist by copying the content to dynamically
* allocated memory. Values are stored null-terminated.
*
*
*
* If a position is passed the caller must be certain that the
* position is inside the bounds of the arraylist. If the position is
* outside of the arraylist an escape message will be sent.
*
* \author Mihael Schmidt
* \date 16.04.2011
*
* \param Pointer to arraylist
* \param Pointer to new entry
* \param Length of new entry (in byte)
* \param Position
*/
P arraylist_add B export
D PI
D arraylist * const
D value * const
D valueLength 10U 0 const
D pPos 10U 0 const options(*nopass)
*
D pos S 10U 0
D header DS likeds(tmpl_header) based(arraylist)
D ptr S *
D entry DS likeds(tmpl_entry) based(ptr)
/free
// determine the position
if (%parms() = 3);
pos = header.elementCount;
elseif (%parms() = 4);
// if a position was passed, check if it is inside the arraylist
if (pPos >= header.elementCount);
sendEscapeMessage('Position out of bounds');
else;
pos = pPos;
moveElements(arraylist : pos);
endif;
endif;
// make some space if necessary
if (header.elementCount = header.elementsAllocated);
increment(arraylist);
endif;
// get free entry
ptr = getEntry(arraylist : pos);
// alloc memory for this entry
entry.value = %alloc(valueLength + 1); // +1 for the null byte
entry.length = valueLength;
// copy value to the entry
memcpy(entry.value : value : valueLength);
// set null to the last byte
memcpy(entry.value + valueLength : %addr(hexNull) : 1);
// update header
header.elementCount += 1;
/end-free
P E
/**
* \brief Append element to the arraylist
*
* Adds an element to the end of the arraylist by copying the content to
* dynamically allocated memory. Values are stored null-terminated.
*
* \author Mihael Schmidt
* \date 16.04.2011
*
* \param Pointer to arraylist
* \param Pointer to new entry
* \param Length of new entry (in byte)
*/
P arraylist_addLast...
P B export
D PI
D arraylist * const
D value * const
D valueLength 10U 0 const
/free
arraylist_add(arraylist : value : valueLength);
/end-free
P E
/**
* \brief Prepend element to the arraylist
*
* Adds an element to the beginning of the arraylist by copying the content to
* dynamically allocated memory. Values are stored null-terminated. If the
* the arraylist is not empty all other elements will be pushed down by one
* position.
*
* \author Mihael Schmidt
* \date 16.04.2011
*
* \param Pointer to arraylist
* \param Pointer to new entry
* \param Length of new entry (in byte)
*/
P arraylist_addFirst...
P B export
D PI
D arraylist * const
D value * const
D valueLength 10U 0 const
/free
arraylist_add(arraylist : value : valueLength : 0);
/end-free
P E
/**
* \brief Get arraylist size
*
* Returns the number of elements currently in the arraylist.
*
* \author Mihael Schmidt
* \date 16.04.2011
*
* \param Pointer to arraylist
*
* \return Number of elements in the arraylist
*/
P arraylist_getSize...
P B export
D PI 10U 0
D arraylist * const
*
D header DS likeds(tmpl_header) based(arraylist)
D size S 10U 0
/free
return header.elementCount;
/end-free
P E
/**
* \brief Get arraylist capacity
*
* Returns the number of elements which can be stored in the current
* arraylist.
*
* \author Mihael Schmidt
* \date 16.04.2011
*
* \param Pointer to arraylist
*
* \return Number of elements able to store in the arraylist
*/
P arraylist_getCapacity...
P B export
D PI 10U 0
D arraylist * const
*
D header DS likeds(tmpl_header) based(arraylist)
D size S 10U 0
/free
return header.elementsAllocated;
/end-free
P E
/**
* \brief Get element
*
* Returns a pointer to the elment at the given position. The element is
* null-terminated. Changes to the element through the returned pointer is
* not recommended. Use the appropriate procedures instead.
*
*
*
* If the requested element position is not in the arraylist then an escape
* message will be sent.
*
* \author Mihael Schmidt
* \date 16.04.2011
*
* \param Pointer to arraylist
* \param Position
*
* \return Pointer to the null-terminated element
* or *null if arraylist is empty
*/
P arraylist_get B export
D PI *
D arraylist * const
D index 10U 0 const
*
D header DS likeds(tmpl_header) based(arraylist)
D ptr S *
D entry DS likeds(tmpl_entry) based(ptr)
/free
if (header.elementCount = 0);
return *null;
elseif (index >= header.elementCount);
sendEscapeMessage('Position out of bounds');
endif;
ptr = getEntry(arraylist : index);
return entry.value;
/end-free
P E
/**
* \brief Get first element
*
* Returns a pointer to the first elment in the arraylist. The element is
* null-terminated. Changes to the element through the returned pointer is
* not recommended. Use the appropriate procedures instead.
*
* \author Mihael Schmidt
* \date 16.04.2011
*
* \param Pointer to arraylist
*
* \return Pointer to the null-terminated element or *null if the arraylist is empty
*/
P arraylist_getFirst...
P B export
D PI *
D arraylist * const
*
D header DS likeds(tmpl_header) based(arraylist)
/free
return arraylist_get(arraylist : 0);
/end-free
P E
/**
* \brief Get last element
*
* Returns a pointer to the last elment in the arraylist. The element is
* null-terminated. Changes to the element through the returned pointer is
* not recommended. Use the appropriate procedures instead.
*
* \author Mihael Schmidt
* \date 16.04.2011
*
* \param Pointer to arraylist
*
* \return Pointer to the null-terminated element
* or *null if the arraylist is empty
*/
P arraylist_getLast...
P B export
D PI *
D arraylist * const
*
D header DS likeds(tmpl_header) based(arraylist)
/free
return arraylist_get(arraylist : header.elementCount - 1);
/end-free
P E
/**
* \brief Check if arraylist is empty
*
* Checks if the arraylist is empty.
*
* \author Mihael Schmidt
* \date 16.04.2011
*
* \param Pointer to the arraylist
*
* \return *on = arraylist is empty
* *off = arraylist is not empty
*/
P arraylist_isEmpty...
P B export
D PI N
D arraylist * const
*
D header DS likeds(tmpl_header) based(arraylist)
/free
return (header.elementCount = 0);
/end-free
P E
/**
* \brief Clear arraylist
*
* Deletes all entries. The capacity of the arraylist remains the same.
*
* \author Mihael Schmidt
* \date 16.04.2011
*
* \param Pointer to the arraylist
*/
P arraylist_clear...
P B export
D PI
D arraylist * const
*
D header DS likeds(tmpl_header) based(arraylist)
D i S 10I 0
D ptr S *
D entry DS likeds(tmpl_entry) based(ptr)
/free
for i = 0 to header.elementCount-1;
ptr = getEntry(arraylist : i);
dealloc(n) entry.value;
endfor;
// TODO reduce array size?
header.elementCount = 0;
/end-free
P E
/**
* \brief Remove an element
*
* Removes an element from the arraylist. If the given position is outside of
* the bounds of the arraylist an escape message will be sent.
*
* \author Mihael Schmidt
* \date 16.04.2011
*
* \param Pointer to the arraylist
* \param Element index to be removed
*/
P arraylist_remove...
P B export
D PI
D arraylist * const
D index 10U 0 const
*
D header DS likeds(tmpl_header) based(arraylist)
D ptr S *
D entry DS likeds(tmpl_entry) based(ptr)
/free
if (index >= header.elementCount);
sendEscapeMessage('Position out of bounds');
endif;
ptr = getEntry(arraylist : index);
dealloc(n) entry.value; // release allocated memory
// check if it is the last element
if (index <> header.elementCount -1); // not the last => move other elements
moveElements(arraylist : index + 1 : -1);
endif;
header.elementCount -= 1;
/end-free
P E
/**
* \brief Remove the first element
*
* Removes the first element from the arraylist.
*
* \author Mihael Schmidt
* \date 16.04.2011
*
* \param Pointer to the arraylist
*/
P arraylist_removeFirst...
P B export
D PI
D arraylist * const
/free
arraylist_remove(arraylist : 0);
/end-free
P E
/**
* \brief Remove the last element
*
* Removes the last element from the arraylist.
*
* \author Mihael Schmidt
* \date 16.04.2011
*
* \param Pointer to the arraylist
*/
P arraylist_removeLast...
P B export
D PI
D arraylist * const
*
D header DS likeds(tmpl_header) based(arraylist)
/free
if (header.elementCount > 0);
arraylist_remove(arraylist : arraylist_getSize(arraylist) - 1);
endif;
/end-free
P E
/**
* \brief Remove a range of elements
*
* Removes a range of elements from the arraylist. The range must be inside
* the bounds of the arraylist. If the range is outside the arraylist an
* escape message will be sent.
*
* \author Mihael Schmidt
* \date 16.04.2011
*
* \param Pointer to the arraylist
* \param Range starting index
* \param Number of elements to remove
*/
P arraylist_removeRange...
P B export
D PI
D arraylist * const
D index 10U 0 const
D count 10U 0 const
*
D header DS likeds(tmpl_header) based(arraylist)
D i S 10I 0
/free
if (index + count -1 >= header.elementCount);
sendEscapeMessage('Position out of bounds');
endif;
for i = index to index + count - 1;
// always index for position because the other elements have moved up by one
arraylist_remove(arraylist : index);
endfor;
/end-free
P E
/**
* \brief Contains element
*
* Checks if the arraylist contains the passed data.
* The check will be done byte by byte, so trailing spaces also count.
*
* \author Mihael Schmidt
* \date 16.04.2011
*
* \param Pointer to the arraylist
* \param Pointer to data
* \param Data length
*
* \return *on if the arraylist contains the data, *off otherwise
*/
P arraylist_contains...
P B export
D PI N
D arraylist * const
D value * const
D valueLength 10U 0 const
/free
return (arraylist_indexOf(arraylist : value : valueLength) >= 0);
/end-free
P E
/**
* \brief Get index of element
*
* Returns the index of the passed element.
*
* \author Mihael Schmidt
* \date 16.04.2011
*
* \param Pointer to the arraylist
* \param Pointer to data
* \param Data length
*
* \return index of the element or -1 if the element is not in the arraylist
*/
P arraylist_indexOf...
P B export
D PI 10I 0
D arraylist * const
D value * const
D valueLength 10U 0 const
*
D header DS likeds(tmpl_header) based(arraylist)
D ptr S *
D entry DS likeds(tmpl_entry) based(ptr)
D i S 10I 0
D retVal S 10I 0 inz(-1)
/free
for i = 0 to header.elementCount - 1;
ptr = header.elementData + (i * %size(tmpl_entry));
if (entry.length = valueLength);
if (memcmp(entry.value : value : valueLength) = 0);
retVal = i;
leave;
endif;
endif;
endfor;
return retVal;
/end-free
P E
/**
* \brief Get last index of element
*
* Returns the last index of the passed element.
*
* \author Mihael Schmidt
* \date 16.04.2011
*
* \param Pointer to the arraylist
* \param Pointer to data
* \param Data length
*
* \return last index of the element
* or -1 if the element is not in the arraylist
*/
P arraylist_lastIndexOf...
P B export
D PI 10I 0
D arraylist * const
D value * const
D valueLength 10U 0 const
*
D header DS likeds(tmpl_header) based(arraylist)
D ptr S *
D entry DS likeds(tmpl_entry) based(ptr)
D i S 10I 0
D retVal S 10I 0 inz(-1)
/free
for i = header.elementCount - 1 downto 0;
ptr = header.elementData + (i * %size(tmpl_entry));
if (entry.length = valueLength);
if (memcmp(entry.value : value : valueLength) = 0);
retVal = i;
leave;
endif;
endif;
endfor;
return retVal;
/end-free
P E
/**
* \brief Frequency of element
*
* Returns the number of times the passed element is in the arraylist.
*
* \author Mihael Schmidt
* \date 2011-04-19
*
* \param Pointer to the arraylist
* \param Pointer to data
* \param Data length
*
* \return frequency of the passed data in the arraylist
*/
P arraylist_frequency...
P B export
D PI 10U 0
D arraylist * const
D value * const
D valueLength 10U 0 const
*
D header DS likeds(tmpl_header) based(arraylist)
D ptr S *
D entry DS likeds(tmpl_entry) based(ptr)
D i S 10I 0
D retVal S 10U 0
/free
for i = 0 to header.elementCount - 1;
ptr = header.elementData + (i * %size(tmpl_entry));
if (entry.length = valueLength);
if (memcmp(entry.value : value : valueLength) = 0);
retVal += 1;
endif;
endif;
endfor;
return retVal;
/end-free
P E
/**
* \brief Replace element
*
* Replaces the given element with the new data.
*
* \author Mihael Schmidt
* \date 2011-04-19
*
* \param Pointer to the arraylist
* \param Index to data which should be replaced
* \param Pointer to the new data
* \param Length of the new data
*/
P arraylist_replace...
P B export
D PI
D arraylist * const
D index 10U 0 const
D value * const
D valueLength 10U 0 const
*
D header DS likeds(tmpl_header) based(arraylist)
D ptr S *
D entry DS likeds(tmpl_entry) based(ptr)
/free
// if a position was passed, check if it is inside the array
if (index >= header.elementCount);
sendEscapeMessage('Position out of bounds.');
endif;
// get entry
ptr = getEntry(arraylist : index);
// alloc memory for this entry
entry.value = %realloc(entry.value : valueLength + 1); // +1 for the null byte
entry.length = valueLength;
// copy value to the entry
memcpy(entry.value : value : valueLength);
// set null to the last byte
memcpy(entry.value + valueLength : %addr(hexNull) : 1);
/end-free
P E
/**
* \brief Create a sublist
*
* Returns a sublist of this arraylist.
*
* \author Mihael Schmidt
* \date 2011-04-19
*
* \param Pointer to the arraylist
*
* \return Pointer to the new arraylist (sublist)
*/
P arraylist_sublist...
P B export
D PI *
D arraylist * const
D startIndex 10U 0 const
D length 10U 0 const options(*nopass)
*
D header DS likeds(tmpl_header) based(arraylist)
D ptr S *
D entry DS likeds(tmpl_entry) based(ptr)
*
D i S 10U 0
D endIndex S 10U 0
D sublist S *
/free
sublist = arraylist_create();
if (%parms() = 3);
endIndex = startIndex + length;
endIndex -= 1;
else;
endIndex = header.elementCount - 1;
endif;
if (startIndex >= header.elementCount);
sendEscapeMessage('Start index position out of bounds.');
endif;
if (endIndex >= header.elementCount);
sendEscapeMessage('End index position out of bounds.');
endif;
for i = startIndex to endIndex;
ptr = getEntry(arraylist : i);
arraylist_add(sublist : entry.value : entry.length);
endfor;
return sublist;
/end-free
P E
/**
* \brief Create a copy of the arraylist
*
* Returns a copy of the arraylist.
*
* \author Mihael Schmidt
* \date 2011-04-19
*
* \param Pointer to the arraylist
*
* \return Pointer to the new arraylist
*/
P arraylist_copy...
P B export
D PI *
D arraylist * const
*
D copyList S *
/free
copyList = arraylist_sublist(arraylist : 0);
return copyList;
/end-free
P E
/**
* \brief Swap arraylist items
*
* \author Mihael Schmidt
* \date 2011-04-19
*
* \param Pointer to the arraylist
* \param Item to swap
* \param Item to swap
*/
P arraylist_swap...
P B export
D PI
D arraylist * const
D itemPos1 10U 0 const
D itemPos2 10U 0 const
*
D header DS likeds(tmpl_header) based(arraylist)
D ptr1 S *
D entry1 DS likeds(tmpl_entry) based(ptr1)
D ptr2 S *
D entry2 DS likeds(tmpl_entry) based(ptr2)
D tmpEntry DS likeds(tmpl_entry)
/free
// if a position was passed, check if it is inside the array
if (itemPos1 >= header.elementCount or
itemPos2 >= header.elementCount);
sendEscapeMessage('Position out of bounds');
endif;
ptr1 = getEntry(arraylist : itemPos1);
ptr2 = getEntry(arraylist : itemPos2);
tmpEntry = entry1;
entry1 = entry2;
entry2 = tmpEntry;
/end-free
P E
/**
* \brief Add all elements to the arraylist
*
* Adds all elements from the source arraylist to the destination arraylist.
*
* \param Pointer to the destination arraylist
* \param Pointer to the source arraylist
*/
P arraylist_addAll...
P B export
D PI
D destArraylist...
D * const
D sourceArraylist...
D * const
*
D header DS likeds(tmpl_header)
D based(sourceArraylist)
D ptr S *
D entry Ds likeds(tmpl_entry) based(ptr)
*
D i S 10U 0
/free
for i = 0 to header.elementCount -1;
ptr = getEntry(sourceArraylist : i);
arraylist_add(destArraylist : entry.value : entry.length);
endfor;
/end-free
P E
/**
* \brief Add integer value to the arraylist
*
* This procedure is a wrapper for the add procedure and
* adds an integer to the arraylist.
*
* \param Pointer to the arraylist
* \param Value
* \param Position (default: append)
*/
P arraylist_addInteger...
P B export
D PI
D arraylist * const
D value 10I 0 const
D index 10U 0 const options(*nopass)
*
D tmpValue S 10I 0
/free
tmpValue = value;
if (%parms() = 2);
arraylist_add(arraylist : %addr(tmpValue) : %size(tmpValue));
elseif (%parms() = 3);
arraylist_add(arraylist : %addr(tmpValue) : %size(tmpValue) : index);
endif;
/end-free
P E
/**
* \brief Add short integer value to the arraylist
*
* This procedure is a wrapper for the add procedure and
* adds a short integer to the arraylist.
*
* \param Pointer to the arraylist
* \param Value
* \param Position (default: append)
*/
P arraylist_addShort...
P B export
D PI
D arraylist * const
D value 5I 0 const
D index 10U 0 const options(*nopass)
*
D tmpValue S 5I 0
/free
tmpValue = value;
if (%parms() = 2);
arraylist_add(arraylist : %addr(tmpValue) : %size(tmpValue));
elseif (%parms() = 3);
arraylist_add(arraylist : %addr(tmpValue) : %size(tmpValue) : index);
endif;
/end-free
P E
/**
* \brief Add long integer value to the arraylist
*
* This procedure is a wrapper for the add procedure and
* adds a long integer to the arraylist.
*
* \param Pointer to the arraylist
* \param Value
* \param Position (default: append)
*/
P arraylist_addLong...
P B export
D PI
D arraylist * const
D value 20I 0 const
D index 10U 0 const options(*nopass)
*
D tmpValue S 20I 0
/free
tmpValue = value;
if (%parms() = 2);
arraylist_add(arraylist : %addr(tmpValue) : %size(tmpValue));
elseif (%parms() = 3);
arraylist_add(arraylist : %addr(tmpValue) : %size(tmpValue) : index);
endif;
/end-free
P E
/**
* \brief Add packed decimal value to the arraylist
*
* This procedure is a wrapper for the add procedure and
* adds a packed decimal to the arraylist.
*
* \param Pointer to the arraylist
* \param Value
* \param Position (default: append)
*/
P arraylist_addDecimal...
P B export
D PI
D arraylist * const
D value 15P 5 const
D index 10U 0 const options(*nopass)
*
D tmpValue S 15P 5
/free
tmpValue = value;
if (%parms() = 2);
arraylist_add(arraylist : %addr(tmpValue) : %size(tmpValue));
elseif (%parms() = 3);
arraylist_add(arraylist : %addr(tmpValue) : %size(tmpValue) : index);
endif;
/end-free
P E
/**
* \brief Add float value to the arraylist
*
* This procedure is a wrapper for the add procedure and
* adds a float to the arraylist.
*
* \param Pointer to the arraylist
* \param Value
* \param Position (default: append)
*/
P arraylist_addFloat...
P B export
D PI
D arraylist * const
D value 4F const
D index 10U 0 const options(*nopass)
*
D tmpValue S 4F
/free
tmpValue = value;
if (%parms() = 2);
arraylist_add(arraylist : %addr(tmpValue) : %size(tmpValue));
elseif (%parms() = 3);
arraylist_add(arraylist : %addr(tmpValue) : %size(tmpValue) : index);
endif;
/end-free
P E
/**
* \brief Add double value to the arraylist
*
* This procedure is a wrapper for the add procedure and
* adds a double to the arraylist.
*
* \param Pointer to the arraylist
* \param Value
* \param Position (default: append)
*/
P arraylist_addDouble...
P B export
D PI
D arraylist * const
D value 8F const
D index 10U 0 const options(*nopass)
*
D tmpValue S 8F
/free
tmpValue = value;
if (%parms() = 2);
arraylist_add(arraylist : %addr(tmpValue) : %size(tmpValue));
elseif (%parms() = 3);
arraylist_add(arraylist : %addr(tmpValue) : %size(tmpValue) : index);
endif;
/end-free
P E
/**
* \brief Add date value to the arraylist
*
* This procedure is a wrapper for the add procedure and
* adds a date to the arraylist.
*
* \param Pointer to the arraylist
* \param Value
* \param Position (default: append)
*/
P arraylist_addDate...
P B export
D PI
D arraylist * const
D value D const
D index 10U 0 const options(*nopass)
*
D tmpValue S D
/free
tmpValue = value;
if (%parms() = 2);
arraylist_add(arraylist : %addr(tmpValue) : %size(tmpValue));
elseif (%parms() = 3);
arraylist_add(arraylist : %addr(tmpValue) : %size(tmpValue) : index);
endif;
/end-free
P E
/**
* \brief Add boolean value to the arraylist
*
* This procedure is a wrapper for the add procedure and
* adds a boolean to the arraylist.
*
* \param Pointer to the arraylist
* \param Value
* \param Position (default: append)
*/
P arraylist_addBoolean...
P B export
D PI
D arraylist * const
D value N const
D index 10U 0 const options(*nopass)
*
D tmpValue S N
/free
tmpValue = value;
if (%parms() = 2);
arraylist_add(arraylist : %addr(tmpValue) : %size(tmpValue));
elseif (%parms() = 3);
arraylist_add(arraylist : %addr(tmpValue) : %size(tmpValue) : index);
endif;
/end-free
P E
/**
* \brief Add character value to the arraylist
*
* This procedure is a wrapper for the add procedure and
* adds a character string to the arraylist.
*
* \param Pointer to the arraylist
* \param Value
* \param Position (default: append)
*/
P arraylist_addString...
P B export
D PI
D arraylist * const
D value 65535A const varying
D index 10U 0 const options(*nopass)
*
D length S 10I 0
D string S 65535A varying
/free
string = value;
length = %len(value);
if (%parms() = 2);
arraylist_add(arraylist : %addr(string : *DATA) : length);
elseif (%parms() = 3);
arraylist_add(arraylist : %addr(string : *DATA) : length : index);
endif;
/end-free
P E
/**
* \brief Get integer value from arraylist
*
* Returns the previously inserted integer value from the arraylist.
* If the value cannot be interpreted as an integer an escape message
* will be sent.
*
* \param Pointer to the arraylist
* \param Position
*
* \return Value
*/
P arraylist_getInteger...
P B export
D PI 10I 0
D arraylist * const
D index 10U 0 const
*
D header DS likeds(tmpl_header) based(arraylist)
D ptr S *
D dataptr S * based(ptr)
D data S 10I 0 based(dataPtr)
D retVal S 10I 0
/free
// check if the arraylist is empty or the position is outside of the arraylist
if (header.elementCount = 0);
sendEscapeMessage('Position out of bounds');
return *loval;
elseif (index < 0 or index > header.elementCount -1);
sendEscapeMessage('Position out of bounds');
return *loval;
endif;
ptr = getEntry(arraylist : index);
monitor;
// test if the temp variable is filled with the right data for the type
// by moving the data from temp to another var (retVal in this case)
retVal = data;
return retVal;
on-error *all;
sendEscapeMessage('Invalid value type');
return *loval;
endmon;
/end-free
P E
/**
* \brief Get short integer value from arraylist
*
* Returns the previously inserted short integer value from the arraylist.
* If the value cannot be interpreted as a short integer an escape message
* will be sent.
*
* \param Pointer to the arraylist
* \param Position
*
* \return Value
*/
P arraylist_getShort...
P B export
D PI 5I 0
D arraylist * const
D index 10U 0 const
*
D header DS likeds(tmpl_header) based(arraylist)
D ptr S *
D dataptr S * based(ptr)
D data S 5I 0 based(dataPtr)
D retVal S 5I 0
/free
// check if the arraylist is empty or the position is outside of the arraylist
if (header.elementCount = 0);
sendEscapeMessage('Position out of bounds');
return *loval;
elseif (index < 0 or index > header.elementCount -1);
sendEscapeMessage('Position out of bounds');
return *loval;
endif;
ptr = getEntry(arraylist : index);
monitor;
// test if the temp variable is filled with the right data for the type
// by moving the data from temp to another var (retVal in this case)
retVal = data;
return retVal;
on-error *all;
sendEscapeMessage('Invalid value type');
return *loval;
endmon;
/end-free
P E
/**
* \brief Get long integer value from arraylist
*
* Returns the previously inserted long integer value from the arraylist.
* If the value cannot be interpreted as a long integer an escape message
* will be sent.
*
* \param Pointer to the arraylist
* \param Position
*
* \return Value
*/
P arraylist_getLong...
P B export
D PI 20I 0
D arraylist * const
D index 10U 0 const
*
D header DS likeds(tmpl_header) based(arraylist)
D ptr S *
D dataptr S * based(ptr)
D data S 20I 0 based(dataPtr)
D retVal S 20I 0
/free
// check if the arraylist is empty or the position is outside of the arraylist
if (header.elementCount = 0);
sendEscapeMessage('Position out of bounds');
return *loval;
elseif (index < 0 or index > header.elementCount -1);
sendEscapeMessage('Position out of bounds');
return *loval;
endif;
ptr = getEntry(arraylist : index);
monitor;
// test if the temp variable is filled with the right data for the type
// by moving the data from temp to another var (retVal in this case)
retVal = data;
return retVal;
on-error *all;
sendEscapeMessage('Invalid value type');
return *loval;
endmon;
/end-free
P E
/**
* \brief Get packed decimal value from arraylist
*
* Returns the previously inserted packed decimal value from the arraylist.
* If the value cannot be interpreted as a packed decimal an escape message
* will be sent.
*
* \param Pointer to the arraylist
* \param Position
*
* \return Value
*/
P arraylist_getDecimal...
P B export
D PI 15P 5
D arraylist * const
D index 10U 0 const
*
D header DS likeds(tmpl_header) based(arraylist)
D ptr S *
D dataptr S * based(ptr)
D data S 15P 5 based(dataPtr)
D retVal S 15P 5
/free
// check if the arraylist is empty or the position is outside of the arraylist
if (header.elementCount = 0);
sendEscapeMessage('Position out of bounds');
return *loval;
elseif (index < 0 or index > header.elementCount -1);
sendEscapeMessage('Position out of bounds');
return *loval;
endif;
ptr = getEntry(arraylist : index);
monitor;
// test if the temp variable is filled with the right data for the type
// by moving the data from temp to another var (retVal in this case)
retVal = data;
return retVal;
on-error *all;
sendEscapeMessage('Invalid value type');
return *loval;
endmon;
/end-free
P E
/**
* \brief Get float value from arraylist
*
* Returns the previously inserted float value from the arraylist.
* If the value cannot be interpreted as a float an escape message
* will be sent.
*
* \param Pointer to the arraylist
* \param Position
*
* \return Value
*/
P arraylist_getFloat...
P B export
D PI 4F
D arraylist * const
D index 10U 0 const
*
D header DS likeds(tmpl_header) based(arraylist)
D ptr S *
D dataptr S * based(ptr)
D data S 4F based(dataPtr)
D retVal S 4F
/free
// check if the arraylist is empty or the position is outside of the arraylist
if (header.elementCount = 0);
sendEscapeMessage('Position out of bounds');
return *loval;
elseif (index < 0 or index > header.elementCount -1);
sendEscapeMessage('Position out of bounds');
return *loval;
endif;
ptr = getEntry(arraylist : index);
monitor;
// test if the temp variable is filled with the right data for the type
// by moving the data from temp to another var (retVal in this case)
retVal = data;
return retVal;
on-error *all;
sendEscapeMessage('Invalid value type');
return *loval;
endmon;
/end-free
P E
/**
* \brief Get dobule value from arraylist
*
* Returns the previously inserted double value from the arraylist.
* If the value cannot be interpreted as a double an escape message
* will be sent.
*
* \param Pointer to the arraylist
* \param Position
*
* \return Value
*/
P arraylist_getDouble...
P B export
D PI 8F
D arraylist * const
D index 10U 0 const
*
D header DS likeds(tmpl_header) based(arraylist)
D ptr S *
D dataptr S * based(ptr)
D data S 8F based(dataPtr)
D retVal S 8F
/free
// check if the arraylist is empty or the position is outside of the arraylist
if (header.elementCount = 0);
sendEscapeMessage('Position out of bounds');
return *loval;
elseif (index < 0 or index > header.elementCount -1);
sendEscapeMessage('Position out of bounds');
return *loval;
endif;
ptr = getEntry(arraylist : index);
monitor;
// test if the temp variable is filled with the right data for the type
// by moving the data from temp to another var (retVal in this case)
retVal = data;
return retVal;
on-error *all;
sendEscapeMessage('Invalid value type');
return *loval;
endmon;
/end-free
P E
/**
* \brief Get date value from arraylist
*
* Returns the previously inserted date value from the arraylist.
* If the value cannot be interpreted as a date an escape message
* will be sent.
*
* \param Pointer to the arraylist
* \param Position
*
* \return Value
*/
P arraylist_getDate...
P B export
D PI D
D arraylist * const
D index 10U 0 const
*
D header DS likeds(tmpl_header) based(arraylist)
D ptr S *
D dataptr S * based(ptr)
D data S D based(dataPtr)
D retVal S D
/free
// check if the arraylist is empty or the position is outside of the arraylist
if (header.elementCount = 0);
sendEscapeMessage('Position out of bounds');
return *loval;
elseif (index < 0 or index > header.elementCount -1);
sendEscapeMessage('Position out of bounds');
return *loval;
endif;
ptr = getEntry(arraylist : index);
monitor;
// test if the temp variable is filled with the right data for the type
// by moving the data from temp to another var (retVal in this case)
retVal = data;
return retVal;
on-error *all;
sendEscapeMessage('Invalid value type');
return *loval;
endmon;
/end-free
P E
/**
* \brief Get boolean value from arraylist
*
* Returns the previously inserted boolean value from the arraylist.
* If the value cannot be interpreted as a boolean an escape message
* will be sent.
*
* \param Pointer to the arraylist
* \param Position
*
* \return Value
*/
P arraylist_getBoolean...
P B export
D PI N
D arraylist * const
D index 10U 0 const
*
D header DS likeds(tmpl_header) based(arraylist)
D ptr S *
D dataptr S * based(ptr)
D data S N based(dataPtr)
D retVal S N
/free
// check if the arraylist is empty or the position is outside of the arraylist
if (header.elementCount = 0);
sendEscapeMessage('Position out of bounds');
return *loval;
elseif (index < 0 or index > header.elementCount -1);
sendEscapeMessage('Position out of bounds');
return *loval;
endif;
ptr = getEntry(arraylist : index);
monitor;
// test if the temp variable is filled with the right data for the type
// by moving the data from temp to another var (retVal in this case)
retVal = data;
return retVal;
on-error *all;
sendEscapeMessage('Invalid value type');
return *loval;
endmon;
/end-free
P E
/**
* \brief Get character value from arraylist
*
* Returns the previously inserted character string value from the arraylist.
* If the value cannot be interpreted as a char value an escape message
* will be sent.
*
* \param Pointer to the arraylist
* \param Position
*
* \return Value
*/
P arraylist_getString...
P B export
D PI 65535A
D arraylist * const
D index 10U 0 const
*
D header DS likeds(tmpl_header) based(arraylist)
D ptr S *
D dataptr S * based(ptr)
D retVal S 65535A
/free
// check if the arraylist is empty or the position is outside of the arraylist
if (header.elementCount = 0);
sendEscapeMessage('Position out of bounds');
return *loval;
elseif (index < 0 or index > header.elementCount -1);
sendEscapeMessage('Position out of bounds');
return *loval;
endif;
ptr = getEntry(arraylist : index);
monitor;
// test if the temp variable is filled with the right data for the type
// by moving the data from temp to another var (retVal in this case)
retVal = %str(dataPtr);
return retVal;
on-error *all;
sendEscapeMessage('Invalid value type');
return *loval;
endmon;
/end-free
P E
/**
* \brief Execute procedure for every arraylist entry
*
* The passed procedure will be executed for every entry
* in the arraylist.
*
*
*
* The user can pass data through a pointer to the procedure.
* The pointer will not be touched by this procedure itself, so it
* can be *null.
*
*
*
* The value of list entry can be changed through the passed procedure.
*
*
*
* The parameters for the passed procedure are:
*