The prosthetic control(MIT)

Committer:
ganlikun
Date:
Thu Jun 23 05:23:34 2022 +0000
Revision:
0:20e0c61e0684
01

Who changed what in which revision?

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