1 /* 2 * Copyright 2011, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _SUPPORT_BSTRING_LIST_H_ 6 #define _SUPPORT_BSTRING_LIST_H_ 7 8 9 #include <BeBuild.h> 10 #include <Flattenable.h> 11 #include <List.h> 12 #include <String.h> 13 14 15 class BStringList : public BFlattenable { 16 public: 17 BStringList(int32 count = 20); 18 BStringList(const BStringList& other); 19 virtual ~BStringList(); 20 21 // Adding and removing items. 22 bool Add(const BString& string, int32 index); 23 bool Add(const BString& string); 24 bool Add(const BStringList& list, int32 index); 25 bool Add(const BStringList& list); 26 27 bool Remove(const BString& string, 28 bool ignoreCase = false); 29 bool Remove(const BStringList& list, 30 bool ignoreCase = false); 31 BString Remove(int32 index); 32 bool Remove(int32 index, int32 count); 33 bool Replace(int32 index, const BString& string); 34 35 void MakeEmpty(); 36 37 // Reorder items 38 void Sort(bool ignoreCase = false); 39 // TODO: Sort() with custom sort function. 40 bool Swap(int32 indexA, int32 indexB); 41 bool Move(int32 fromIndex, int32 toIndex); 42 43 // Retrieve items 44 BString StringAt(int32 index) const; 45 BString First() const; 46 BString Last() const; 47 48 // Query 49 bool HasString(const BString& string, 50 bool ignoreCase = false) const; 51 int32 IndexOf(const BString& string, 52 bool ignoreCase = false) const; 53 int32 CountStrings() const; 54 bool IsEmpty() const; 55 56 // Iteration 57 void DoForEach(bool (*func)(const BString& string)); 58 void DoForEach(bool (*func)(const BString& string, 59 void* arg2), void* arg2); 60 61 BStringList& operator=(const BStringList& other); 62 bool operator==(const BStringList& other) const; 63 bool operator!=(const BStringList& other) const; 64 65 // BFlattenable 66 virtual bool IsFixedSize() const; 67 virtual type_code TypeCode() const; 68 virtual bool AllowsTypeCode(type_code code) const; 69 virtual ssize_t FlattenedSize() const; 70 virtual status_t Flatten(void* buffer, ssize_t size) const; 71 virtual status_t Unflatten(type_code code, const void* buffer, 72 ssize_t size); 73 74 private: 75 void _IncrementRefCounts() const; 76 void _DecrementRefCounts() const; 77 78 private: 79 BList fStrings; 80 }; 81 82 83 inline bool 84 BStringList::HasString(const BString& string, bool ignoreCase) const 85 { 86 return IndexOf(string, ignoreCase) >= 0; 87 } 88 89 90 inline bool 91 BStringList::operator!=(const BStringList& other) const 92 { 93 return !(*this == other); 94 } 95 96 97 #endif // _SUPPORT_BSTRING_LIST_H_ 98