- add sources.
[platform/framework/web/crosswalk.git] / src / native_client_sdk / src / libraries / nacl_io / path.h
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef LIBRARIES_NACL_IO_PATH_H_
6 #define LIBRARIES_NACL_IO_PATH_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "sdk_util/macros.h"
12
13 namespace nacl_io {
14
15 typedef std::vector<std::string> StringArray_t;
16
17 class Path {
18  public:
19   Path();
20   Path(const Path& path);
21
22   // This constructor splits path by '/' as a starting point for this Path.
23   // If the path begins with the character '/', the path is considered
24   // to be absolute.
25   explicit Path(const std::string& path);
26   ~Path();
27
28
29   // Return true of the first path item is '/'.
30   bool IsAbsolute() const;
31
32   // Return a part of the path
33   const std::string& Part(size_t index) const;
34
35   // Return the number of path parts
36   size_t Size() const;
37
38   // Return true of this is the top of the path
39   bool Top() const;
40
41   // Update the path.
42   Path& Append(const std::string& path);
43   Path& Prepend(const std::string& path);
44   Path& Set(const std::string& path);
45
46   // Return the parent path.
47   Path Parent() const;
48   std::string Basename() const;
49
50   std::string Join() const;
51   std::string Range(size_t start, size_t end) const;
52   StringArray_t Split() const;
53
54   // Collapse the string list removing extraneous '.', '..' path components
55   static StringArray_t Normalize(const StringArray_t& paths);
56   static std::string Join(const StringArray_t& paths);
57   static std::string Range(const StringArray_t& paths, size_t start,
58                            size_t end);
59   static StringArray_t Split(const std::string& paths);
60   // Operator versions
61   Path& operator=(const Path& p);
62   Path& operator=(const std::string& str);
63
64  private:
65   // Internal representation of the path stored an array of string representing
66   // the directory traversal.  The first string is a "/" if this is an absolute
67   // path.
68   StringArray_t paths_;
69 };
70
71 }  // namespace nacl_io
72
73 #endif  // PACKAGES_LIBRARIES_NACL_IO_PATH_H_