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.
CellularList.h
00001 /* 00002 * Copyright (c) 2017, Arm Limited and affiliates. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #ifndef CELLULAR_LIST_H_ 00019 #define CELLULAR_LIST_H_ 00020 00021 #include <stddef.h> 00022 00023 namespace mbed { 00024 00025 /** Class CellularList 00026 * 00027 * Templated linked list class for common usage. 00028 * 00029 */ 00030 template <class T> class CellularList 00031 { 00032 private: 00033 T *_head, *_tail; 00034 public: 00035 CellularList() 00036 { 00037 _head=NULL; 00038 _tail=NULL; 00039 } 00040 00041 ~CellularList() 00042 { 00043 T *temp = _head; 00044 while (temp) { 00045 _head = _head->next; 00046 delete temp; 00047 temp = _head; 00048 } 00049 } 00050 00051 T* add_new() 00052 { 00053 T *temp=new T; 00054 if (!temp) { 00055 return NULL; 00056 } 00057 temp->next = NULL; 00058 if (_head == NULL) { 00059 _head = temp; 00060 } else { 00061 _tail->next=temp; 00062 } 00063 _tail = temp; 00064 00065 return _tail; 00066 } 00067 00068 void delete_last() 00069 { 00070 T* previous = NULL; 00071 T *current=_head; 00072 00073 if (!current) { 00074 return; 00075 } 00076 00077 while (current->next != NULL) { 00078 previous=current; 00079 current=current->next; 00080 } 00081 00082 if (previous) { 00083 _tail=previous; 00084 previous->next=NULL; 00085 } else { 00086 _head = NULL; 00087 _tail = NULL; 00088 } 00089 00090 delete current; 00091 } 00092 00093 void delete_all() 00094 { 00095 T *temp = _head; 00096 while (temp) { 00097 _head = _head->next; 00098 delete temp; 00099 temp = _head; 00100 } 00101 _tail=NULL; 00102 } 00103 00104 00105 T *get_head() 00106 { 00107 return _head; 00108 } 00109 }; 00110 00111 } // namespace mbed 00112 00113 #endif // CELLULAR_LIST_H_
Generated on Tue Jul 12 2022 18:18:29 by
