TUKS MCU Introductory course / TUKS-COURSE-TIMER
Committer:
elmot
Date:
Fri Feb 24 21:13:56 2017 +0000
Revision:
1:d0dfbce63a89
Ready-to-copy

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elmot 1:d0dfbce63a89 1 /* mbed Microcontroller Library
elmot 1:d0dfbce63a89 2 * Copyright (c) 2006-2013 ARM Limited
elmot 1:d0dfbce63a89 3 *
elmot 1:d0dfbce63a89 4 * Licensed under the Apache License, Version 2.0 (the "License");
elmot 1:d0dfbce63a89 5 * you may not use this file except in compliance with the License.
elmot 1:d0dfbce63a89 6 * You may obtain a copy of the License at
elmot 1:d0dfbce63a89 7 *
elmot 1:d0dfbce63a89 8 * http://www.apache.org/licenses/LICENSE-2.0
elmot 1:d0dfbce63a89 9 *
elmot 1:d0dfbce63a89 10 * Unless required by applicable law or agreed to in writing, software
elmot 1:d0dfbce63a89 11 * distributed under the License is distributed on an "AS IS" BASIS,
elmot 1:d0dfbce63a89 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
elmot 1:d0dfbce63a89 13 * See the License for the specific language governing permissions and
elmot 1:d0dfbce63a89 14 * limitations under the License.
elmot 1:d0dfbce63a89 15 */
elmot 1:d0dfbce63a89 16 #include "drivers/FilePath.h"
elmot 1:d0dfbce63a89 17
elmot 1:d0dfbce63a89 18 namespace mbed {
elmot 1:d0dfbce63a89 19
elmot 1:d0dfbce63a89 20 FilePath::FilePath(const char* file_path) : file_name(NULL), fb(NULL) {
elmot 1:d0dfbce63a89 21 if ((file_path[0] != '/') || (file_path[1] == 0)) return;
elmot 1:d0dfbce63a89 22
elmot 1:d0dfbce63a89 23 const char* file_system = &file_path[1];
elmot 1:d0dfbce63a89 24 file_name = file_system;
elmot 1:d0dfbce63a89 25 int len = 0;
elmot 1:d0dfbce63a89 26 while (true) {
elmot 1:d0dfbce63a89 27 char c = *file_name;
elmot 1:d0dfbce63a89 28 if (c == '/') { // end of object name
elmot 1:d0dfbce63a89 29 file_name++; // point to one char after the '/'
elmot 1:d0dfbce63a89 30 break;
elmot 1:d0dfbce63a89 31 }
elmot 1:d0dfbce63a89 32 if (c == 0) { // end of object name, with no filename
elmot 1:d0dfbce63a89 33 break;
elmot 1:d0dfbce63a89 34 }
elmot 1:d0dfbce63a89 35 len++;
elmot 1:d0dfbce63a89 36 file_name++;
elmot 1:d0dfbce63a89 37 }
elmot 1:d0dfbce63a89 38
elmot 1:d0dfbce63a89 39 fb = FileBase::lookup(file_system, len);
elmot 1:d0dfbce63a89 40 }
elmot 1:d0dfbce63a89 41
elmot 1:d0dfbce63a89 42 const char* FilePath::fileName(void) {
elmot 1:d0dfbce63a89 43 return file_name;
elmot 1:d0dfbce63a89 44 }
elmot 1:d0dfbce63a89 45
elmot 1:d0dfbce63a89 46 bool FilePath::isFileSystem(void) {
elmot 1:d0dfbce63a89 47 if (NULL == fb)
elmot 1:d0dfbce63a89 48 return false;
elmot 1:d0dfbce63a89 49 return (fb->getPathType() == FileSystemPathType);
elmot 1:d0dfbce63a89 50 }
elmot 1:d0dfbce63a89 51
elmot 1:d0dfbce63a89 52 FileSystemLike* FilePath::fileSystem(void) {
elmot 1:d0dfbce63a89 53 if (isFileSystem()) {
elmot 1:d0dfbce63a89 54 return (FileSystemLike*)fb;
elmot 1:d0dfbce63a89 55 }
elmot 1:d0dfbce63a89 56 return NULL;
elmot 1:d0dfbce63a89 57 }
elmot 1:d0dfbce63a89 58
elmot 1:d0dfbce63a89 59 bool FilePath::isFile(void) {
elmot 1:d0dfbce63a89 60 if (NULL == fb)
elmot 1:d0dfbce63a89 61 return false;
elmot 1:d0dfbce63a89 62 return (fb->getPathType() == FilePathType);
elmot 1:d0dfbce63a89 63 }
elmot 1:d0dfbce63a89 64
elmot 1:d0dfbce63a89 65 FileLike* FilePath::file(void) {
elmot 1:d0dfbce63a89 66 if (isFile()) {
elmot 1:d0dfbce63a89 67 return (FileLike*)fb;
elmot 1:d0dfbce63a89 68 }
elmot 1:d0dfbce63a89 69 return NULL;
elmot 1:d0dfbce63a89 70 }
elmot 1:d0dfbce63a89 71
elmot 1:d0dfbce63a89 72 bool FilePath::exists(void) {
elmot 1:d0dfbce63a89 73 return fb != NULL;
elmot 1:d0dfbce63a89 74 }
elmot 1:d0dfbce63a89 75
elmot 1:d0dfbce63a89 76 } // namespace mbed