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
00001 /* 00002 * Copyright (c) 2017, Aerialspecs, Inc. 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a copy 00005 * of this software and associated documentation files (the "Software"), to deal 00006 * in the Software without restriction, including without limitation the rights 00007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 * copies of the Software, and to permit persons to whom the Software is 00009 * furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included in all 00012 * copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00020 * SOFTWARE. 00021 */ 00022 00023 #ifndef ARRAYLIST_H_ 00024 #define ARRAYLIST_H_ 00025 00026 00027 #include "stdint.h" 00028 #include "Iterator.h" 00029 00030 namespace com { 00031 namespace aerialspecs { 00032 namespace mbed { 00033 namespace sketchlet { 00034 00035 /** 00036 * \brief Class to represent a simple list of elements in an array. 00037 * 00038 * \author Robert R Murrell 00039 */ 00040 template <class T> 00041 class ArrayList { 00042 public: 00043 /** 00044 * \brief Creates a new ArrayList with an array size specified by usize. 00045 * 00046 * \param usize An unsigned byte specifying the array size, or the maximum number 00047 * of elements this array can have. 00048 */ 00049 ArrayList(uint8_t usize); 00050 00051 /** 00052 * \brief Appends an element to the and of the array. 00053 * 00054 * This is a template method so elements in an ArrayList will be strongly typed. 00055 * 00056 * \param element The element to add to the array. 00057 * 00058 * This method will increment the internal index by 1. 00059 */ 00060 virtual void append(T element); 00061 00062 virtual T get(uint8_t at); 00063 00064 /** 00065 * \brief Returns the number of element in the array. 00066 * 00067 * \return internal index + 1. 00068 */ 00069 virtual uint8_t length(); 00070 00071 /** 00072 * \brief Returns the maximum number of elements this ArrayList can hold. 00073 * 00074 * \return usize. 00075 */ 00076 virtual uint8_t size(); 00077 00078 /** 00079 * \brief Creates a new Iterator for this ArrayList. 00080 * 00081 * The Iterator is a "point-in-time" iterator in that the iterator can only count to 00082 * the length at the time of it's creation. An invocation of this method followed by 00083 * an addition of an element will not be reflected in the Iterator. Iterator is also 00084 * a template concept and will be strongly typed the same as this ArrayList. 00085 * 00086 * \return A new instance of Iterator. The caller must delete this Iterator when complete. 00087 */ 00088 virtual Iterator<T>* iterate(); 00089 00090 virtual ~ArrayList(); 00091 00092 private: 00093 uint8_t usize; 00094 uint8_t index; 00095 T* elements; 00096 }; 00097 00098 }}}} 00099 00100 #endif /* ARRAYLIST_H_ */
Generated on Wed Jul 13 2022 16:05:25 by
1.7.2