3 #ifndef SPECTMORPH_UTIL_HH
4 #define SPECTMORPH_UTIL_HH
18 #error "unsupported platform"
27 #error "unsupported compiler"
38 typedef uint8_t uint8;
39 typedef uint32_t uint32;
40 typedef int64_t int64;
41 typedef uint64_t uint64;
42 typedef unsigned int uint;
44 #define SPECTMORPH_CLASS_NON_COPYABLE(Class) \
45 Class (const Class&) = delete; \
46 Class& operator= (const Class&) = delete
49 #define SPECTMORPH_PRINTF(format_idx, arg_idx) __attribute__ ((__format__ (gnu_printf, format_idx, arg_idx)))
51 #define SPECTMORPH_PRINTF(format_idx, arg_idx) __attribute__ ((__format__ (__printf__, format_idx, arg_idx)))
54 std::string string_printf (
const char *format, ...) SPECTMORPH_PRINTF (1, 2);
55 std::
string string_vprintf (const
char *format, va_list vargs);
57 std::
string string_locale_printf (const
char *format, ...) SPECTMORPH_PRINTF (1, 2);
59 void sm_printf (const
char *format, ...) SPECTMORPH_PRINTF (1, 2);
61 static constexpr
int AVOID_ARRAY_UB = 1;
66 INSTALL_DIR_TEMPLATES,
67 INSTALL_DIR_INSTRUMENTS,
71 std::string sm_get_install_dir (InstallDir p);
74 void sm_set_pkg_data_dir (
const std::string& data_dir);
83 std::string sm_get_user_dir (UserDir p);
84 std::string sm_get_default_plan();
85 std::string sm_get_cache_dir();
88 std::string sm_mac_documents_dir();
89 std::string sm_mac_application_support_dir_user();
90 std::string sm_mac_application_support_dir_system();
91 void set_macos_data_dir();
96 DOCUMENTS_DIR_INSTRUMENTS
99 std::string sm_get_documents_dir (DocumentsDir p);
121 case Code::FILE_NOT_FOUND:
122 m_message =
"No such file, device or directory";
125 case Code::FORMAT_INVALID:
126 m_message =
"Invalid format";
129 case Code::PARSE_ERROR:
130 m_message =
"Parsing error";
134 m_message =
"Unknown error";
138 Error (
const std::string& message) :
152 return m_message.c_str();
156 return m_code != Code::NONE;
160 std::string m_message;
164 std::string sm_resolve_link (
const std::string& link_file);
165 void set_windows_data_dir (HMODULE hInstance);
169 #define SM_SET_OS_DATA_DIR() set_windows_data_dir (hInstance)
173 #define SM_SET_OS_DATA_DIR() set_macos_data_dir()
177 void set_static_linux_data_dir();
179 #ifdef SM_STATIC_LINUX
180 #define SM_SET_OS_DATA_DIR() set_static_linux_data_dir()
183 #define SM_SET_OS_DATA_DIR()
188 std::string sha1_hash (
const unsigned char *data,
size_t len);
189 std::string sha1_hash (
const std::string& str);
193 std::string to_utf8 (
const std::u32string& str);
194 std::u32string to_utf32 (
const std::string& utf8);
196 Error read_dir (
const std::string& dirname, std::vector<std::string>& files);
197 bool file_exists (
const std::string& filename);
198 bool dir_exists (
const std::string& dirname);
200 double sm_atof (
const char *str);
201 double sm_atof_any (
const char *str);
206 #include "smdebug.hh"
Definition: smutils.hh:102