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 
22 FileSystemPath::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 }
FileSystemPath::m_parent
String m_parent
Full path to our parent.
Definition: FileSystemPath.h:110
FileSystemPath.h
String::length
Size length() const
Same as count().
Definition: String.cpp:105
String
Abstraction of strings.
Definition: String.h:41
FileSystemPath::full
const String & full() const
Get the full path as a String.
Definition: FileSystemPath.cpp:58
List::head
Node * head()
Get the first Node on the list.
Definition: List.h:254
MemoryBlock.h
FileSystemPath::m_full
const String m_full
Full input path.
Definition: FileSystemPath.h:101
FileSystemPath::base
const String & base() const
The name of the last element in the path.
Definition: FileSystemPath.cpp:53
FileSystemPath::split
const List< String > & split() const
Returns a List of separate path elements.
Definition: FileSystemPath.cpp:63
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
FileSystemPath::m_base
const String m_base
Last element in the full path.
Definition: FileSystemPath.h:107
FileSystemPath::m_separator
const char m_separator
Separator character.
Definition: FileSystemPath.h:98
FileSystemPath::length
Size length() const
Get Length of our full path.
Definition: FileSystemPath.cpp:68
FileSystemPath::parent
const String & parent() const
Retrieve the full path of our parent.
Definition: FileSystemPath.cpp:48
FileSystemPath::m_path
const List< String > m_path
The path split in pieces by the separator.
Definition: FileSystemPath.h:104
String.h
List
Simple linked list template class.
Definition: List.h:36
ZERO
#define ZERO
Zero value.
Definition: Macros.h:43
FileSystemPath::FileSystemPath
FileSystemPath(const char *path, const char separator=DefaultSeparator)
Constructor using char pointer.
Definition: FileSystemPath.cpp:22