rau cha / mbed-src-I2CWaitFix

Fork of mbed-src by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FilePath.cpp Source File

FilePath.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #include "FilePath.h"
00017 
00018 namespace mbed {
00019 
00020 FilePath::FilePath(const char* file_path) : file_name(NULL), fb(NULL) {
00021     if ((file_path[0] != '/') || (file_path[1] == 0)) return;
00022 
00023     const char* file_system = &file_path[1];
00024     file_name = file_system;
00025     int len = 0;
00026     while (true) {
00027         char c = *file_name;
00028         if (c == '/') { // end of object name
00029             file_name++; // point to one char after the '/'
00030             break;
00031         }
00032         if (c == 0) { // end of object name, with no filename
00033             break;
00034         }
00035         len++;
00036         file_name++;
00037     }
00038 
00039     FileBase::lookup(file_system, len);
00040 
00041 
00042     fb = FileBase::lookup(file_system, len);
00043 }
00044 
00045 const char* FilePath::fileName(void) {
00046     return file_name;
00047 }
00048 
00049 bool FilePath::isFileSystem(void) {
00050     return (fb->getPathType() == FileSystemPathType);
00051 }
00052 
00053 FileSystemLike* FilePath::fileSystem(void) {
00054     if (isFileSystem()) {
00055         return (FileSystemLike*)fb;
00056     }
00057     return NULL;
00058 }
00059 
00060 bool FilePath::isFile(void) {
00061     return (fb->getPathType() == FilePathType);
00062 }
00063 
00064 FileLike* FilePath::file(void) {
00065     if (isFile()) {
00066         return (FileLike*)fb;
00067     }
00068     return NULL;
00069 }
00070 
00071 } // namespace mbed