xref: /haiku/headers/private/kernel/fs/KPath.h (revision e9c4d47ad719d6fd67cd9b75b41ebbec563e7a79)
1 /*
2  * Copyright 2004-2006, Ingo Weinhold, bonefish@users.sf.net.
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 
12 namespace BPrivate {
13 namespace DiskDevice {
14 
15 class KPath {
16 	public:
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 		void Adopt(KPath& other);
26 
27 		status_t InitCheck() const;
28 
29 		status_t SetPath(const char *path, bool normalize = false);
30 		const char *Path() const;
31 		size_t Length() const { return fPathLength; }
32 
33 		size_t BufferSize() const { return fBufferSize; }
34 		char *LockBuffer();
35 		void UnlockBuffer();
36 
37 		const char *Leaf() const;
38 		status_t ReplaceLeaf(const char *newLeaf);
39 		bool RemoveLeaf();
40 			// returns false, if nothing could be removed anymore
41 
42 		status_t Append(const char *toAppend, bool isComponent = true);
43 
44 		KPath& operator=(const KPath& other);
45 		KPath& operator=(const char* path);
46 
47 		bool operator==(const KPath& other) const;
48 		bool operator==(const char* path) const;
49 		bool operator!=(const KPath& other) const;
50 		bool operator!=(const char* path) const;
51 
52 	private:
53 		void _ChopTrailingSlashes();
54 
55 		char*	fBuffer;
56 		size_t	fBufferSize;
57 		size_t	fPathLength;
58 		bool	fLocked;
59 };
60 
61 } // namespace DiskDevice
62 } // namespace BPrivate
63 
64 using BPrivate::DiskDevice::KPath;
65 
66 #endif	/* _K_PATH_H */
67