Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ArrayList.h@3:bdd07af32afe, 2017-01-20 (annotated)
- Committer:
- aerialspecs
- Date:
- Fri Jan 20 15:10:27 2017 +0000
- Revision:
- 3:bdd07af32afe
- Parent:
- 0:42e6dbd4dbeb
Removed default constructor from ArrayList. Embedded environment is too constrained to allow for arbitrary sizing.
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| aerialspecs | 0:42e6dbd4dbeb | 1 | /* | 
| aerialspecs | 0:42e6dbd4dbeb | 2 | * Copyright (c) 2017, Aerialspecs, Inc. | 
| aerialspecs | 0:42e6dbd4dbeb | 3 | * | 
| aerialspecs | 0:42e6dbd4dbeb | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy | 
| aerialspecs | 0:42e6dbd4dbeb | 5 | * of this software and associated documentation files (the "Software"), to deal | 
| aerialspecs | 0:42e6dbd4dbeb | 6 | * in the Software without restriction, including without limitation the rights | 
| aerialspecs | 0:42e6dbd4dbeb | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
| aerialspecs | 0:42e6dbd4dbeb | 8 | * copies of the Software, and to permit persons to whom the Software is | 
| aerialspecs | 0:42e6dbd4dbeb | 9 | * furnished to do so, subject to the following conditions: | 
| aerialspecs | 0:42e6dbd4dbeb | 10 | * | 
| aerialspecs | 0:42e6dbd4dbeb | 11 | * The above copyright notice and this permission notice shall be included in all | 
| aerialspecs | 0:42e6dbd4dbeb | 12 | * copies or substantial portions of the Software. | 
| aerialspecs | 0:42e6dbd4dbeb | 13 | * | 
| aerialspecs | 0:42e6dbd4dbeb | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
| aerialspecs | 0:42e6dbd4dbeb | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
| aerialspecs | 0:42e6dbd4dbeb | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 
| aerialspecs | 0:42e6dbd4dbeb | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
| aerialspecs | 0:42e6dbd4dbeb | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
| aerialspecs | 0:42e6dbd4dbeb | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | 
| aerialspecs | 0:42e6dbd4dbeb | 20 | * SOFTWARE. | 
| aerialspecs | 0:42e6dbd4dbeb | 21 | */ | 
| aerialspecs | 0:42e6dbd4dbeb | 22 | |
| aerialspecs | 0:42e6dbd4dbeb | 23 | #ifndef ARRAYLIST_H_ | 
| aerialspecs | 0:42e6dbd4dbeb | 24 | #define ARRAYLIST_H_ | 
| aerialspecs | 0:42e6dbd4dbeb | 25 | |
| aerialspecs | 0:42e6dbd4dbeb | 26 | |
| aerialspecs | 0:42e6dbd4dbeb | 27 | #include "stdint.h" | 
| aerialspecs | 0:42e6dbd4dbeb | 28 | #include "Iterator.h" | 
| aerialspecs | 0:42e6dbd4dbeb | 29 | |
| aerialspecs | 0:42e6dbd4dbeb | 30 | namespace com { | 
| aerialspecs | 0:42e6dbd4dbeb | 31 | namespace aerialspecs { | 
| aerialspecs | 0:42e6dbd4dbeb | 32 | namespace mbed { | 
| aerialspecs | 0:42e6dbd4dbeb | 33 | namespace sketchlet { | 
| aerialspecs | 0:42e6dbd4dbeb | 34 | |
| aerialspecs | 0:42e6dbd4dbeb | 35 | /** | 
| aerialspecs | 0:42e6dbd4dbeb | 36 | * \brief Class to represent a simple list of elements in an array. | 
| aerialspecs | 0:42e6dbd4dbeb | 37 | * | 
| aerialspecs | 0:42e6dbd4dbeb | 38 | * \author Robert R Murrell | 
| aerialspecs | 0:42e6dbd4dbeb | 39 | */ | 
| aerialspecs | 0:42e6dbd4dbeb | 40 | template <class T> | 
| aerialspecs | 0:42e6dbd4dbeb | 41 | class ArrayList { | 
| aerialspecs | 0:42e6dbd4dbeb | 42 | public: | 
| aerialspecs | 0:42e6dbd4dbeb | 43 | /** | 
| aerialspecs | 0:42e6dbd4dbeb | 44 | * \brief Creates a new ArrayList with an array size specified by usize. | 
| aerialspecs | 0:42e6dbd4dbeb | 45 | * | 
| aerialspecs | 0:42e6dbd4dbeb | 46 | * \param usize An unsigned byte specifying the array size, or the maximum number | 
| aerialspecs | 0:42e6dbd4dbeb | 47 | * of elements this array can have. | 
| aerialspecs | 0:42e6dbd4dbeb | 48 | */ | 
| aerialspecs | 0:42e6dbd4dbeb | 49 | ArrayList(uint8_t usize); | 
| aerialspecs | 0:42e6dbd4dbeb | 50 | |
| aerialspecs | 0:42e6dbd4dbeb | 51 | /** | 
| aerialspecs | 0:42e6dbd4dbeb | 52 | * \brief Appends an element to the and of the array. | 
| aerialspecs | 0:42e6dbd4dbeb | 53 | * | 
| aerialspecs | 0:42e6dbd4dbeb | 54 | * This is a template method so elements in an ArrayList will be strongly typed. | 
| aerialspecs | 0:42e6dbd4dbeb | 55 | * | 
| aerialspecs | 0:42e6dbd4dbeb | 56 | * \param element The element to add to the array. | 
| aerialspecs | 0:42e6dbd4dbeb | 57 | * | 
| aerialspecs | 0:42e6dbd4dbeb | 58 | * This method will increment the internal index by 1. | 
| aerialspecs | 0:42e6dbd4dbeb | 59 | */ | 
| aerialspecs | 0:42e6dbd4dbeb | 60 | virtual void append(T element); | 
| aerialspecs | 0:42e6dbd4dbeb | 61 | |
| aerialspecs | 0:42e6dbd4dbeb | 62 | virtual T get(uint8_t at); | 
| aerialspecs | 0:42e6dbd4dbeb | 63 | |
| aerialspecs | 0:42e6dbd4dbeb | 64 | /** | 
| aerialspecs | 0:42e6dbd4dbeb | 65 | * \brief Returns the number of element in the array. | 
| aerialspecs | 0:42e6dbd4dbeb | 66 | * | 
| aerialspecs | 0:42e6dbd4dbeb | 67 | * \return internal index + 1. | 
| aerialspecs | 0:42e6dbd4dbeb | 68 | */ | 
| aerialspecs | 0:42e6dbd4dbeb | 69 | virtual uint8_t length(); | 
| aerialspecs | 0:42e6dbd4dbeb | 70 | |
| aerialspecs | 0:42e6dbd4dbeb | 71 | /** | 
| aerialspecs | 0:42e6dbd4dbeb | 72 | * \brief Returns the maximum number of elements this ArrayList can hold. | 
| aerialspecs | 0:42e6dbd4dbeb | 73 | * | 
| aerialspecs | 0:42e6dbd4dbeb | 74 | * \return usize. | 
| aerialspecs | 0:42e6dbd4dbeb | 75 | */ | 
| aerialspecs | 0:42e6dbd4dbeb | 76 | virtual uint8_t size(); | 
| aerialspecs | 0:42e6dbd4dbeb | 77 | |
| aerialspecs | 0:42e6dbd4dbeb | 78 | /** | 
| aerialspecs | 0:42e6dbd4dbeb | 79 | * \brief Creates a new Iterator for this ArrayList. | 
| aerialspecs | 0:42e6dbd4dbeb | 80 | * | 
| aerialspecs | 0:42e6dbd4dbeb | 81 | * The Iterator is a "point-in-time" iterator in that the iterator can only count to | 
| aerialspecs | 0:42e6dbd4dbeb | 82 | * the length at the time of it's creation. An invocation of this method followed by | 
| aerialspecs | 0:42e6dbd4dbeb | 83 | * an addition of an element will not be reflected in the Iterator. Iterator is also | 
| aerialspecs | 0:42e6dbd4dbeb | 84 | * a template concept and will be strongly typed the same as this ArrayList. | 
| aerialspecs | 0:42e6dbd4dbeb | 85 | * | 
| aerialspecs | 0:42e6dbd4dbeb | 86 | * \return A new instance of Iterator. The caller must delete this Iterator when complete. | 
| aerialspecs | 0:42e6dbd4dbeb | 87 | */ | 
| aerialspecs | 0:42e6dbd4dbeb | 88 | virtual Iterator<T>* iterate(); | 
| aerialspecs | 0:42e6dbd4dbeb | 89 | |
| aerialspecs | 0:42e6dbd4dbeb | 90 | virtual ~ArrayList(); | 
| aerialspecs | 0:42e6dbd4dbeb | 91 | |
| aerialspecs | 0:42e6dbd4dbeb | 92 | private: | 
| aerialspecs | 0:42e6dbd4dbeb | 93 | uint8_t usize; | 
| aerialspecs | 0:42e6dbd4dbeb | 94 | uint8_t index; | 
| aerialspecs | 0:42e6dbd4dbeb | 95 | T* elements; | 
| aerialspecs | 0:42e6dbd4dbeb | 96 | }; | 
| aerialspecs | 0:42e6dbd4dbeb | 97 | |
| aerialspecs | 0:42e6dbd4dbeb | 98 | }}}} | 
| aerialspecs | 0:42e6dbd4dbeb | 99 | |
| aerialspecs | 0:42e6dbd4dbeb | 100 | #endif /* ARRAYLIST_H_ */ |