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