FreeNOS
FileSystemPath.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2009 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <String.h>
19#include <MemoryBlock.h>
20#include "FileSystemPath.h"
21
22FileSystemPath::FileSystemPath(const char *path, const char separator)
23 : m_separator(separator)
24 , m_full(path)
25 , m_path(m_full.split(m_separator))
26 , m_base(m_path.count() > 0 ? m_path.last() : "")
27 , m_parent()
28{
29 // Create parent, if any
30 if (m_path.head() && m_path.head()->next)
31 {
32 const char tmp[] = { m_separator, ZERO };
33 m_parent << tmp;
34
35 // Construct parent path
36 for (const List<String>::Node *l = m_path.head(); l && l->next; l = l->next)
37 {
38 m_parent << *l->data;
39
40 if (l->next && l->next->next)
41 {
42 m_parent << tmp;
43 }
44 }
45 }
46}
47
49{
50 return m_parent;
51}
52
54{
55 return m_base;
56}
57
59{
60 return m_full;
61}
62
64{
65 return m_path;
66}
67
69{
70 return m_full.length();
71}
const List< String > m_path
The path split in pieces by the separator.
const String & full() const
Get the full path as a String.
String m_parent
Full path to our parent.
const List< String > & split() const
Returns a List of separate path elements.
const String & parent() const
Retrieve the full path of our parent.
FileSystemPath(const char *path, const char separator=DefaultSeparator)
Constructor using char pointer.
const String m_full
Full input path.
const char m_separator
Separator character.
const String m_base
Last element in the full path.
Size length() const
Get Length of our full path.
const String & base() const
The name of the last element in the path.
Represents an item on the List.
Definition List.h:44
Simple linked list template class.
Definition List.h:37
Node * head()
Get the first Node on the list.
Definition List.h:254
Abstraction of strings.
Definition String.h:42
Size length() const
Same as count().
Definition String.cpp:105
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
#define ZERO
Zero value.
Definition Macros.h:43