mbed library for NZ32-SC151

Committer:
modtronix-com
Date:
Fri Aug 19 15:46:42 2016 +1000
Revision:
17:639ed60ce759
Parent:
1:71204b8406f2
Added tag v1.1 for changeset 076cbe3e55be

Who changed what in which revision?

UserRevisionLine numberNew contents of line
modtronix 1:71204b8406f2 1 /* mbed Microcontroller Library
modtronix 1:71204b8406f2 2 * Copyright (c) 2006-2013 ARM Limited
modtronix 1:71204b8406f2 3 *
modtronix 1:71204b8406f2 4 * Licensed under the Apache License, Version 2.0 (the "License");
modtronix 1:71204b8406f2 5 * you may not use this file except in compliance with the License.
modtronix 1:71204b8406f2 6 * You may obtain a copy of the License at
modtronix 1:71204b8406f2 7 *
modtronix 1:71204b8406f2 8 * http://www.apache.org/licenses/LICENSE-2.0
modtronix 1:71204b8406f2 9 *
modtronix 1:71204b8406f2 10 * Unless required by applicable law or agreed to in writing, software
modtronix 1:71204b8406f2 11 * distributed under the License is distributed on an "AS IS" BASIS,
modtronix 1:71204b8406f2 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
modtronix 1:71204b8406f2 13 * See the License for the specific language governing permissions and
modtronix 1:71204b8406f2 14 * limitations under the License.
modtronix 1:71204b8406f2 15 */
modtronix 1:71204b8406f2 16 #include "FileBase.h"
modtronix 1:71204b8406f2 17
modtronix 1:71204b8406f2 18 namespace mbed {
modtronix 1:71204b8406f2 19
modtronix 1:71204b8406f2 20 FileBase *FileBase::_head = NULL;
modtronix 1:71204b8406f2 21
modtronix 1:71204b8406f2 22 FileBase::FileBase(const char *name, PathType t) : _next(NULL),
modtronix 1:71204b8406f2 23 _name(name),
modtronix 1:71204b8406f2 24 _path_type(t) {
modtronix 1:71204b8406f2 25 if (name != NULL) {
modtronix 1:71204b8406f2 26 // put this object at head of the list
modtronix 1:71204b8406f2 27 _next = _head;
modtronix 1:71204b8406f2 28 _head = this;
modtronix 1:71204b8406f2 29 } else {
modtronix 1:71204b8406f2 30 _next = NULL;
modtronix 1:71204b8406f2 31 }
modtronix 1:71204b8406f2 32 }
modtronix 1:71204b8406f2 33
modtronix 1:71204b8406f2 34 FileBase::~FileBase() {
modtronix 1:71204b8406f2 35 if (_name != NULL) {
modtronix 1:71204b8406f2 36 // remove this object from the list
modtronix 1:71204b8406f2 37 if (_head == this) { // first in the list, so just drop me
modtronix 1:71204b8406f2 38 _head = _next;
modtronix 1:71204b8406f2 39 } else { // find the object before me, then drop me
modtronix 1:71204b8406f2 40 FileBase *p = _head;
modtronix 1:71204b8406f2 41 while (p->_next != this) {
modtronix 1:71204b8406f2 42 p = p->_next;
modtronix 1:71204b8406f2 43 }
modtronix 1:71204b8406f2 44 p->_next = _next;
modtronix 1:71204b8406f2 45 }
modtronix 1:71204b8406f2 46 }
modtronix 1:71204b8406f2 47 }
modtronix 1:71204b8406f2 48
modtronix 1:71204b8406f2 49 FileBase *FileBase::lookup(const char *name, unsigned int len) {
modtronix 1:71204b8406f2 50 FileBase *p = _head;
modtronix 1:71204b8406f2 51 while (p != NULL) {
modtronix 1:71204b8406f2 52 /* Check that p->_name matches name and is the correct length */
modtronix 1:71204b8406f2 53 if (p->_name != NULL && std::strncmp(p->_name, name, len) == 0 && std::strlen(p->_name) == len) {
modtronix 1:71204b8406f2 54 return p;
modtronix 1:71204b8406f2 55 }
modtronix 1:71204b8406f2 56 p = p->_next;
modtronix 1:71204b8406f2 57 }
modtronix 1:71204b8406f2 58 return NULL;
modtronix 1:71204b8406f2 59 }
modtronix 1:71204b8406f2 60
modtronix 1:71204b8406f2 61 FileBase *FileBase::get(int n) {
modtronix 1:71204b8406f2 62 FileBase *p = _head;
modtronix 1:71204b8406f2 63 int m = 0;
modtronix 1:71204b8406f2 64 while (p != NULL) {
modtronix 1:71204b8406f2 65 if (m == n) return p;
modtronix 1:71204b8406f2 66
modtronix 1:71204b8406f2 67 m++;
modtronix 1:71204b8406f2 68 p = p->_next;
modtronix 1:71204b8406f2 69 }
modtronix 1:71204b8406f2 70 return NULL;
modtronix 1:71204b8406f2 71 }
modtronix 1:71204b8406f2 72
modtronix 1:71204b8406f2 73 const char* FileBase::getName(void) {
modtronix 1:71204b8406f2 74 return _name;
modtronix 1:71204b8406f2 75 }
modtronix 1:71204b8406f2 76
modtronix 1:71204b8406f2 77 PathType FileBase::getPathType(void) {
modtronix 1:71204b8406f2 78 return _path_type;
modtronix 1:71204b8406f2 79 }
modtronix 1:71204b8406f2 80
modtronix 1:71204b8406f2 81 } // namespace mbed
modtronix 1:71204b8406f2 82