init

Dependencies:   mbed

Committer:
Nathan Yonkee
Date:
Fri Mar 02 07:12:37 2018 -0700
Revision:
9:d58e77ebd769
add mbed-os library

Who changed what in which revision?

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