<commit_before>
#ifndef _LO_CPP_H_
#define _LO_CPP_H_

#include <lo/lo.h>
#include <lo/lo_throw.h>

#include <functional>
#include <memory>
#include <list>
#include <unordered_map>
#include <string>
#include <sstream>
#include <initializer_list>

#define LO_ADD_METHOD_RT(ht, argtypes, args, rt, r, r1, r2)             \
    template <typename H>                                               \
    auto add_method(const string_type path, const string_type types, H&& h) \
    -> rt const                                                         \
    {                                                                   \
        std::string key = std::string(path._s?:"") + "," + (types._s?:""); \
        _handlers[key].push_front(                                      \
            std::unique_ptr<handler>(new handler_type<r ht>(h)));       \
        _add_method(path, types,                                        \
            [](const char *path, const char *types,                     \
               lo_arg **argv, int argc, void *msg,                      \
               void *data)->int                                         \
            {                                                           \
                r1 (*static_cast<handler_type<r ht>*>(data)) args; \
                r2;                                                     \
            }, _handlers[key].front().get());                           \
    }

#define RT_INT(argtypes) \
    typename std::enable_if<std::is_same<decltype(h argtypes), int>::value, void>::type
#define RT_VOID(argtypes) \
    typename std::enable_if<std::is_same<decltype(h argtypes), void>::value, void>::type

#define LO_ADD_METHOD(ht, argtypes, args)                         \
    LO_ADD_METHOD_RT(ht, argtypes, args,                          \
                     RT_INT(argtypes), int, return,);             \
    LO_ADD_METHOD_RT(ht, argtypes, args,                          \
                     RT_VOID(argtypes), void, , return 0)

namespace lo {

    // Helper classes to allow polymorphism on "const char *",
    // "std::string", and "int".
    class string_type {
      public:
        string_type(const char *s=0) { _s = s; }
        string_type(const std::string &s) { _s = s.c_str(); }
        operator const char*() const { return _s; }
        const char *_s;
    };

    class num_string_type : public string_type {
      public:
      num_string_type(const char *s) : string_type(s) {}
      num_string_type(const std::string &s) : string_type(s) {}
        num_string_type(int n) { std::ostringstream ss; ss << n;
            _p.reset(new std::string(ss.str())); _s = _p->c_str(); }
        std::unique_ptr<std::string> _p;
    };

    class Address
    {
      public:
        Address(const string_type &host, const num_string_type &port,
                int proto=LO_UDP)
          { address = lo_address_new_with_proto(proto, host, port); owned=true; }

        Address(const string_type &url)
          { address = lo_address_new_from_url(url); owned=true; }

        Address(lo_address a, bool _owned=true)
          { address = a; owned=_owned; }

        ~Address()
          { if (address && owned) lo_address_free(address); }

        Address& operator=(Address b) { b.swap(*this); return *this; }
        void swap(Address& b) throw () { std::swap(this->address, b.address); }

        int ttl() const
          { return lo_address_get_ttl(address); }

        void set_ttl(int ttl)
          { lo_address_set_ttl(address, ttl); }

        int send(const string_type &path) const
          { return lo_send(address, path, ""); }

        // In these functions we append "$$" to the type string, which
        // simply instructs lo_message_add_varargs() not to use
        // LO_MARKER checking at the end of the argument list.
        int send(const string_type &path, const string_type &type, ...) const
        {
            va_list q;
            va_start(q, type);
            lo_message m = lo_message_new();
            std::string t = std::string(type) + "$$";
            lo_message_add_varargs(m, t.c_str(), q);
            int r = lo_send_message(address, path, m);
            lo_message_free(m);
            return r;
        }

        int send(lo_timetag ts, const string_type &path,
                 const string_type &type, ...) const
        {
            va_list q;
            va_start(q, type);
            lo_message m = lo_message_new();
            std::string t = std::string(type) + "$$";
            lo_message_add_varargs(m, t.c_str(), q);
            lo_bundle b = lo_bundle_new(ts);
            lo_bundle_add_message(b, path, m);
            int r = lo_send_bundle(address, b);
            lo_bundle_free_messages(m);
            return r;
        }

        int send(const string_type &path, lo_message m) const
            { return lo_send_message(address, path, m); }

        int send(lo_bundle b)
            { return lo_send_bundle(address, b); }

        int send_from(lo_server from, const string_type &path,
                      const string_type &type, ...) const
        {
            va_list q;
            va_start(q, type);
            lo_message m = lo_message_new();
            std::string t = std::string(type) + "$$";
            lo_message_add_varargs(m, t.c_str(), q);
            int r = lo_send_message_from(from, address, path, m);
            lo_message_free(m);
            return r;
        }

