1/*
2 * Copyright 2002-2012, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _PATH_H
6#define _PATH_H
7
8
9#include <Flattenable.h>
10#include <Message.h>
11#include <StorageDefs.h>
12
13
14// Forward declarations
15class BDirectory;
16class BEntry;
17struct entry_ref;
18
19
20class BPath : public BFlattenable {
21public:
22							BPath();
23							BPath(const BPath& path);
24							BPath(const entry_ref* ref);
25							BPath(const BEntry* entry);
26							BPath(const char* dir, const char* leaf = NULL,
27								bool normalize = false);
28							BPath(const BDirectory* dir,
29								const char* leaf = NULL,
30								bool normalize = false);
31
32	virtual					~BPath();
33
34			status_t		InitCheck() const;
35
36			status_t		SetTo(const entry_ref* ref);
37			status_t		SetTo(const BEntry* entry);
38			status_t		SetTo(const char* path, const char* leaf = NULL,
39								bool normalize = false);
40			status_t		SetTo(const BDirectory* dir,
41								const char* leaf = NULL,
42								bool normalize = false);
43			void			Unset();
44
45			status_t		Append(const char* path, bool normalize = false);
46
47			const char*		Path() const;
48			const char*		Leaf() const;
49			status_t		GetParent(BPath* path) const;
50			bool			IsAbsolute() const;
51
52			bool			operator==(const BPath& item) const;
53			bool			operator==(const char* path) const;
54			bool			operator!=(const BPath& item) const;
55			bool			operator!=(const char* path) const;
56			BPath&			operator=(const BPath& item);
57			BPath&			operator=(const char* path);
58
59	// BFlattenable protocol
60	virtual	bool			IsFixedSize() const;
61	virtual	type_code		TypeCode() const;
62	virtual	ssize_t			FlattenedSize() const;
63	virtual	status_t		Flatten(void* buffer, ssize_t size) const;
64	virtual	bool			AllowsTypeCode(type_code code) const;
65	virtual	status_t		Unflatten(type_code code, const void* buffer,
66								ssize_t size);
67
68private:
69	virtual void			_WarPath1();
70	virtual void			_WarPath2();
71	virtual void			_WarPath3();
72
73			status_t		_SetPath(const char* path);
74	static	bool			_MustNormalize(const char* path, status_t* _error);
75
76			uint32			_reserved[4];
77
78			char*			fName;
79								// Pointer to the path string of the object.
80			status_t		fCStatus;
81								// The initialization status of the object.
82};
83
84#endif	// _PATH_H
85