SpectMorph
smutils.hh
1 // Licensed GNU LGPL v3 or later: http://www.gnu.org/licenses/lgpl.html
2 
3 #ifndef SPECTMORPH_UTIL_HH
4 #define SPECTMORPH_UTIL_HH
5 
6 #include <string>
7 
8 // operating system: one of these three
9 #if WIN32
10  #define SM_OS_WINDOWS
11 #elif __APPLE__
12  #define SM_OS_MACOS
13 #elif __linux__
14  #define SM_OS_LINUX
15 #else
16  #error "unsupported platform"
17 #endif
18 
19 // detect compiler
20 #if __clang__
21  #define SM_COMP_CLANG
22 #elif __GNUC__ > 2
23  #define SM_COMP_GCC
24 #else
25  #error "unsupported compiler"
26 #endif
27 
28 namespace SpectMorph
29 {
30 
31 /* integer types */
32 typedef uint8_t uint8;
33 typedef uint32_t uint32;
34 typedef int64_t int64;
35 typedef uint64_t uint64;
36 typedef unsigned int uint;
37 
38 #define SPECTMORPH_CLASS_NON_COPYABLE(Class) private: Class (const Class&); Class& operator= (const Class&);
39 
40 #ifdef SM_COMP_GCC
41  #define SPECTMORPH_PRINTF(format_idx, arg_idx) __attribute__ ((__format__ (gnu_printf, format_idx, arg_idx)))
42 #else
43  #define SPECTMORPH_PRINTF(format_idx, arg_idx) __attribute__ ((__format__ (__printf__, format_idx, arg_idx)))
44 #endif
45 
46 std::string string_printf (const char *format, ...) SPECTMORPH_PRINTF (1, 2);
47 std::string string_vprintf (const char *format, va_list vargs);
48 
49 std::string string_locale_printf (const char *format, ...) SPECTMORPH_PRINTF (1, 2);
50 
51 void sm_printf (const char *format, ...) SPECTMORPH_PRINTF (1, 2);
52 
53 enum InstallDir
54 {
55  INSTALL_DIR_TEMPLATES,
56  INSTALL_DIR_INSTRUMENTS
57 };
58 
59 std::string sm_get_install_dir (InstallDir p);
60 
61 // data directory is relocatable
62 void sm_set_pkg_data_dir (const std::string& data_dir);
63 
64 enum UserDir
65 {
66  USER_DIR_INSTRUMENTS,
67  USER_DIR_DATA
68 };
69 
70 std::string sm_get_user_dir (UserDir p);
71 std::string sm_get_default_plan();
72 std::string sm_get_cache_dir();
73 
74 enum class Error
75 {
76  NONE = 0,
77  FILE_NOT_FOUND,
78  FORMAT_INVALID,
79  PARSE_ERROR,
80 };
81 
82 // convenience: provide comparision: (error == 0), (error != 0)
83 bool constexpr operator== (Error v, int64_t n) { return int64_t (v) == n; }
84 bool constexpr operator== (int64_t n, Error v) { return n == int64_t (v); }
85 bool constexpr operator!= (Error v, int64_t n) { return int64_t (v) != n; }
86 bool constexpr operator!= (int64_t n, Error v) { return n != int64_t (v); }
87 
88 const char *sm_error_blurb (Error error);
89 
90 #ifdef SM_OS_WINDOWS
91 std::string sm_resolve_link (const std::string& link_file);
92 #endif
93 
94 } // namespace SpectMorph
95 
96 /* we want to be able to use sm_debug without extra includes */
97 #include "smdebug.hh"
98 
99 #endif
STL namespace.
Definition: smadsrenvelope.hh:8