From 2f91bdfa5390bdf992ab7044488b5afb21716661 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 13 Apr 2019 19:19:29 +0200 Subject: NO-OP: after fixes in libs --- libs/pbd/pbd/compose.h | 755 +++++++++++++++++++++++----------------------- libs/pbd/pbd/msvc_pbd.h | 84 +++--- libs/pbd/pbd/ringbuffer.h | 130 ++++---- libs/pbd/pbd/timersub.h | 19 +- libs/pbd/pbd/tokenizer.h | 48 ++- 5 files changed, 516 insertions(+), 520 deletions(-) (limited to 'libs/pbd/pbd') diff --git a/libs/pbd/pbd/compose.h b/libs/pbd/pbd/compose.h index 231afa583e..c7a225ca32 100644 --- a/libs/pbd/pbd/compose.h +++ b/libs/pbd/pbd/compose.h @@ -36,400 +36,397 @@ #include #include #include -#include // for multimap +#include // for multimap #include "pbd/libpbd_visibility.h" namespace StringPrivate { - // the actual composition class - using string::compose is cleaner, so we - // hide it here - class LIBPBD_API Composition - { - public: - // initialize and prepare format string on the form "text %1 text %2 etc." - explicit Composition(std::string fmt); - - // supply an replacement argument starting from %1 - template - Composition &arg(const T &obj); - - // specialization to catch strings (C++ and C) - Composition &arg(const std::string &str); - Composition &arg(char const * const cstr); - - // compose and return string - std::string str() const; - - private: - std::ostringstream os; - int arg_no; - - // we store the output as a list - when the output string is requested, the - // list is concatenated to a string; this way we can keep iterators into - // the list instead of into a string where they're possibly invalidated on - // inserting a specification string - typedef std::list output_list; - output_list output; - - // the initial parse of the format string fills in the specification map - // with positions for each of the various %?s - typedef std::multimap specification_map; - specification_map specs; - }; - - // helper for converting spec string numbers - inline int char_to_int(char c) - { - switch (c) { - case '0': return 0; - case '1': return 1; - case '2': return 2; - case '3': return 3; - case '4': return 4; - case '5': return 5; - case '6': return 6; - case '7': return 7; - case '8': return 8; - case '9': return 9; - default: return -1000; - } - } - - inline bool is_number(int n) - { - switch (n) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - return true; - - default: - return false; - } - } - - - // implementation of class Composition - template - inline Composition &Composition::arg(const T &obj) - { - os << obj; - - std::string rep = os.str(); - - if (!rep.empty()) { // manipulators don't produce output - for (specification_map::const_iterator i = specs.lower_bound(arg_no), - end = specs.upper_bound(arg_no); i != end; ++i) { - output_list::iterator pos = i->second; - ++pos; - - output.insert(pos, rep); - } - - os.str(std::string()); - //os.clear(); - ++arg_no; - } - - return *this; - } - - inline Composition &Composition::arg(const std::string &str) - { - /* specialization to ensure that empty strings show up - * in the output - */ - for (specification_map::const_iterator i = specs.lower_bound(arg_no), - end = specs.upper_bound(arg_no); i != end; ++i) { - output_list::iterator pos = i->second; - ++pos; - - output.insert(pos, str); - } - - ++arg_no; - - return *this; - } - - inline Composition &Composition::arg(char const * const cstr) - { - /* specialization to ensure that empty C strings show up - * in the output - */ - for (specification_map::const_iterator i = specs.lower_bound(arg_no), - end = specs.upper_bound(arg_no); i != end; ++i) { - output_list::iterator pos = i->second; - ++pos; - - output.insert(pos, std::string (cstr)); - } - - ++arg_no; - - return *this; - } - - inline Composition::Composition(std::string fmt) - : arg_no(1) - { - std::string::size_type b = 0, i = 0; - - // fill in output with the strings between the %1 %2 %3 etc. and - // fill in specs with the positions - while (i < fmt.length()) { - if (fmt[i] == '%' && i + 1 < fmt.length()) { - if (fmt[i + 1] == '%') { // catch %% - fmt.replace(i, 2, "%"); - ++i; +// the actual composition class - using string::compose is cleaner, so we +// hide it here +class LIBPBD_API Composition +{ +public: + // initialize and prepare format string on the form "text %1 text %2 etc." + explicit Composition(std::string fmt); + + // supply an replacement argument starting from %1 + template + Composition &arg(const T &obj); + + // specialization to catch strings (C++ and C) + Composition &arg(const std::string &str); + Composition &arg(char const * const cstr); + + // compose and return string + std::string str() const; + +private: + std::ostringstream os; + int arg_no; + + // we store the output as a list - when the output string is requested, the + // list is concatenated to a string; this way we can keep iterators into + // the list instead of into a string where they're possibly invalidated on + // inserting a specification string + typedef std::list output_list; + output_list output; + + // the initial parse of the format string fills in the specification map + // with positions for each of the various %?s + typedef std::multimap specification_map; + specification_map specs; +}; + +// helper for converting spec string numbers +inline int char_to_int(char c) +{ + switch (c) { + case '0': return 0; + case '1': return 1; + case '2': return 2; + case '3': return 3; + case '4': return 4; + case '5': return 5; + case '6': return 6; + case '7': return 7; + case '8': return 8; + case '9': return 9; + default: return -1000; + } +} + +inline bool is_number(int n) +{ + switch (n) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + return true; + + default: + return false; } - else if (is_number(fmt[i + 1])) { // aha! a spec! - // save string - output.push_back(fmt.substr(b, i - b)); +} + +// implementation of class Composition +template + inline Composition &Composition::arg(const T &obj) + { + os << obj; + + std::string rep = os.str(); + + if (!rep.empty()) { // manipulators don't produce output + for (specification_map::const_iterator i = specs.lower_bound(arg_no), + end = specs.upper_bound(arg_no); i != end; ++i) { + output_list::iterator pos = i->second; + ++pos; + + output.insert(pos, rep); + } + + os.str(std::string()); + //os.clear(); + ++arg_no; + } + + return *this; + } + +inline Composition &Composition::arg(const std::string &str) +{ + /* specialization to ensure that empty strings show up + * in the output + */ + for (specification_map::const_iterator i = specs.lower_bound(arg_no), + end = specs.upper_bound(arg_no); i != end; ++i) { + output_list::iterator pos = i->second; + ++pos; + + output.insert(pos, str); + } + + ++arg_no; + + return *this; +} - int n = 1; // number of digits - int spec_no = 0; +inline Composition &Composition::arg(char const * const cstr) +{ + /* specialization to ensure that empty C strings show up + * in the output + */ + for (specification_map::const_iterator i = specs.lower_bound(arg_no), + end = specs.upper_bound(arg_no); i != end; ++i) { + output_list::iterator pos = i->second; + ++pos; + + output.insert(pos, std::string (cstr)); + } - do { - spec_no += char_to_int(fmt[i + n]); - spec_no *= 10; - ++n; - } while (i + n < fmt.length() && is_number(fmt[i + n])); + ++arg_no; - spec_no /= 10; - output_list::iterator pos = output.end(); - --pos; // safe since we have just inserted a string> + return *this; +} - specs.insert(specification_map::value_type(spec_no, pos)); +inline Composition::Composition(std::string fmt) + : arg_no(1) +{ + std::string::size_type b = 0, i = 0; + + // fill in output with the strings between the %1 %2 %3 etc. and + // fill in specs with the positions + while (i < fmt.length()) { + if (fmt[i] == '%' && i + 1 < fmt.length()) { + if (fmt[i + 1] == '%') { // catch %% + fmt.replace(i, 2, "%"); + ++i; + } + else if (is_number(fmt[i + 1])) { // aha! a spec! + // save string + output.push_back(fmt.substr(b, i - b)); + + int n = 1; // number of digits + int spec_no = 0; + + do { + spec_no += char_to_int(fmt[i + n]); + spec_no *= 10; + ++n; + } while (i + n < fmt.length() && is_number(fmt[i + n])); + + spec_no /= 10; + output_list::iterator pos = output.end(); + --pos; // safe since we have just inserted a string> + + specs.insert(specification_map::value_type(spec_no, pos)); + + // jump over spec string + i += n; + b = i; + } + else + ++i; + } + else + ++i; + } - // jump over spec string - i += n; - b = i; + if (i - b > 0) { // add the rest of the string + output.push_back(fmt.substr(b, i - b)); } - else - ++i; - } - else - ++i; - } - - if (i - b > 0) // add the rest of the string - output.push_back(fmt.substr(b, i - b)); - } - - inline std::string Composition::str() const - { - // assemble string - std::string str; - - for (output_list::const_iterator i = output.begin(), end = output.end(); - i != end; ++i) - str += *i; - - return str; - } +} + +inline std::string Composition::str() const +{ + // assemble string + std::string str; + + for (output_list::const_iterator i = output.begin(), end = output.end(); + i != end; ++i) + str += *i; + + return str; +} } // now for the real thing(s) -//namespace PBD -//{ - // a series of functions which accept a format string on the form "text %1 - // more %2 less %3" and a number of templated parameters and spits out the - // composited string - template - inline std::string string_compose(const std::string &fmt, const T1 &o1) - { - StringPrivate::Composition c(fmt); - c.arg(o1); - return c.str(); - } - - template - inline std::string string_compose(const std::string &fmt, - const T1 &o1, const T2 &o2) - { - StringPrivate::Composition c(fmt); - c.arg(o1).arg(o2); - return c.str(); - } - - template - inline std::string string_compose(const std::string &fmt, - const T1 &o1, const T2 &o2, const T3 &o3) - { - StringPrivate::Composition c(fmt); - c.arg(o1).arg(o2).arg(o3); - return c.str(); - } - - template - inline std::string string_compose(const std::string &fmt, - const T1 &o1, const T2 &o2, const T3 &o3, - const T4 &o4) - { - StringPrivate::Composition c(fmt); - c.arg(o1).arg(o2).arg(o3).arg(o4); - return c.str(); - } - - template - inline std::string string_compose(const std::string &fmt, - const T1 &o1, const T2 &o2, const T3 &o3, - const T4 &o4, const T5 &o5) - { - StringPrivate::Composition c(fmt); - c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5); - return c.str(); - } - - template - inline std::string string_compose(const std::string &fmt, - const T1 &o1, const T2 &o2, const T3 &o3, - const T4 &o4, const T5 &o5, const T6 &o6) - { - StringPrivate::Composition c(fmt); - c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6); - return c.str(); - } - - template - inline std::string string_compose(const std::string &fmt, - const T1 &o1, const T2 &o2, const T3 &o3, - const T4 &o4, const T5 &o5, const T6 &o6, - const T7 &o7) - { - StringPrivate::Composition c(fmt); - c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7); - return c.str(); - } - - template - inline std::string string_compose(const std::string &fmt, - const T1 &o1, const T2 &o2, const T3 &o3, - const T4 &o4, const T5 &o5, const T6 &o6, - const T7 &o7, const T8 &o8) - { - StringPrivate::Composition c(fmt); - c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7).arg(o8); - return c.str(); - } - - template - inline std::string string_compose(const std::string &fmt, - const T1 &o1, const T2 &o2, const T3 &o3, - const T4 &o4, const T5 &o5, const T6 &o6, - const T7 &o7, const T8 &o8, const T9 &o9) - { - StringPrivate::Composition c(fmt); - c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7).arg(o8).arg(o9); - return c.str(); - } - - template - inline std::string string_compose(const std::string &fmt, - const T1 &o1, const T2 &o2, const T3 &o3, - const T4 &o4, const T5 &o5, const T6 &o6, - const T7 &o7, const T8 &o8, const T9 &o9, - const T10 &o10) - { - StringPrivate::Composition c(fmt); - c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7).arg(o8).arg(o9) - .arg(o10); - return c.str(); - } - - template - inline std::string string_compose(const std::string &fmt, - const T1 &o1, const T2 &o2, const T3 &o3, - const T4 &o4, const T5 &o5, const T6 &o6, - const T7 &o7, const T8 &o8, const T9 &o9, - const T10 &o10, const T11 &o11) - { - StringPrivate::Composition c(fmt); - c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7).arg(o8).arg(o9) - .arg(o10).arg(o11); - return c.str(); - } - - template - inline std::string string_compose(const std::string &fmt, - const T1 &o1, const T2 &o2, const T3 &o3, - const T4 &o4, const T5 &o5, const T6 &o6, - const T7 &o7, const T8 &o8, const T9 &o9, - const T10 &o10, const T11 &o11, const T12 &o12) - { - StringPrivate::Composition c(fmt); - c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7).arg(o8).arg(o9) - .arg(o10).arg(o11).arg(o12); - return c.str(); - } - - template - inline std::string string_compose(const std::string &fmt, - const T1 &o1, const T2 &o2, const T3 &o3, - const T4 &o4, const T5 &o5, const T6 &o6, - const T7 &o7, const T8 &o8, const T9 &o9, - const T10 &o10, const T11 &o11, const T12 &o12, - const T13 &o13) - { - StringPrivate::Composition c(fmt); - c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7).arg(o8).arg(o9) - .arg(o10).arg(o11).arg(o12).arg(o13); - return c.str(); - } - - template - inline std::string string_compose(const std::string &fmt, - const T1 &o1, const T2 &o2, const T3 &o3, - const T4 &o4, const T5 &o5, const T6 &o6, - const T7 &o7, const T8 &o8, const T9 &o9, - const T10 &o10, const T11 &o11, const T12 &o12, - const T13 &o13, const T14 &o14) - { - StringPrivate::Composition c(fmt); - c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7).arg(o8).arg(o9) - .arg(o10).arg(o11).arg(o12).arg(o13).arg(o14); - return c.str(); - } - - template - inline std::string string_compose(const std::string &fmt, - const T1 &o1, const T2 &o2, const T3 &o3, - const T4 &o4, const T5 &o5, const T6 &o6, - const T7 &o7, const T8 &o8, const T9 &o9, - const T10 &o10, const T11 &o11, const T12 &o12, - const T13 &o13, const T14 &o14, const T15 &o15) - { - StringPrivate::Composition c(fmt); - c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7).arg(o8).arg(o9) - .arg(o10).arg(o11).arg(o12).arg(o13).arg(o14).arg(o15); - return c.str(); - } -//} +// a series of functions which accept a format string on the form "text %1 +// more %2 less %3" and a number of templated parameters and spits out the +// composited string +template +inline std::string string_compose(const std::string &fmt, const T1 &o1) +{ + StringPrivate::Composition c(fmt); + c.arg(o1); + return c.str(); +} + +template +inline std::string string_compose(const std::string &fmt, + const T1 &o1, const T2 &o2) +{ + StringPrivate::Composition c(fmt); + c.arg(o1).arg(o2); + return c.str(); +} + +template +inline std::string string_compose(const std::string &fmt, + const T1 &o1, const T2 &o2, const T3 &o3) +{ + StringPrivate::Composition c(fmt); + c.arg(o1).arg(o2).arg(o3); + return c.str(); +} + +template +inline std::string string_compose(const std::string &fmt, + const T1 &o1, const T2 &o2, const T3 &o3, + const T4 &o4) +{ + StringPrivate::Composition c(fmt); + c.arg(o1).arg(o2).arg(o3).arg(o4); + return c.str(); +} + +template +inline std::string string_compose(const std::string &fmt, + const T1 &o1, const T2 &o2, const T3 &o3, + const T4 &o4, const T5 &o5) +{ + StringPrivate::Composition c(fmt); + c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5); + return c.str(); +} + +template +inline std::string string_compose(const std::string &fmt, + const T1 &o1, const T2 &o2, const T3 &o3, + const T4 &o4, const T5 &o5, const T6 &o6) +{ + StringPrivate::Composition c(fmt); + c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6); + return c.str(); +} + +template +inline std::string string_compose(const std::string &fmt, + const T1 &o1, const T2 &o2, const T3 &o3, + const T4 &o4, const T5 &o5, const T6 &o6, + const T7 &o7) +{ + StringPrivate::Composition c(fmt); + c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7); + return c.str(); +} + +template +inline std::string string_compose(const std::string &fmt, + const T1 &o1, const T2 &o2, const T3 &o3, + const T4 &o4, const T5 &o5, const T6 &o6, + const T7 &o7, const T8 &o8) +{ + StringPrivate::Composition c(fmt); + c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7).arg(o8); + return c.str(); +} + +template +inline std::string string_compose(const std::string &fmt, + const T1 &o1, const T2 &o2, const T3 &o3, + const T4 &o4, const T5 &o5, const T6 &o6, + const T7 &o7, const T8 &o8, const T9 &o9) +{ + StringPrivate::Composition c(fmt); + c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7).arg(o8).arg(o9); + return c.str(); +} + +template +inline std::string string_compose(const std::string &fmt, + const T1 &o1, const T2 &o2, const T3 &o3, + const T4 &o4, const T5 &o5, const T6 &o6, + const T7 &o7, const T8 &o8, const T9 &o9, + const T10 &o10) +{ + StringPrivate::Composition c(fmt); + c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7).arg(o8).arg(o9) + .arg(o10); + return c.str(); +} + +template +inline std::string string_compose(const std::string &fmt, + const T1 &o1, const T2 &o2, const T3 &o3, + const T4 &o4, const T5 &o5, const T6 &o6, + const T7 &o7, const T8 &o8, const T9 &o9, + const T10 &o10, const T11 &o11) +{ + StringPrivate::Composition c(fmt); + c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7).arg(o8).arg(o9) + .arg(o10).arg(o11); + return c.str(); +} + +template +inline std::string string_compose(const std::string &fmt, + const T1 &o1, const T2 &o2, const T3 &o3, + const T4 &o4, const T5 &o5, const T6 &o6, + const T7 &o7, const T8 &o8, const T9 &o9, + const T10 &o10, const T11 &o11, const T12 &o12) +{ + StringPrivate::Composition c(fmt); + c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7).arg(o8).arg(o9) + .arg(o10).arg(o11).arg(o12); + return c.str(); +} + +template +inline std::string string_compose(const std::string &fmt, + const T1 &o1, const T2 &o2, const T3 &o3, + const T4 &o4, const T5 &o5, const T6 &o6, + const T7 &o7, const T8 &o8, const T9 &o9, + const T10 &o10, const T11 &o11, const T12 &o12, + const T13 &o13) +{ + StringPrivate::Composition c(fmt); + c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7).arg(o8).arg(o9) + .arg(o10).arg(o11).arg(o12).arg(o13); + return c.str(); +} + +template +inline std::string string_compose(const std::string &fmt, + const T1 &o1, const T2 &o2, const T3 &o3, + const T4 &o4, const T5 &o5, const T6 &o6, + const T7 &o7, const T8 &o8, const T9 &o9, + const T10 &o10, const T11 &o11, const T12 &o12, + const T13 &o13, const T14 &o14) +{ + StringPrivate::Composition c(fmt); + c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7).arg(o8).arg(o9) + .arg(o10).arg(o11).arg(o12).arg(o13).arg(o14); + return c.str(); +} + +template +inline std::string string_compose(const std::string &fmt, + const T1 &o1, const T2 &o2, const T3 &o3, + const T4 &o4, const T5 &o5, const T6 &o6, + const T7 &o7, const T8 &o8, const T9 &o9, + const T10 &o10, const T11 &o11, const T12 &o12, + const T13 &o13, const T14 &o14, const T15 &o15) +{ + StringPrivate::Composition c(fmt); + c.arg(o1).arg(o2).arg(o3).arg(o4).arg(o5).arg(o6).arg(o7).arg(o8).arg(o9) + .arg(o10).arg(o11).arg(o12).arg(o13).arg(o14).arg(o15); + return c.str(); +} #endif // STRING_COMPOSE_H diff --git a/libs/pbd/pbd/msvc_pbd.h b/libs/pbd/pbd/msvc_pbd.h index 7c981582c5..a471dd11ba 100644 --- a/libs/pbd/pbd/msvc_pbd.h +++ b/libs/pbd/pbd/msvc_pbd.h @@ -80,11 +80,11 @@ #ifdef __cplusplus extern "C" { -#endif /* __cplusplus */ +#endif /* __cplusplus */ #ifdef __cplusplus -} /* extern "C" */ -#endif /* __cplusplus */ +} /* extern "C" */ +#endif /* __cplusplus */ #ifdef PLATFORM_WINDOWS @@ -121,22 +121,22 @@ extern "C" { #endif #ifndef OPEN_MAX -#define OPEN_MAX 32 +#define OPEN_MAX (32) #endif #ifdef __cplusplus extern "C" { -#endif /* __cplusplus */ +#endif /* __cplusplus */ -PBDEXTN_API int PBDEXTN_APICALLTYPE cyginit (unsigned int result); -LIBPBD_API int PBD_APICALLTYPE dlclose (void *handle) __THROW; -LIBPBD_API void* PBD_APICALLTYPE dlopen (const char *file_name, int mode) __THROW; -LIBPBD_API void* PBD_APICALLTYPE dlsym (void *handle, const char *symbol_name) __THROW; -LIBPBD_API char* PBD_APICALLTYPE dlerror () __THROW; +PBDEXTN_API int PBDEXTN_APICALLTYPE cyginit (unsigned int result); +LIBPBD_API int PBD_APICALLTYPE dlclose (void *handle) __THROW; +LIBPBD_API void* PBD_APICALLTYPE dlopen (const char *file_name, int mode) __THROW; +LIBPBD_API void* PBD_APICALLTYPE dlsym (void *handle, const char *symbol_name) __THROW; +LIBPBD_API char* PBD_APICALLTYPE dlerror () __THROW; #ifdef __cplusplus -} /* extern "C" */ -#endif /* __cplusplus */ +} /* extern "C" */ +#endif /* __cplusplus */ #ifndef __CYGWIN__ /* For whatever reason, Ardour's 'libevoral' refuses to build as a DLL if we include both 'rpc.h' */ @@ -157,17 +157,17 @@ typedef int (FAR PBDEXTN_APICALLTYPE *CYGINIT_API)(unsigned int); #define _SSIZE_T_ typedef long _ssize_t; -#ifndef _NO_OLDNAMES +#ifndef _NO_OLDNAMES typedef _ssize_t ssize_t; #endif #endif /* ! _SSIZE_T_ */ struct dirent { - long d_ino; // Always zero - unsigned short d_reclen; // Always zero - unsigned short d_namlen; // Length of name in d_name - char d_name[FILENAME_MAX]; // File name + long d_ino; // Always zero + unsigned short d_reclen; // Always zero + unsigned shor d_namlen; // Length of name in d_name + char d_name[FILENAME_MAX]; // File name }; // This is an internal data structure. Do not use it @@ -175,65 +175,65 @@ struct dirent typedef struct { // Disk transfer area for this dir - struct _finddata_t dd_dta; + struct _finddata_t dd_dta; // 'dirent' struct to return from dir (NOTE: this // is not thread safe). - struct dirent dd_dir; + struct dirent dd_dir; // '_findnext()' handle - long dd_handle; + long dd_handle; // Current status of search: // 0 = not started yet (next entry to read is first entry) // -1 = off the end // Otherwise - positive (0 based) index of next entry - int dd_stat; + int dd_stat; // Full path for dir with search pattern (struct will be extended) - char dd_name[1]; + char dd_name[1]; } DIR; typedef unsigned int nfds_t; #ifdef __cplusplus extern "C" { -#endif /* __cplusplus */ +#endif /* __cplusplus */ -LIBPBD_API int __cdecl gettimeofday(struct timeval *__restrict tv, __timezone_ptr_t tz); -LIBPBD_API ssize_t PBD_APICALLTYPE pread(int handle, void *buf, size_t nbytes, off_t offset); -LIBPBD_API ssize_t PBD_APICALLTYPE pwrite(int handle, const void *buf, size_t nbytes, off_t offset); +LIBPBD_API int __cdecl gettimeofday(struct timeval *__restrict tv, __timezone_ptr_t tz); +LIBPBD_API ssize_t PBD_APICALLTYPE pread(int handle, void *buf, size_t nbytes, off_t offset); +LIBPBD_API ssize_t PBD_APICALLTYPE pwrite(int handle, const void *buf, size_t nbytes, off_t offset); #if defined(_MSC_VER) && (_MSC_VER < 1800) -LIBPBD_API double PBD_APICALLTYPE expm1(double x); -LIBPBD_API double PBD_APICALLTYPE log1p(double x); -LIBPBD_API double PBD_APICALLTYPE round(double x); -LIBPBD_API float PBD_APICALLTYPE roundf(float x); +LIBPBD_API double PBD_APICALLTYPE expm1(double x); +LIBPBD_API double PBD_APICALLTYPE log1p(double x); +LIBPBD_API double PBD_APICALLTYPE round(double x); +LIBPBD_API float PBD_APICALLTYPE roundf(float x); #endif #if defined(_MSC_VER) && (_MSC_VER < 1900) -LIBPBD_API double PBD_APICALLTYPE log2 (double x); -LIBPBD_API double PBD_APICALLTYPE trunc(double x); +LIBPBD_API double PBD_APICALLTYPE log2 (double x); +LIBPBD_API double PBD_APICALLTYPE trunc(double x); #endif namespace PBD { -LIBPBD_API bool PBD_APICALLTYPE TestForMinimumSpecOS(char *revision="currently ignored"); -LIBPBD_API char* PBD_APICALLTYPE realpath (const char *original_path, char resolved_path[_MAX_PATH+1]); -LIBPBD_API int PBD_APICALLTYPE mkstemp (char *template_name); -LIBPBD_API int PBD_APICALLTYPE ntfs_link (const char *existing_filepath, const char *link_filepath); -LIBPBD_API int PBD_APICALLTYPE ntfs_unlink (const char *link_filepath); +LIBPBD_API bool PBD_APICALLTYPE TestForMinimumSpecOS(char *revision="currently ignored"); +LIBPBD_API char* PBD_APICALLTYPE realpath (const char *original_path, char resolved_path[_MAX_PATH+1]); +LIBPBD_API int PBD_APICALLTYPE mkstemp (char *template_name); +LIBPBD_API int PBD_APICALLTYPE ntfs_link (const char *existing_filepath, const char *link_filepath); +LIBPBD_API int PBD_APICALLTYPE ntfs_unlink (const char *link_filepath); // These are used to replicate 'dirent.h' functionality -LIBPBD_API DIR* PBD_APICALLTYPE opendir (const char *szPath); -LIBPBD_API struct dirent* PBD_APICALLTYPE readdir (DIR *pDir); -LIBPBD_API int PBD_APICALLTYPE closedir (DIR *pDir); +LIBPBD_API DIR* PBD_APICALLTYPE opendir (const char *szPath); +LIBPBD_API struct dirent* PBD_APICALLTYPE readdir (DIR *pDir); +LIBPBD_API int PBD_APICALLTYPE closedir (DIR *pDir); } // namespace PBD #ifdef __cplusplus -} /* extern "C" */ -#endif /* __cplusplus */ +} /* extern "C" */ +#endif /* __cplusplus */ #endif // !__CYGWIN__ #endif // PLATFORM_WINDOWS diff --git a/libs/pbd/pbd/ringbuffer.h b/libs/pbd/pbd/ringbuffer.h index 9b5b09651e..bed9e829fb 100644 --- a/libs/pbd/pbd/ringbuffer.h +++ b/libs/pbd/pbd/ringbuffer.h @@ -30,16 +30,18 @@ namespace PBD { template class /*LIBPBD_API*/ RingBuffer { - public: +public: RingBuffer (guint sz) { -// size = ffs(sz); /* find first [bit] set is a single inlined assembly instruction. But it looks like the API rounds up so... */ - guint power_of_two; - for (power_of_two = 1; 1U< /*LIBPBD_API*/ guint RingBuffer::read (T *dest, guint cnt) { - guint free_cnt; - guint cnt2; - guint to_read; - guint n1, n2; - guint priv_read_idx; + guint free_cnt; + guint cnt2; + guint to_read; + guint n1, n2; + guint priv_read_idx; - priv_read_idx=g_atomic_int_get(&read_idx); + priv_read_idx=g_atomic_int_get(&read_idx); - if ((free_cnt = read_space ()) == 0) { - return 0; - } + if ((free_cnt = read_space ()) == 0) { + return 0; + } - to_read = cnt > free_cnt ? free_cnt : cnt; + to_read = cnt > free_cnt ? free_cnt : cnt; - cnt2 = priv_read_idx + to_read; + cnt2 = priv_read_idx + to_read; - if (cnt2 > size) { - n1 = size - priv_read_idx; - n2 = cnt2 & size_mask; - } else { - n1 = to_read; - n2 = 0; - } + if (cnt2 > size) { + n1 = size - priv_read_idx; + n2 = cnt2 & size_mask; + } else { + n1 = to_read; + n2 = 0; + } - memcpy (dest, &buf[priv_read_idx], n1 * sizeof (T)); - priv_read_idx = (priv_read_idx + n1) & size_mask; + memcpy (dest, &buf[priv_read_idx], n1 * sizeof (T)); + priv_read_idx = (priv_read_idx + n1) & size_mask; - if (n2) { - memcpy (dest+n1, buf, n2 * sizeof (T)); - priv_read_idx = n2; - } + if (n2) { + memcpy (dest+n1, buf, n2 * sizeof (T)); + priv_read_idx = n2; + } - g_atomic_int_set(&read_idx, priv_read_idx); - return to_read; + g_atomic_int_set(&read_idx, priv_read_idx); + return to_read; } template /*LIBPBD_API*/ guint RingBuffer::write (T const *src, guint cnt) { - guint free_cnt; - guint cnt2; - guint to_write; - guint n1, n2; - guint priv_write_idx; + guint free_cnt; + guint cnt2; + guint to_write; + guint n1, n2; + guint priv_write_idx; - priv_write_idx=g_atomic_int_get(&write_idx); + priv_write_idx=g_atomic_int_get(&write_idx); - if ((free_cnt = write_space ()) == 0) { - return 0; - } + if ((free_cnt = write_space ()) == 0) { + return 0; + } - to_write = cnt > free_cnt ? free_cnt : cnt; + to_write = cnt > free_cnt ? free_cnt : cnt; - cnt2 = priv_write_idx + to_write; + cnt2 = priv_write_idx + to_write; - if (cnt2 > size) { - n1 = size - priv_write_idx; - n2 = cnt2 & size_mask; - } else { - n1 = to_write; - n2 = 0; - } + if (cnt2 > size) { + n1 = size - priv_write_idx; + n2 = cnt2 & size_mask; + } else { + n1 = to_write; + n2 = 0; + } - memcpy (&buf[priv_write_idx], src, n1 * sizeof (T)); - priv_write_idx = (priv_write_idx + n1) & size_mask; + memcpy (&buf[priv_write_idx], src, n1 * sizeof (T)); + priv_write_idx = (priv_write_idx + n1) & size_mask; - if (n2) { - memcpy (buf, src+n1, n2 * sizeof (T)); - priv_write_idx = n2; - } + if (n2) { + memcpy (buf, src+n1, n2 * sizeof (T)); + priv_write_idx = n2; + } - g_atomic_int_set(&write_idx, priv_write_idx); - return to_write; + g_atomic_int_set(&write_idx, priv_write_idx); + return to_write; } template /*LIBPBD_API*/ void diff --git a/libs/pbd/pbd/timersub.h b/libs/pbd/pbd/timersub.h index 6cb152414c..785cbdde9d 100644 --- a/libs/pbd/pbd/timersub.h +++ b/libs/pbd/pbd/timersub.h @@ -1,5 +1,5 @@ /* Copyright (C) 1991-1994,1996-2003,2005,2006,2009 - Free Software Foundation, Inc. + Free Software Foundation, Inc. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -19,14 +19,13 @@ #include #ifndef timersub -# define timersub(a, b, result) \ - do { \ - (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ - (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ - if ((result)->tv_usec < 0) { \ - --(result)->tv_sec; \ - (result)->tv_usec += 1000000; \ - } \ +# define timersub(a, b, result) \ + do { \ + (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ + (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ + if ((result)->tv_usec < 0) { \ + --(result)->tv_sec; \ + (result)->tv_usec += 1000000; \ + } \ } while (0) #endif - diff --git a/libs/pbd/pbd/tokenizer.h b/libs/pbd/pbd/tokenizer.h index ef9f3c951e..78e6be0490 100644 --- a/libs/pbd/pbd/tokenizer.h +++ b/libs/pbd/pbd/tokenizer.h @@ -43,49 +43,47 @@ tokenize(const StringType& str, Iter it, bool strip_whitespace=false) { - typename StringType::size_type start_pos = 0; - typename StringType::size_type end_pos = 0; - unsigned int token_count = 0; - - do { - start_pos = str.find_first_not_of(delims, start_pos); - end_pos = str.find_first_of(delims, start_pos); - if (start_pos != end_pos) { - if (end_pos == str.npos) { - end_pos = str.length(); - } - if (strip_whitespace) { + typename StringType::size_type start_pos = 0; + typename StringType::size_type end_pos = 0; + unsigned int token_count = 0; + + do { + start_pos = str.find_first_not_of(delims, start_pos); + end_pos = str.find_first_of(delims, start_pos); + if (start_pos != end_pos) { + if (end_pos == str.npos) { + end_pos = str.length(); + } + if (strip_whitespace) { StringType stripped = str.substr(start_pos, end_pos - start_pos); strip_whitespace_edges (stripped); if (stripped.length()) { *it++ = stripped; } } else { - *it++ = str.substr(start_pos, end_pos - start_pos); + *it++ = str.substr(start_pos, end_pos - start_pos); } - ++token_count; - start_pos = str.find_first_not_of(delims, end_pos + 1); - } - } while (start_pos != str.npos); + ++token_count; + start_pos = str.find_first_not_of(delims, end_pos + 1); + } + } while (start_pos != str.npos); - if (start_pos != str.npos) { - if (strip_whitespace) { + if (start_pos != str.npos) { + if (strip_whitespace) { StringType stripped = str.substr(start_pos, str.length() - start_pos); strip_whitespace_edges (stripped); if (stripped.length()) { *it++ = stripped; } } else { - *it++ = str.substr(start_pos, str.length() - start_pos); + *it++ = str.substr(start_pos, str.length() - start_pos); } - ++token_count; - } + ++token_count; + } - return token_count; + return token_count; } } // namespace PBD #endif // PBD_TOKENIZER - - -- cgit v1.2.3