Mojo C++ bindings: better log message for serialization warnings.
[chromium-blink-merge.git] / native_client_sdk / src / libraries / nacl_io / path.h
blobc2a7c5eec22a72c42b44fced8ab4946f78a4292f
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.
5 #ifndef LIBRARIES_NACL_IO_PATH_H_
6 #define LIBRARIES_NACL_IO_PATH_H_
8 #include <string>
9 #include <vector>
11 #include "sdk_util/macros.h"
13 namespace nacl_io {
15 typedef std::vector<std::string> StringArray_t;
17 class Path {
18 public:
19 Path() {}
20 Path(const Path& path);
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);
27 // Return true of the first path item is '/'.
28 bool IsAbsolute() const;
30 // Return true if this is the root path (i.e. it has no parent)
31 bool IsRoot() const;
33 // Return a part of the path
34 const std::string& Part(size_t index) const;
36 // Return the number of path parts
37 size_t Size() const;
39 // Update the path.
40 Path& Append(const std::string& path);
41 Path& Prepend(const std::string& path);
42 Path& Set(const std::string& path);
44 // Return the parent path.
45 Path Parent() const;
46 std::string Basename() const;
48 std::string Join() const;
49 std::string Range(size_t start, size_t end) const;
50 StringArray_t Split() const;
52 // Collapse the string list removing extraneous '.', '..' path components
53 static StringArray_t Normalize(const StringArray_t& paths);
54 static std::string Join(const StringArray_t& paths);
55 static std::string Range(const StringArray_t& paths,
56 size_t start,
57 size_t end);
58 static StringArray_t Split(const std::string& paths);
59 // Operator versions
60 Path& operator=(const Path& p);
61 Path& operator=(const std::string& str);
62 bool operator==(const Path& other) { return Split() == other.Split(); }
63 bool operator!=(const Path& other) { return !operator==(other); }
65 private:
66 // Internal representation of the path stored an array of string representing
67 // the directory traversal. The first string is a "/" if this is an absolute
68 // path.
69 StringArray_t paths_;
72 } // namespace nacl_io
74 #endif // PACKAGES_LIBRARIES_NACL_IO_PATH_H_