Yihui Xiong / Mbed 2 deprecated Seeed_nRF51822_Motion

Dependencies:   mbed

Committer:
yihui
Date:
Mon Jan 11 02:32:24 2016 +0000
Revision:
0:638edba3adf6
initial

Who changed what in which revision?

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