43 # if !defined(strcasecmp) 44 # define strcasecmp stricmp 45 # define strncasecmp strnicmp 60 mu_cppdate(
char str[ ],
const char *date,
const char *time),
62 mu_split_tag(
char pre[],
int *maj,
int *min,
int *clas,
int *bug,
63 int *y,
int *m,
int *d,
const char *tag);
66 *
mu_utoa9(
char *str,
unsigned i,
int strip),
72 *
mu_verstr(
char verstr[ ],
const char *pre,
73 int maj,
int min,
int clas,
int bug);
77 mu_vernum(
const char *name,
const char *cvs);
79 #define MU_iferr_abort(err, func) do { \ 80 if (err) mu_error_action(-1, func, __FILE__, __LINE__, -1); } while (0) 82 #define MU_iferr_warn(err, func) do { \ 83 if (err) mu_error_action(-1, func, __FILE__, __LINE__, 0); } while (0) 85 #define MU_iferr(err, func) do { \ 86 if (err) mu_error_action(-1, func, __FILE__, __LINE__, 1); } while (0) 88 #define MU_iferrn_abort(err, func) do { \ 90 if (errn) mu_error_action(errn, func, __FILE__, __LINE__, -1); } while (0) 92 #define MU_iferrn_warn(err, func) do { \ 94 if (errn) mu_error_action(errn, func, __FILE__, __LINE__, 0); } while (0) 96 #define MU_iferrn(err, func) do { \ 98 if (errn) mu_error_action(errn, func, __FILE__, __LINE__, 1); } while (0) 100 #define mu_alloc(s) mu_alloc_r(NULL, s) 101 #define mu_realloc(p, s) mu_realloc_r(NULL, p, s) 102 #define mu_free(p) mu_free_r(NULL, p) 103 #define mu_freeall() mu_freeall_r(NULL) 122 mu_getopt(
int argc,
char *
const argv[],
const char *opts);
125 mu_time_unary(
double (*fn)(
double),
double x1,
double x2,
double tmin);
129 double x2,
double y1,
double y2,
double tmin);
133 double x2,
double y1,
double y2,
double z1,
double z2,
145 extern std::string::size_type
npos;
148 extern const std::string
nullStr;
155 extern const std::map<char, const char *>
siScaleMap;
163 inline const char *siScale(
char siPrefix)
166 return (p !=
siScaleMap.end() ? p->second :
"NaN");
180 inline bool siHasPrefix(
const std::string &unit,
181 const std::vector<std::string> &baseUnits)
183 for (
auto &base: baseUnits) {
if (base == unit) {
return false; } }
185 for (
auto &base: baseUnits) {
if (base == &unit[1]) {
return true; } }
192 extern int readLogicalLine(std::string &line, FILE *file,
193 unsigned *nLines =
nullptr,
194 const char *eol =
"\r\n");
204 template<
typename C,
typename I =
typename C::const_iterator>
205 const typename C::value_type &getValue(I p)
217 template<
typename C,
typename I =
typename C::const_iterator>
218 const typename C::key_type &getKey(I p)
230 template<
typename C,
typename I =
typename C::const_iterator>
231 const typename C::mapped_type &getMapped(I p)
255 inline int strMatch(
const std::string &s1,
const std::string &s2,
256 std::string::size_type minChar =
npos,
257 bool caseSense =
false)
259 auto ncmp = (caseSense ? strncmp : strncasecmp);
260 auto n = std::min(s1.size(), s2.size());
261 if (n < minChar) { n = std::max(s1.size(), s2.size()); }
262 return ncmp(s1.c_str(), s2.c_str(), n);
280 template<
typename C,
typename I =
typename C::iterator,
281 const std::string &(*F)(I) = getValue<C, I>>
282 std::vector<I> findMatch(
const std::string &s, C &pool,
283 std::string::size_type minChar =
npos,
bool caseSense =
false)
286 for (I p = pool.begin(); p != pool.end(); ++p) {
287 if (strMatch(s, F(p), minChar, caseSense) == 0) { rtn.push_back(p); }
313 template<
typename C,
typename I =
typename C::iterator,
314 const std::string &(*F)(I) = getKey<C, I>>
315 I findUnique(
const std::string &str, C &pool,
316 std::string::size_type minChar =
npos,
bool caseSense =
false)
318 const char *fn =
"util::findUnique";
319 auto matches = findMatch<C, I, F>(str, pool, minChar, caseSense);
320 std::string matchNames;
321 for (
auto p: matches) {
326 "Multiple matches found for '%s':\n%s", str, matchNames);
328 return (matches.empty() ? pool.end() : matches[0]);
349 template<
typename R,
typename S,
typename T,
typename... Args>
351 std::enable_if<std::is_member_function_pointer<S>::value, R>::type
352 fn_call(S s, T &t, Args&&... args) {
return (t.*s)(args...); }
355 template<
typename R,
typename S,
typename T,
typename... Args>
357 std::enable_if<!std::is_member_function_pointer<S>::value, R>::type
358 fn_call(S s, T &t, Args&&... args) {
return s(t, args...); }
377 std::string qualifyPath(
const std::string &path,
const std::string &file)
381 if (!path.empty() && !file.empty() && file[0] !=
'/' 382 && file !=
"-" && file !=
"!") {
384 if (path.back() !=
'/') { rtn +=
'/'; }
405 std::string getToken(
const std::string &line,
size_t *index =
nullptr)
407 const std::string white{
" \t\r\n"};
408 size_t i0 = line.find_first_not_of(white, (index ? *index : 0UL)),
409 i1 = line.find_first_of(white, i0);
410 if (index) { *index = i1; }
411 return (i0 !=
npos ? line.substr(i0, i1-i0) :
"");
DLLSPEC void mu_wait_time(double)
DLLSPEC int mu_free_r(void **, void *)
DLLSPEC char * mu_utoa9(char *str, unsigned i, int strip)
DLLSPEC double mu_cpu_time(void)
DLLSPEC double mu_system_time(void)
DLLSPEC double mu_clock_time(void)
DLLSPEC char * mu_fgetline(char *, long int, FILE *)
DLLSPEC const char * mu_verstr(char verstr[], const char *pre, int maj, int min, int clas, int bug)
DLLSPEC void * mu_realloc_r(void **, void *, size_t)
DLLSPEC double mu_time_unary(double(*fn)(double), double x1, double x2, double tmin)
DLLSPEC int mu_clock_Hz(void)
#define MU_EXCEPTION_IF(cond, src, msg,...)
Conditionally throws mutils::Exception.
DLLSPEC double mu_thread_cpu_time(void)
DLLSPEC const char * mu_version(void)
const std::string nullStr(1, 0)
const std::string siPrefixes("YZEPTGMkhDdcmunpfazy")
DLLSPEC void mu_split_tag(char pre[], int *maj, int *min, int *clas, int *bug, int *y, int *m, int *d, const char *tag)
std::string::size_type npos
DLLSPEC int mu_getopt(int argc, char *const argv[], const char *opts)
DLLSPEC void mu_cppdate(char str[], const char *date, const char *time)
DLLSPEC int mu_vernum(const char *name, const char *cvs)
DLLSPEC double mu_process_cpu_time(void)
DLLSPEC double mu_user_time(void)
DLLSPEC void mu_freeall_r(void *)
DLLSPEC double mu_real_clock_time(void)
DLLSPEC double mu_time_binary(double(*fn)(double, double), double x1, double x2, double y1, double y2, double tmin)
DLLSPEC void mu_error_action(int, const char *, const char *, int, int)
const std::map< char, const char * > siScaleMap
DLLSPEC int mu_ppmtext(char *, char *, int, int, int)
Defines the Exception base class.
DLLSPEC double mu_time_trinary(double(*fn)(double, double, double), double x1, double x2, double y1, double y2, double z1, double z2, double tmin)
DLLSPEC const char * mu_platform(void)
DLLSPEC void * mu_alloc_r(void **, size_t)