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