Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / native_client_sdk / src / libraries / nacl_io / path.h
blob737e8f17d9d17e33fcf2e8a1e854a39023cf2ce4
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 <limits.h>
10 #include <string>
11 #include <vector>
13 #include "sdk_util/macros.h"
15 namespace nacl_io {
17 class Path {
18 public:
19 Path();
20 Path(const Path& path);
21 explicit Path(const std::string& path);
23 // Return true of the first path item is '/'.
24 bool IsAbsolute() const;
26 // Return true if this is the root path (i.e. it has no parent)
27 bool IsRoot() const;
29 // Return a part of the path
30 std::string Part(size_t index) const;
32 // Return the number of path parts
33 size_t Size() const;
35 // Update the path.
36 Path& Append(const Path& path);
37 Path& Append(const std::string& path);
38 Path& Set(const std::string& path);
39 Path& MakeRelative();
41 // Return the parent path.
42 Path Parent() const;
43 std::string Basename() const;
45 std::string Join() const;
46 std::string Range(size_t start, size_t end) const;
48 // Operator versions
49 Path& operator=(const Path& p);
50 Path& operator=(const std::string& str);
51 bool operator==(const Path& other);
52 bool operator!=(const Path& other);
54 private:
55 // Collapse the string list removing extraneous '.', '..' path components
56 void Normalize();
58 size_t len_;
59 char path_[PATH_MAX];
62 } // namespace nacl_io
64 #endif // PACKAGES_LIBRARIES_NACL_IO_PATH_H_