StringList.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright (C) 2009-2015, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #ifndef ANKI_UTIL_STRING_LIST_H
  6. #define ANKI_UTIL_STRING_LIST_H
  7. #include "anki/util/String.h"
  8. #include "anki/util/List.h"
  9. #include <algorithm>
  10. namespace anki {
  11. // Forward
  12. template<typename TAlloc>
  13. class StringListBase;
  14. /// @addtogroup util_private
  15. /// @{
  16. template<typename TAlloc>
  17. using StringListBaseScopeDestroyer =
  18. ScopeDestroyer<StringListBase<TAlloc>, TAlloc>;
  19. /// @}
  20. /// @addtogroup util_containers
  21. /// @{
  22. /// A simple convenience class for string lists
  23. template<typename TAlloc>
  24. class StringListBase: public List<StringBase<TAlloc>>
  25. {
  26. public:
  27. using Self = StringListBase; ///< Self type
  28. using Char = char; ///< Char type
  29. using Allocator = TAlloc;
  30. using String = StringBase<Allocator>; ///< String type
  31. using Base = List<String>; ///< Base
  32. using ScopeDestroyer = StringListBaseScopeDestroyer<Allocator>;
  33. /// Sort method for sortAll().
  34. enum class Sort
  35. {
  36. ASCENDING,
  37. DESCENDING
  38. };
  39. // Use the base constructors
  40. using Base::Base;
  41. void destroy(Allocator alloc);
  42. /// Join all the elements into a single big string using a the
  43. /// seperator @a separator
  44. ANKI_USE_RESULT Error join(
  45. Allocator alloc, const CString& separator, String& out) const;
  46. /// Returns the index position of the last occurrence of @a value in
  47. /// the list
  48. /// @return -1 of not found
  49. I getIndexOf(const CString& value) const;
  50. /// Sort the string list
  51. void sortAll(const Sort method = Sort::ASCENDING);
  52. /// Push at the end of the list a formated string
  53. template<typename... TArgs>
  54. ANKI_USE_RESULT Error pushBackSprintf(
  55. Allocator alloc, const TArgs&... args);
  56. /// Split a string using a separator (@a separator) and return these
  57. /// strings in a string list
  58. ANKI_USE_RESULT Error splitString(
  59. Allocator alloc, const CString& s, const Char separator);
  60. };
  61. /// A common string list allocated in heap.
  62. using StringList = StringListBase<HeapAllocator<char>>;
  63. /// @}
  64. } // end namespace anki
  65. #include "anki/util/StringList.inl.h"
  66. #endif