StringList.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef ANKI_UTIL_STRING_LIST_H
  2. #define ANKI_UTIL_STRING_LIST_H
  3. #include "anki/util/Vector.h"
  4. #include "anki/util/StdTypes.h"
  5. #include <string>
  6. namespace anki {
  7. /// @addtogroup util
  8. /// @{
  9. /// @addtogroup containers
  10. /// @{
  11. /// A simple convenience class for string lists
  12. class StringList: public Vector<std::string>
  13. {
  14. public:
  15. typedef StringList Self; ///< Self type
  16. typedef Vector<std::string> Base; ///< Its the vector of strings
  17. typedef Base::value_type String; ///< Its string
  18. typedef String::value_type Char; ///< Char type
  19. enum StringListSort
  20. {
  21. SLS_ASCENDING = 0,
  22. SLS_DESCENDING
  23. };
  24. /// Join all the elements into a single big string using a the
  25. /// seperator @a sep
  26. String join(const Char* sep) const;
  27. /// Returns the index position of the last occurrence of @a value in
  28. /// the list
  29. /// @return -1 of not found
  30. I getIndexOf(const Char* value) const;
  31. /// Sort the string list
  32. void sortAll(const StringListSort method = SLS_ASCENDING);
  33. /// Split a string using a list of separators (@a sep) and return these
  34. /// strings in a string list
  35. static Self splitString(const Char* s, const Char sep = ' ',
  36. Bool keepEmpties = false);
  37. /// Mainly for the unit tests
  38. friend std::ostream& operator<<(std::ostream& s, const Self& a);
  39. };
  40. /// @}
  41. /// @}
  42. } // end namespace anki
  43. #endif