KPath.h revision eac83fb3
1/*
2 * Copyright 2004-2008, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2008-2017, Axel D��rfler, axeld@pinc-software.de.
4 * Distributed under the terms of the MIT License.
5 */
6#ifndef _K_PATH_H
7#define _K_PATH_H
8
9
10#include <KernelExport.h>
11
12
13namespace BPrivate {
14namespace DiskDevice {
15
16class KPath {
17public:
18	enum {
19		DEFAULT = 0,
20		NORMALIZE = 0x01,
21		TRAVERSE_LEAF_LINK = 0x02,
22	};
23public:
24								KPath(size_t bufferSize = B_PATH_NAME_LENGTH);
25								KPath(const char* path, int32 flags = DEFAULT,
26									size_t bufferSize = B_PATH_NAME_LENGTH);
27								KPath(const KPath& other);
28								~KPath();
29
30			status_t			SetTo(const char* path, int32 flags = DEFAULT,
31									size_t bufferSize = B_PATH_NAME_LENGTH);
32			void				Adopt(KPath& other);
33
34			status_t			InitCheck() const;
35
36			status_t			SetPath(const char* path,
37									int32 flags = DEFAULT);
38			const char*			Path() const;
39			size_t				Length() const
40									{ return fPathLength; }
41
42			size_t				BufferSize() const
43									{ return fBufferSize; }
44			char*				LockBuffer();
45			void				UnlockBuffer();
46			char*				DetachBuffer();
47
48			const char*			Leaf() const;
49			status_t			ReplaceLeaf(const char* newLeaf);
50			bool				RemoveLeaf();
51				// returns false, if nothing could be removed anymore
52
53			status_t			Append(const char* toAppend,
54									bool isComponent = true);
55
56			status_t			Normalize(bool traverseLeafLink);
57
58			KPath&				operator=(const KPath& other);
59			KPath&				operator=(const char* path);
60
61			bool				operator==(const KPath& other) const;
62			bool				operator==(const char* path) const;
63			bool				operator!=(const KPath& other) const;
64			bool				operator!=(const char* path) const;
65
66private:
67			void				_ChopTrailingSlashes();
68
69			char*				fBuffer;
70			size_t				fBufferSize;
71			size_t				fPathLength;
72			bool				fLocked;
73};
74
75
76} // namespace DiskDevice
77} // namespace BPrivate
78
79
80using BPrivate::DiskDevice::KPath;
81
82
83#endif	/* _K_PATH_H */
84