mbed library for NZ32-SC151

Committer:
modtronix-com
Date:
Fri Aug 19 15:46:42 2016 +1000
Revision:
17:639ed60ce759
Parent:
1:71204b8406f2
Added tag v1.1 for changeset 076cbe3e55be

Who changed what in which revision?

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