libvisual  0.5.0
lv_util.hpp
1 #ifndef _LV_UTIL_HPP
2 #define _LV_UTIL_HPP
3 
4 #include <libvisual/lvconfig.h>
5 #include <libvisual/lv_defines.h>
6 #include <string>
7 #include <memory>
8 #include <functional>
9 
10 namespace LV {
11 
12  template<typename T, typename ...Args>
13  std::unique_ptr<T> make_unique( Args&& ...args )
14  {
15  return std::unique_ptr<T> (new T (std::forward<Args> (args)... ));
16  }
17 
26  inline bool str_has_suffix (std::string const& str, std::string const& suffix)
27  {
28  if (str.length() >= suffix.length()) {
29  return (str.compare (str.length() - suffix.length(), suffix.length(), suffix) == 0);
30  } else {
31  return false;
32  }
33  }
34 
35  LV_API bool for_each_file_in_dir (std::string const& path,
36  std::function<bool (std::string const&)> filter,
37  std::function<bool (std::string const&)> func);
38 
46  inline char const* string_to_c (std::string const& string)
47  {
48  return !string.empty () ? string.c_str () : nullptr;
49  }
50 
51 } // LV namespace
52 
53 #endif // _LV_UTIL_HPP