Robert Murrell / Sketchlet
Committer:
aerialspecs
Date:
Fri Jan 20 14:58:52 2017 +0000
Revision:
0:42e6dbd4dbeb
Child:
3:bdd07af32afe
Initial import

Who changed what in which revision?

UserRevisionLine numberNew 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 #include "ArrayList.h"
aerialspecs 0:42e6dbd4dbeb 24
aerialspecs 0:42e6dbd4dbeb 25 namespace com {
aerialspecs 0:42e6dbd4dbeb 26 namespace aerialspecs {
aerialspecs 0:42e6dbd4dbeb 27 namespace mbed {
aerialspecs 0:42e6dbd4dbeb 28 namespace sketchlet {
aerialspecs 0:42e6dbd4dbeb 29
aerialspecs 0:42e6dbd4dbeb 30 template <class T> ArrayList<T>::ArrayList() {
aerialspecs 0:42e6dbd4dbeb 31 this->usize = ARRAYLIST_DEFAULT_SIZE;
aerialspecs 0:42e6dbd4dbeb 32 this->elements = new T[this->usize];
aerialspecs 0:42e6dbd4dbeb 33 this->index = 0;
aerialspecs 0:42e6dbd4dbeb 34 }
aerialspecs 0:42e6dbd4dbeb 35
aerialspecs 0:42e6dbd4dbeb 36 template <class T> ArrayList<T>::ArrayList(uint8_t usize) {
aerialspecs 0:42e6dbd4dbeb 37 this->usize = usize;
aerialspecs 0:42e6dbd4dbeb 38 this->elements = new T[this->usize];
aerialspecs 0:42e6dbd4dbeb 39 this->index = 0;
aerialspecs 0:42e6dbd4dbeb 40 }
aerialspecs 0:42e6dbd4dbeb 41
aerialspecs 0:42e6dbd4dbeb 42 template <class T> T ArrayList<T>::get(uint8_t at) {
aerialspecs 0:42e6dbd4dbeb 43 return this->elements[at];
aerialspecs 0:42e6dbd4dbeb 44 }
aerialspecs 0:42e6dbd4dbeb 45
aerialspecs 0:42e6dbd4dbeb 46 template <class T> void ArrayList<T>::append(T element) {
aerialspecs 0:42e6dbd4dbeb 47 this->elements[this->index] = element;
aerialspecs 0:42e6dbd4dbeb 48 ++this->index;
aerialspecs 0:42e6dbd4dbeb 49 }
aerialspecs 0:42e6dbd4dbeb 50
aerialspecs 0:42e6dbd4dbeb 51 template <class T> uint8_t ArrayList<T>::length() {
aerialspecs 0:42e6dbd4dbeb 52 return (this->index + 1);
aerialspecs 0:42e6dbd4dbeb 53 }
aerialspecs 0:42e6dbd4dbeb 54
aerialspecs 0:42e6dbd4dbeb 55 template <class T> uint8_t ArrayList<T>::size() {
aerialspecs 0:42e6dbd4dbeb 56 return this->usize;
aerialspecs 0:42e6dbd4dbeb 57 }
aerialspecs 0:42e6dbd4dbeb 58
aerialspecs 0:42e6dbd4dbeb 59 template <class T> Iterator<T>* ArrayList<T>::iterate() {
aerialspecs 0:42e6dbd4dbeb 60 return new Iterator<T>(this->elements, this->index);
aerialspecs 0:42e6dbd4dbeb 61 }
aerialspecs 0:42e6dbd4dbeb 62
aerialspecs 0:42e6dbd4dbeb 63 template <class T> ArrayList<T>::~ArrayList() {
aerialspecs 0:42e6dbd4dbeb 64 delete[] this->elements;
aerialspecs 0:42e6dbd4dbeb 65 }
aerialspecs 0:42e6dbd4dbeb 66
aerialspecs 0:42e6dbd4dbeb 67 }}}}