StringList.h 1.2 KB

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