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