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