daeUtils.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // A home for commonly used utility functions. These are mostly for internal DOM
  2. // use, but the automated tests use some of these functions, so we'll export
  3. // them.
  4. #ifndef daeUtils_h
  5. #define daeUtils_h
  6. #include <string>
  7. #include <sstream>
  8. #include <list>
  9. #include <vector>
  10. #include <dae/daePlatform.h>
  11. namespace cdom {
  12. // System type info. We only need to distinguish between Posix and Winodws for now.
  13. enum systemType {
  14. Posix,
  15. Windows
  16. };
  17. // Get the system type at runtime.
  18. DLLSPEC systemType getSystemType();
  19. // String replace function. Usage: replace("abcdef", "cd", "12") --> "ab12ef".
  20. DLLSPEC std::string replace(const std::string& s,
  21. const std::string& replace,
  22. const std::string& replaceWith);
  23. // Usage:
  24. // tokenize("this/is some#text", "/#", true) --> ("this" "/" "is some" "#" "text")
  25. // tokenize("this is some text", " ", false) --> ("this" "is" "some" "text")
  26. DLLSPEC std::list<std::string> tokenize(const std::string& s,
  27. const std::string& separators,
  28. bool separatorsInResult = false);
  29. // Same as the previous function, but returns the result via a parameter to avoid an object copy.
  30. DLLSPEC void tokenize(const std::string& s,
  31. const std::string& separators,
  32. /* out */ std::list<std::string>& tokens,
  33. bool separatorsInResult = false);
  34. typedef std::list<std::string>::iterator tokenIter;
  35. DLLSPEC std::vector<std::string> makeStringArray(const char* s, ...);
  36. DLLSPEC std::list<std::string> makeStringList(const char* s, ...);
  37. DLLSPEC std::string getCurrentDir();
  38. DLLSPEC std::string getCurrentDirAsUri();
  39. DLLSPEC int strcasecmp(const char* str1, const char* str2);
  40. DLLSPEC std::string tolower(const std::string& s);
  41. // Disable VS warning
  42. #ifdef _MSC_VER
  43. #pragma warning(push)
  44. #pragma warning(disable : 4267)
  45. #endif
  46. template<typename T>
  47. std::string toString(const T& val) {
  48. std::ostringstream stream;
  49. stream << val;
  50. return stream.str();
  51. }
  52. #ifdef _MSC_VER
  53. #pragma warning(pop)
  54. #endif
  55. }
  56. #endif