xref: /haiku/headers/private/kernel/boot/PathBlocklist.h (revision fc7456e9b1ec38c941134ed6d01c438cf289381e)
1 /*
2  * Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef KERNEL_BOOT_PATH_BLOCKLIST_H
6 #define KERNEL_BOOT_PATH_BLOCKLIST_H
7 
8 
9 #include <string.h>
10 
11 #include <util/SinglyLinkedList.h>
12 
13 
14 class BlockedPath : public SinglyLinkedListLinkImpl<BlockedPath> {
15 public:
16 								BlockedPath();
17 								~BlockedPath();
18 
19 			bool				SetTo(const char* path);
20 
21 			bool				Append(const char* component);
22 
23 			const char*			Path() const
24 									{ return fPath != NULL ? fPath : ""; }
25 
26 			size_t				Length() const
27 									{ return fLength; }
28 
29 			bool				operator==(const char* path) const
30 									{ return strcmp(Path(), path) == 0; }
31 
32 private:
33 			bool				_Resize(size_t length, bool keepData);
34 
35 private:
36 			char*				fPath;
37 			size_t				fLength;
38 			size_t				fCapacity;
39 };
40 
41 
42 class PathBlocklist {
43 public:
44 			typedef SinglyLinkedList<BlockedPath>::ConstIterator Iterator;
45 
46 public:
47 								PathBlocklist();
48 								~PathBlocklist();
49 
50 			bool				Add(const char* path);
51 			void				Remove(const char* path);
52 			bool				Contains(const char* path) const;
53 			void				MakeEmpty();
54 
55 			bool				IsEmpty() const
56 									{ return fPaths.IsEmpty(); }
57 
58 			Iterator			GetIterator() const
59 									{ return fPaths.GetIterator(); }
60 
61 private:
62 			BlockedPath*	_FindPath(const char* path) const;
63 
64 private:
65 			typedef SinglyLinkedList<BlockedPath> PathList;
66 
67 private:
68 			PathList			fPaths;
69 };
70 
71 
72 #endif	// KERNEL_BOOT_PATH_BLOCKLIST_H
73