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