        int send_from(lo_server from, lo_timetag ts, 
                      const string_type &path,
                      const string_type &type, ...) const
        {
            va_list q;
            va_start(q, type);
            lo_message m = lo_message_new();
            std::string t = std::string(type) + "$$";
            lo_message_add_varargs(m, t.c_str(), q);
            lo_bundle b = lo_bundle_new(ts);
            lo_bundle_add_message(b, path, m);
            int r = lo_send_bundle_from(from, address, b);<commit_msg>Fix a typo in lo::Address:send_from.<commit_after>
#ifndef _LO_CPP_H_
#define _LO_CPP_H_

#include <lo/lo.h>
#include <lo/lo_throw.h>

#include <functional>
#include <memory>
#include <list>
#include <unordered_map>
#include <string>
#include <sstream>
#include <initializer_list>

#define LO_ADD_METHOD_RT(ht, argtypes, args, rt, r, r1, r2)             \
    template <typename H>                                               \
    auto add_method(const string_type path, const string_type types, H&& h) \
    -> rt const                                                         \
    {                                                                   \
        std::string key = std::string(path._s?:"") + "," + (types._s?:""); \
        _handlers[key].push_front(                                      \
            std::unique_ptr<handler>(new handler_type<r ht>(h)));       \
        _add_method(path, types,                                        \
            [](const char *path, const char *types,                     \
               lo_arg **argv, int argc, void *msg,                      \
               void *data)->int                                         \
            {                                                           \
                r1 (*static_cast<handler_type<r ht>*>(data)) args; \
                r2;                                                     \
            }, _handlers[key].front().get());                           \
    }

#define RT_INT(argtypes) \
    typename std::enable_if<std::is_same<decltype(h argtypes), int>::value, void>::type
#define RT_VOID(argtypes) \
    typename std::enable_if<std::is_same<decltype(h argtypes), void>::value, void>::type

#define LO_ADD_METHOD(ht, argtypes, args)                         \
    LO_ADD_METHOD_RT(ht, argtypes, args,                          \
                     RT_INT(argtypes), int, return,);             \
    LO_ADD_METHOD_RT(ht, argtypes, args,                          \
                     RT_VOID(argtypes), void, , return 0)

namespace lo {

    // Helper classes to allow polymorphism on "const char *",
    // "std::string", and "int".
    class string_type {
      public:
        string_type(const char *s=0) { _s = s; }
        string_type(const std::string &s) { _s = s.c_str(); }
        operator const char*() const { return _s; }
        const char *_s;
    };

    class num_string_type : public string_type {
      public:
      num_string_type(const char *s) : string_type(s) {}
      num_string_type(const std::string &s) : string_type(s) {}
        num_string_type(int n) { std::ostringstream ss; ss << n;
            _p.reset(new std::string(ss.str())); _s = _p->c_str(); }
        std::unique_ptr<std::string> _p;
    };

    class Address
    {
      public:
        Address(const string_type &host, const num_string_type &port,
                int proto=LO_UDP)
          { address = lo_address_new_with_proto(proto, host, port); owned=true; }

        Address(const string_type &url)
          { address = lo_address_new_from_url(url); owned=true; }

        Address(lo_address a, bool _owned=true)
          { address = a; owned=_owned; }

        ~Address()
          { if (address && owned) lo_address_free(address); }

        Address& operator=(Address b) { b.swap(*this); return *this; }
        void swap(Address& b) throw () { std::swap(this->address, b.address); }

        int ttl() const
          { return lo_address_get_ttl(address); }

        void set_ttl(int ttl)
          { lo_address_set_ttl(address, ttl); }

        int send(const string_type &path) const
          { return lo_send(address, path, ""); }

        // In these functions we append "$$" to the type string, which
        // simply instructs lo_message_add_varargs() not to use
        // LO_MARKER checking at the end of the argument list.
        int send(const string_type &path, const string_type &type, ...) const
        {
            va_list q;
            va_start(q, type);
            lo_message m = lo_message_new();
            std::string t = std::string(type) + "$$";
            lo_message_add_varargs(m, t.c_str(), q);
            int r = lo_send_message(address, path, m);
            lo_message_free(m);
            return r;
        }

        int send(lo_timetag ts, const string_type &path,
                 const string_type &type, ...) const
        {
            va_list q;
            va_start(q, type);
            lo_message m = lo_message_new();
            std::string t = std::string(type) + "$$";
            lo_message_add_varargs(m, t.c_str(), q);
            lo_bundle b = lo_bundle_new(ts);
            lo_bundle_add_message(b, path, m);
            int r = lo_send_bundle(address, b);
            lo_bundle_free_messages(m);
            return r;
        }

        int send(const string_type &path, lo_message m) const
            { return lo_send_message(address, path, m); }

        int send(lo_bundle b)
            { return lo_send_bundle(address, b); }

        int send_from(lo_server from, const string_type &path,
                      const string_type &type, ...) const
        {
            va_list q;
            va_start(q, type);
            lo_message m = lo_message_new();
            std::string t = std::string(type) + "$$";
            lo_message_add_varargs(m, t.c_str(), q);
            int r = lo_send_message_from(address, from, path, m);
            lo_message_free(m);
            return r;
        }

        int send_from(lo_server from, lo_timetag ts, 
                      const string_type &path,
                      const string_type &type, ...) const
        {
            va_list q;
            va_start(q, type);
            lo_message m = lo_message_new();
            std::string t = std::string(type) + "$$";
            lo_message_add_varargs(m, t.c_str(), q);
            lo_bundle b = lo_bundle_new(ts);
            lo_bundle_add_message(b, path, m);
            int r = lo_send_bundle_from(from, address, b);
{'fraction_non_alphanumeric': 0.11660688964884477, 'fraction_numerical': 0.0010009175077154058, 'mean_word_length': 1.5829383886255923, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '444843', 'n_tokens_mistral': 3574, 'n_tokens_neox': 3495, 'n_words': 813}