1 /* 2 * Copyright 2002-2009, 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 15 class BDirectory; 16 class BEntry; 17 struct entry_ref; 18 19 20 class BPath : public BFlattenable { 21 public: 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 51 bool operator==(const BPath& item) const; 52 bool operator==(const char* path) const; 53 bool operator!=(const BPath& item) const; 54 bool operator!=(const char* path) const; 55 BPath& operator=(const BPath& item); 56 BPath& operator=(const char* path); 57 58 // BFlattenable protocol 59 virtual bool IsFixedSize() const; 60 virtual type_code TypeCode() const; 61 virtual ssize_t FlattenedSize() const; 62 virtual status_t Flatten(void* buffer, ssize_t size) const; 63 virtual bool AllowsTypeCode(type_code code) const; 64 virtual status_t Unflatten(type_code code, const void* buffer, 65 ssize_t size); 66 67 private: 68 virtual void _WarPath1(); 69 virtual void _WarPath2(); 70 virtual void _WarPath3(); 71 72 status_t _SetPath(const char* path); 73 static bool _MustNormalize(const char* path, status_t* _error); 74 75 uint32 _reserved[4]; 76 77 char* fName; 78 status_t fCStatus; 79 }; 80 81 #endif // _PATH_H 82