mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
FilePath.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 #include "platform/FilePath.h" 00018 00019 namespace mbed { 00020 00021 FilePath::FilePath(const char *file_path) : file_name(NULL), fb(NULL) 00022 { 00023 // skip slashes 00024 file_path += strspn(file_path, "/"); 00025 00026 const char *file_system = file_path; 00027 file_name = file_system; 00028 int len = 0; 00029 while (true) { 00030 char c = *file_name; 00031 if (c == '/') { // end of object name 00032 file_name++; // point to one char after the '/' 00033 break; 00034 } 00035 if (c == 0) { // end of object name, with no filename 00036 break; 00037 } 00038 len++; 00039 file_name++; 00040 } 00041 00042 MBED_ASSERT(len != 0); 00043 fb = FileBase::lookup(file_system, len); 00044 } 00045 00046 const char *FilePath::fileName(void) 00047 { 00048 return file_name; 00049 } 00050 00051 bool FilePath::isFileSystem(void) 00052 { 00053 if (NULL == fb) { 00054 return false; 00055 } 00056 return (fb->getPathType() == FileSystemPathType); 00057 } 00058 00059 FileSystemLike *FilePath::fileSystem(void) 00060 { 00061 if (isFileSystem()) { 00062 return static_cast<FileSystemLike *>(fb); 00063 } 00064 return NULL; 00065 } 00066 00067 bool FilePath::isFile(void) 00068 { 00069 if (NULL == fb) { 00070 return false; 00071 } 00072 return (fb->getPathType() == FilePathType); 00073 } 00074 00075 FileLike *FilePath::file(void) 00076 { 00077 if (isFile()) { 00078 return (FileLike *)fb; 00079 } 00080 return NULL; 00081 } 00082 00083 bool FilePath::exists(void) 00084 { 00085 return fb != NULL; 00086 } 00087 00088 } // namespace mbed
Generated on Tue Jul 12 2022 20:41:14 by 1.7.2