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