initial

Dependencies:   mbed

Committer:
yihui
Date:
Mon Jan 11 02:32:24 2016 +0000
Revision:
0:638edba3adf6
initial

Who changed what in which revision?

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