refactor: Pass by value

This commit is contained in:
Michael Carlberg 2016-06-21 03:59:43 +02:00
parent b26ab9ce5f
commit e1f8c001dd
72 changed files with 253 additions and 253 deletions

View file

@ -20,7 +20,7 @@ struct Font
std::string id; std::string id;
int offset; int offset;
Font(const std::string& id, int offset) Font(std::string id, int offset)
: id(id), offset(offset){} : id(id), offset(offset){}
}; };

View file

@ -34,5 +34,5 @@ namespace drawtypes
} }
}; };
std::unique_ptr<Animation> get_config_animation(const std::string& config_path, const std::string& animation_name = "animation", bool required = true); std::unique_ptr<Animation> get_config_animation(std::string config_path, std::string animation_name = "animation", bool required = true);
} }

View file

@ -24,7 +24,7 @@ namespace drawtypes
std::unique_ptr<Icon> indicator; std::unique_ptr<Icon> indicator;
public: public:
Bar(int width, const std::string& fmt, bool lazy_builder_closing = true); Bar(int width, std::string fmt, bool lazy_builder_closing = true);
Bar(int width, bool lazy_builder_closing = true) Bar(int width, bool lazy_builder_closing = true)
: Bar(width, "<fill><indicator><empty>", lazy_builder_closing){} : Bar(width, "<fill><indicator><empty>", lazy_builder_closing){}
@ -38,5 +38,5 @@ namespace drawtypes
std::string get_output(float percentage, bool floor_percentage = false); std::string get_output(float percentage, bool floor_percentage = false);
}; };
std::unique_ptr<Bar> get_config_bar(const std::string& config_path, const std::string& bar_name = "bar", bool lazy_builder_closing = true); std::unique_ptr<Bar> get_config_bar(std::string config_path, std::string bar_name = "bar", bool lazy_builder_closing = true);
} }

View file

@ -11,9 +11,9 @@ namespace drawtypes
{ {
struct Icon : public Label struct Icon : public Label
{ {
Icon(const std::string& icon, int font = 0) Icon(std::string icon, int font = 0)
: Label(icon, font){} : Label(icon, font){}
Icon(const std::string& icon, const std::string& fg, const std::string& bg = "", const std::string& ul = "", const std::string& ol = "", int font = 0, int padding = 0, int margin = 0) Icon(std::string icon, std::string fg, std::string bg = "", std::string ul = "", std::string ol = "", int font = 0, int padding = 0, int margin = 0)
: Label(icon, fg, bg, ul, ol, font, padding, margin){} : Label(icon, fg, bg, ul, ol, font, padding, margin){}
std::unique_ptr<Icon> clone(); std::unique_ptr<Icon> clone();
@ -24,15 +24,15 @@ namespace drawtypes
std::map<std::string, std::unique_ptr<Icon>> icons; std::map<std::string, std::unique_ptr<Icon>> icons;
public: public:
void add(const std::string& id, std::unique_ptr<Icon> &&icon); void add(std::string id, std::unique_ptr<Icon> &&icon);
std::unique_ptr<Icon> &get(const std::string& id, const std::string& fallback_id = ""); std::unique_ptr<Icon> &get(std::string id, std::string fallback_id = "");
bool has(const std::string& id); bool has(std::string id);
operator bool() { operator bool() {
return this->icons.size() > 0; return this->icons.size() > 0;
} }
}; };
std::unique_ptr<Icon> get_config_icon(const std::string& module_name, const std::string& icon_name = "icon", bool required = true, const std::string& def = ""); std::unique_ptr<Icon> get_config_icon(std::string module_name, std::string icon_name = "icon", bool required = true, std::string def = "");
std::unique_ptr<Icon> get_optional_config_icon(const std::string& module_name, const std::string& icon_name = "icon", const std::string& def = ""); std::unique_ptr<Icon> get_optional_config_icon(std::string module_name, std::string icon_name = "icon", std::string def = "");
} }

View file

@ -10,9 +10,9 @@ namespace drawtypes
std::string text, fg, bg, ul, ol; std::string text, fg, bg, ul, ol;
int font = 0, padding = 0, margin = 0; int font = 0, padding = 0, margin = 0;
Label(const std::string& text, int font) Label(std::string text, int font)
: text(text), font(font){} : text(text), font(font){}
Label(const std::string& text, const std::string& fg = "", const std::string& bg = "", const std::string& ul = "", const std::string& ol = "", int font = 0, int padding = 0, int margin = 0) Label(std::string text, std::string fg = "", std::string bg = "", std::string ul = "", std::string ol = "", int font = 0, int padding = 0, int margin = 0)
: text(text), fg(fg), bg(bg), ul(ul), ol(ol), font(font), padding(padding), margin(margin){} : text(text), fg(fg), bg(bg), ul(ul), ol(ol), font(font), padding(padding), margin(margin){}
operator bool() { operator bool() {
@ -21,10 +21,10 @@ namespace drawtypes
std::unique_ptr<Label> clone(); std::unique_ptr<Label> clone();
void replace_token(const std::string& token, const std::string& replacement); void replace_token(std::string token, std::string replacement);
void replace_defined_values(std::unique_ptr<Label> &label); void replace_defined_values(std::unique_ptr<Label> &label);
}; };
std::unique_ptr<Label> get_config_label(const std::string& module_name, const std::string& label_name = "label", bool required = true, const std::string& def = ""); std::unique_ptr<Label> get_config_label(std::string module_name, std::string label_name = "label", bool required = true, std::string def = "");
std::unique_ptr<Label> get_optional_config_label(const std::string& module_name, const std::string& label_name = "label", const std::string& def = ""); std::unique_ptr<Label> get_optional_config_label(std::string module_name, std::string label_name = "label", std::string def = "");
} }

View file

@ -27,5 +27,5 @@ namespace drawtypes
} }
}; };
std::unique_ptr<Ramp> get_config_ramp(const std::string& module_name, const std::string& ramp_name = "ramp", bool required = true); std::unique_ptr<Ramp> get_config_ramp(std::string module_name, std::string ramp_name = "ramp", bool required = true);
} }

View file

@ -51,5 +51,5 @@ class EventLoop
void cleanup(int timeout_ms = 5000); void cleanup(int timeout_ms = 5000);
void add_stdin_subscriber(const std::string& module_name); void add_stdin_subscriber(std::string module_name);
}; };

View file

@ -19,13 +19,13 @@ namespace alsa
class Exception : public ::Exception class Exception : public ::Exception
{ {
public: public:
explicit Exception(const std::string& msg) : ::Exception("[Alsa] "+ msg){} explicit Exception(std::string msg) : ::Exception("[Alsa] "+ msg){}
}; };
class ControlInterfaceError : public Exception class ControlInterfaceError : public Exception
{ {
public: public:
ControlInterfaceError(int code, const std::string& msg) ControlInterfaceError(int code, std::string msg)
: Exception(msg +" ["+ std::to_string(code) +"]") {} : Exception(msg +" ["+ std::to_string(code) +"]") {}
}; };
@ -71,7 +71,7 @@ namespace alsa
snd_mixer_elem_t *mixer_element = nullptr; snd_mixer_elem_t *mixer_element = nullptr;
public: public:
explicit Mixer(const std::string& mixer_control_name); explicit Mixer(std::string mixer_control_name);
~Mixer(); ~Mixer();
Mixer(const Mixer &) = delete; Mixer(const Mixer &) = delete;
Mixer &operator=(const Mixer &) = delete; Mixer &operator=(const Mixer &) = delete;
@ -86,7 +86,7 @@ namespace alsa
bool is_muted(); bool is_muted();
protected: protected:
void error_handler(const std::string& message); void error_handler(std::string message);
}; };
// }}} // }}}

View file

@ -16,21 +16,21 @@ namespace mpd
class Exception : public ::Exception class Exception : public ::Exception
{ {
public: public:
Exception(const std::string& msg, bool clearable) Exception(std::string msg, bool clearable)
: ::Exception(msg + (clearable ? " (clearable)" : " (not clearable)")){} : ::Exception(msg + (clearable ? " (clearable)" : " (not clearable)")){}
}; };
class ClientError : public Exception class ClientError : public Exception
{ {
public: public:
explicit ClientError(const std::string& msg, mpd_error code, bool clearable) explicit ClientError(std::string msg, mpd_error code, bool clearable)
: Exception("[mpd::ClientError::"+ std::to_string(code) +"] "+ msg, clearable){} : Exception("[mpd::ClientError::"+ std::to_string(code) +"] "+ msg, clearable){}
}; };
class ServerError : public Exception class ServerError : public Exception
{ {
public: public:
ServerError(const std::string& msg, mpd_server_error code, bool clearable) ServerError(std::string msg, mpd_server_error code, bool clearable)
: Exception("[mpd::ServerError::"+ std::to_string(code) +"] "+ msg, clearable){} : Exception("[mpd::ServerError::"+ std::to_string(code) +"] "+ msg, clearable){}
}; };
@ -140,9 +140,9 @@ namespace mpd
void idle(); void idle();
int noidle(); int noidle();
void set_host(const std::string& host) { this->host = host; } void set_host(std::string host) { this->host = host; }
void set_port(int port) { this->port = port; } void set_port(int port) { this->port = port; }
void set_password(const std::string& password) { this->password = password; } void set_password(std::string password) { this->password = password; }
void set_timeout(int timeout) { this->timeout = timeout; } void set_timeout(int timeout) { this->timeout = timeout; }
std::unique_ptr<Status> get_status(); std::unique_ptr<Status> get_status();

View file

@ -13,14 +13,14 @@
namespace net namespace net
{ {
bool is_wireless_interface(const std::string& ifname); bool is_wireless_interface(std::string ifname);
// Network // Network
class NetworkException : public Exception class NetworkException : public Exception
{ {
public: public:
explicit NetworkException(const std::string& msg) explicit NetworkException(std::string msg)
: Exception("[Network] "+ msg){} : Exception("[Network] "+ msg){}
}; };
@ -36,7 +36,7 @@ namespace net
bool test_connection(); bool test_connection();
public: public:
explicit Network(const std::string& interface); explicit Network(std::string interface);
~Network(); ~Network();
virtual bool connected(); virtual bool connected();
@ -56,7 +56,7 @@ namespace net
int linkspeed = 0; int linkspeed = 0;
public: public:
explicit WiredNetwork(const std::string& interface); explicit WiredNetwork(std::string interface);
std::string get_link_speed(); std::string get_link_speed();
}; };
@ -72,7 +72,7 @@ namespace net
struct iwreq iw; struct iwreq iw;
public: public:
explicit WirelessNetwork(const std::string& interface); explicit WirelessNetwork(std::string interface);
std::string get_essid(); std::string get_essid();
float get_signal_dbm(); float get_signal_dbm();

View file

@ -7,4 +7,4 @@ DefineBaseException(ApplicationError);
void register_pid(pid_t pid); void register_pid(pid_t pid);
void unregister_pid(pid_t pid); void unregister_pid(pid_t pid);
void register_command_handler(const std::string& module_name); void register_command_handler(std::string module_name);

View file

@ -24,10 +24,10 @@ namespace modules
concurrency::Atomic<int> percentage; concurrency::Atomic<int> percentage;
public: public:
explicit BacklightModule(const std::string& name); explicit BacklightModule(std::string name);
bool on_event(InotifyEvent *event); bool on_event(InotifyEvent *event);
bool build(Builder *builder, const std::string& tag); bool build(Builder *builder, std::string tag);
void idle() const void idle() const
{ {

View file

@ -42,7 +42,6 @@ class ModuleFormatter
{ {
std::string value; std::string value;
std::vector<std::string> tags; std::vector<std::string> tags;
std::string fg, bg, ul, ol; std::string fg, bg, ul, ol;
int spacing, padding, margin, offset; int spacing, padding, margin, offset;
@ -78,7 +77,7 @@ class ModuleFormatter
std::map<std::string, std::unique_ptr<Format>> formats; std::map<std::string, std::unique_ptr<Format>> formats;
public: public:
explicit ModuleFormatter(const std::string& module_name) explicit ModuleFormatter(std::string module_name)
: module_name(module_name) {} : module_name(module_name) {}
void add(const std::string& name, const std::string& fallback, std::vector<std::string> &&tags, std::vector<std::string> &&whitelist = {}) void add(const std::string& name, const std::string& fallback, std::vector<std::string> &&tags, std::vector<std::string> &&whitelist = {})
@ -136,8 +135,8 @@ class ModuleFormatter
namespace modules namespace modules
{ {
void broadcast_module_update(const std::string& module_name); void broadcast_module_update(std::string module_name);
std::string get_tag_name(const std::string& tag); std::string get_tag_name(std::string tag);
struct ModuleInterface struct ModuleInterface
{ {
@ -152,7 +151,7 @@ namespace modules
virtual std::string operator()() = 0; virtual std::string operator()() = 0;
virtual bool handle_command(const std::string& cmd) = 0; virtual bool handle_command(std::string cmd) = 0;
}; };
template<typename ModuleImpl> template<typename ModuleImpl>
@ -219,7 +218,7 @@ namespace modules
return this->cache(); return this->cache();
} }
bool handle_command(const std::string& cmd) { bool handle_command(std::string cmd) {
return CastModule(ModuleImpl)->handle_command(cmd); return CastModule(ModuleImpl)->handle_command(cmd);
} }
@ -309,7 +308,7 @@ namespace modules
this->threads.emplace_back(std::thread(&StaticModule::broadcast, this)); this->threads.emplace_back(std::thread(&StaticModule::broadcast, this));
} }
bool build(Builder *builder, const std::string& tag) bool build(Builder *builder, std::string tag)
{ {
return true; return true;
} }
@ -336,7 +335,7 @@ namespace modules
public: public:
template<typename I> template<typename I>
TimerModule(const std::string& name, I const &interval) TimerModule(std::string name, I const &interval)
: Module<ModuleImpl>(name), interval(interval) {} : Module<ModuleImpl>(name), interval(interval) {}
void start() void start()

View file

@ -49,12 +49,12 @@ namespace modules
void subthread_routine(); void subthread_routine();
public: public:
explicit BatteryModule(const std::string& name); explicit BatteryModule(std::string name);
void start(); void start();
bool on_event(InotifyEvent *event); bool on_event(InotifyEvent *event);
std::string get_format(); std::string get_format();
bool build(Builder *builder, const std::string& tag); bool build(Builder *builder, std::string tag);
}; };
} }

View file

@ -66,13 +66,13 @@ namespace modules
std::string prev_data; std::string prev_data;
public: public:
BspwmModule(const std::string& name, const std::string& monitor); BspwmModule(std::string name, std::string monitor);
~BspwmModule() { close(this->socket_fd); } ~BspwmModule() { close(this->socket_fd); }
void start(); void start();
bool has_event(); bool has_event();
bool update(); bool update();
bool build(Builder *builder, const std::string& tag); bool build(Builder *builder, std::string tag);
bool handle_command(const std::string& cmd); bool handle_command(std::string cmd);
}; };
} }

View file

@ -11,9 +11,9 @@ namespace modules
concurrency::Atomic<int> counter; concurrency::Atomic<int> counter;
public: public:
explicit CounterModule(const std::string& name); explicit CounterModule(std::string name);
bool update(); bool update();
bool build(Builder *builder, const std::string& tag); bool build(Builder *builder, std::string tag);
}; };
} }

View file

@ -43,9 +43,9 @@ namespace modules
float get_load(int core); float get_load(int core);
public: public:
explicit CpuModule(const std::string& name); explicit CpuModule(std::string name);
bool update(); bool update();
bool build(Builder *builder, const std::string& tag); bool build(Builder *builder, std::string tag);
}; };
} }

View file

@ -19,12 +19,12 @@ namespace modules
bool detailed = false; bool detailed = false;
public: public:
explicit DateModule(const std::string& name); explicit DateModule(std::string name);
bool update(); bool update();
bool build(Builder *builder, const std::string& tag); bool build(Builder *builder, std::string tag);
std::string get_output(); std::string get_output();
bool handle_command(const std::string& cmd); bool handle_command(std::string cmd);
}; };
} }

View file

@ -63,15 +63,15 @@ namespace modules
int ipc_fd = -1; int ipc_fd = -1;
public: public:
i3Module(const std::string& name, const std::string& monitor); i3Module(std::string name, std::string monitor);
void start(); void start();
void stop(); void stop();
bool has_event(); bool has_event();
bool update(); bool update();
bool build(Builder *builder, const std::string& tag); bool build(Builder *builder, std::string tag);
bool handle_command(const std::string& cmd); bool handle_command(std::string cmd);
}; };
} }

View file

@ -24,9 +24,9 @@ namespace modules
std::atomic<int> percentage_free; std::atomic<int> percentage_free;
public: public:
explicit MemoryModule(const std::string& name); explicit MemoryModule(std::string name);
bool update(); bool update();
bool build(Builder *builder, const std::string& tag); bool build(Builder *builder, std::string tag);
}; };
} }

View file

@ -33,12 +33,12 @@ namespace modules
std::unique_ptr<drawtypes::Label> label_close; std::unique_ptr<drawtypes::Label> label_close;
public: public:
explicit MenuModule(const std::string& name); explicit MenuModule(std::string name);
std::string get_output(); std::string get_output();
bool build(Builder *builder, const std::string& tag); bool build(Builder *builder, std::string tag);
bool handle_command(const std::string& cmd); bool handle_command(std::string cmd);
}; };
} }

View file

@ -65,15 +65,15 @@ namespace modules
std::string progress_fill, progress_empty, progress_indicator; std::string progress_fill, progress_empty, progress_indicator;
public: public:
explicit MpdModule(const std::string& name); explicit MpdModule(std::string name);
~MpdModule(); ~MpdModule();
void start(); void start();
bool has_event(); bool has_event();
bool update(); bool update();
std::string get_format(); std::string get_format();
bool build(Builder *builder, const std::string& tag); bool build(Builder *builder, std::string tag);
bool handle_command(const std::string& cmd); bool handle_command(std::string cmd);
}; };
} }

View file

@ -50,14 +50,14 @@ namespace modules
void subthread_routine(); void subthread_routine();
public: public:
explicit NetworkModule(const std::string& name); explicit NetworkModule(std::string name);
void start(); void start();
bool update(); bool update();
std::string get_format(); std::string get_format();
bool build(Builder *builder, const std::string& tag); bool build(Builder *builder, std::string tag);
}; };
} }

View file

@ -27,11 +27,11 @@ namespace modules
protected: protected:
public: public:
explicit ScriptModule(const std::string& name); explicit ScriptModule(std::string name);
void start(); void start();
bool update(); bool update();
bool build(Builder *builder, const std::string& tag); bool build(Builder *builder, std::string tag);
std::string get_output(); std::string get_output();
}; };
} }

View file

@ -9,7 +9,7 @@ namespace modules
static constexpr auto FORMAT = "content"; static constexpr auto FORMAT = "content";
public: public:
explicit TextModule(const std::string& name); explicit TextModule(std::string name);
std::string get_format(); std::string get_format();
std::string get_output(); std::string get_output();

View file

@ -43,16 +43,15 @@ namespace modules
concurrency::Atomic<bool> has_changed; concurrency::Atomic<bool> has_changed;
public: public:
explicit VolumeModule(const std::string& name); explicit VolumeModule(std::string name);
~VolumeModule();
bool has_event(); bool has_event();
bool update(); bool update();
std::string get_format(); std::string get_format();
bool build(Builder *builder, const std::string& tag); bool build(Builder *builder, std::string tag);
std::string get_output(); std::string get_output();
bool handle_command(const std::string& cmd); bool handle_command(std::string cmd);
}; };
} }

View file

@ -40,9 +40,9 @@ class Registry
void load(); void load();
void unload(); void unload();
bool wait(); bool wait();
void notify(const std::string& module_name); void notify(std::string module_name);
std::string get(const std::string& module_name); std::string get(std::string module_name);
std::unique_ptr<RegistryModuleEntry>& find(const std::string& module_name); std::unique_ptr<RegistryModuleEntry>& find(std::string module_name);
}; };
std::shared_ptr<Registry> &get_registry(); std::shared_ptr<Registry> &get_registry();

View file

@ -34,7 +34,7 @@ class Builder
int T_value = 1; int T_value = 1;
std::string B_value = "", F_value = "", U_value = ""; std::string B_value = "", F_value = "", U_value = "";
void tag_open(char tag, const std::string& value); void tag_open(char tag, std::string value);
void tag_close(char tag); void tag_close(char tag);
void align_left(); void align_left();
@ -48,11 +48,11 @@ class Builder
std::string flush(); std::string flush();
void append(const std::string& node); void append(std::string node);
void append_module_output(Alignment alignment, const std::string& module_output, bool margin_left = true, bool margin_right = true); void append_module_output(Alignment alignment, std::string module_output, bool margin_left = true, bool margin_right = true);
void node(const std::string& str, bool add_space = false); void node(std::string str, bool add_space = false);
void node(const std::string& str, int font_index, bool add_space = false); void node(std::string str, int font_index, bool add_space = false);
void node(drawtypes::Bar *bar, float percentage, bool add_space = false); void node(drawtypes::Bar *bar, float percentage, bool add_space = false);
void node(std::unique_ptr<drawtypes::Bar> &bar, float percentage, bool add_space = false); void node(std::unique_ptr<drawtypes::Bar> &bar, float percentage, bool add_space = false);
@ -76,20 +76,20 @@ class Builder
void font(int index); void font(int index);
void font_close(bool force = false); void font_close(bool force = false);
void background(const std::string& color); void background(std::string color);
void background_close(bool force = false); void background_close(bool force = false);
void color(const std::string& color); void color(std::string color);
void color_alpha(const std::string& alpha); void color_alpha(std::string alpha);
void color_close(bool force = false); void color_close(bool force = false);
void line_color(const std::string& color); void line_color(std::string color);
void line_color_close(bool force = false); void line_color_close(bool force = false);
void overline(const std::string& color = ""); void overline(std::string color = "");
void overline_close(bool force = false); void overline_close(bool force = false);
void underline(const std::string& color = ""); void underline(std::string color = "");
void underline_close(bool force = false); void underline_close(bool force = false);
// void invert(); // void invert();

View file

@ -22,14 +22,14 @@ class Command
int fork_status; int fork_status;
public: public:
Command(const std::string& cmd, int stdout[2] = nullptr, int stdin[2] = nullptr); Command(std::string cmd, int stdout[2] = nullptr, int stdin[2] = nullptr);
~Command(); ~Command();
int exec(bool wait_for_completion = true); int exec(bool wait_for_completion = true);
int wait(); int wait();
void tail(std::function<void(std::string)> callback); void tail(std::function<void(std::string)> callback);
int writeline(const std::string& data); int writeline(std::string data);
int get_stdout(int); int get_stdout(int);
// int get_stdin(int); // int get_stdin(int);

View file

@ -8,7 +8,7 @@
class InotifyException : public Exception class InotifyException : public Exception
{ {
public: public:
explicit InotifyException(const std::string& msg) explicit InotifyException(std::string msg)
: Exception("[Inotify] "+ msg){} : Exception("[Inotify] "+ msg){}
}; };
@ -48,7 +48,7 @@ class InotifyWatch
int fd = -1, wd = -1, mask; int fd = -1, wd = -1, mask;
public: public:
explicit InotifyWatch(const std::string& path, int mask = InotifyEvent::ALL); explicit InotifyWatch(std::string path, int mask = InotifyEvent::ALL);
~InotifyWatch(); ~InotifyWatch();
std::string operator()() { std::string operator()() {

View file

@ -31,7 +31,7 @@ struct Store
std::string get_string(); std::string get_string();
std::string &get_string(std::string& s); std::string &get_string(std::string& s);
void set_string(const std::string& s); void set_string(std::string s);
Store(int size); Store(int size);
~Store() {} ~Store() {}

View file

@ -16,23 +16,23 @@ namespace cli
std::string help; std::string help;
std::vector<std::string> accept; std::vector<std::string> accept;
Option(const std::string& flag_short, const std::string& flag_long, const std::string& placeholder, std::vector<std::string> accept, std::string help) Option(std::string flag_short, std::string flag_long, std::string placeholder, std::vector<std::string> accept, std::string help)
: flag_short(flag_short), flag_long(flag_long), placeholder(placeholder), help(help), accept(accept){} : flag_short(flag_short), flag_long(flag_long), placeholder(placeholder), help(help), accept(accept){}
}; };
void add_option(const std::string& opt_short, const std::string& opt_long, const std::string& help); void add_option(std::string opt_short, std::string opt_long, std::string help);
void add_option(const std::string& opt_short, const std::string& opt_long, const std::string& placeholder, const std::string& help, std::vector<std::string> accept = {}); void add_option(std::string opt_short, std::string opt_long, std::string placeholder, std::string help, std::vector<std::string> accept = {});
bool is_option(char *opt, const std::string& opt_short, const std::string& opt_long); bool is_option(char *opt, std::string opt_short, std::string opt_long);
bool is_option_short(char *opt, const std::string& opt_short); bool is_option_short(char *opt, std::string opt_short);
bool is_option_long(char *opt, const std::string& opt_long); bool is_option_long(char *opt, std::string opt_long);
std::string parse_option_value(int &i, int argc, char **argv, std::vector<std::string> accept = {}); std::string parse_option_value(int &i, int argc, char **argv, std::vector<std::string> accept = {});
bool has_option(const std::string& opt); bool has_option(std::string opt);
std::string get_option_value(const std::string& opt); std::string get_option_value(std::string opt);
bool match_option_value(const std::string& opt, const std::string& val); bool match_option_value(std::string opt, std::string val);
void parse(int i, int argc, char **argv); void parse(int i, int argc, char **argv);
void usage(const std::string& usage, bool exit_success = true); void usage(std::string usage, bool exit_success = true);
} }

View file

@ -21,20 +21,20 @@ namespace config
static std::recursive_mutex mtx; static std::recursive_mutex mtx;
std::string get_bar_path(); std::string get_bar_path();
void set_bar_path(const std::string& path); void set_bar_path(std::string path);
void load(const std::string& path); void load(std::string path);
void load(const char *dir, const std::string& path); void load(const char *dir, std::string path);
// void reload(); // void reload();
boost::property_tree::ptree get_tree(); boost::property_tree::ptree get_tree();
std::string build_path(const std::string& section, const std::string& key); std::string build_path(std::string section, std::string key);
std::string get_file_path(); std::string get_file_path();
template<typename T> template<typename T>
T dereference_var(const std::string& ref_section, const std::string& ref_key, const std::string& var, const T ref_val) T dereference_var(std::string ref_section, std::string ref_key, std::string var, const T ref_val)
{ {
std::lock_guard<std::recursive_mutex> lck(config::mtx); std::lock_guard<std::recursive_mutex> lck(config::mtx);
@ -63,7 +63,7 @@ namespace config
} }
template<typename T> template<typename T>
T get(const std::string& section, const std::string& key) T get(std::string section, std::string key)
{ {
std::lock_guard<std::recursive_mutex> lck(config::mtx); std::lock_guard<std::recursive_mutex> lck(config::mtx);
@ -78,7 +78,7 @@ namespace config
} }
template<typename T> template<typename T>
T get(const std::string& section, const std::string& key, T default_value) T get(std::string section, std::string key, T default_value)
{ {
std::lock_guard<std::recursive_mutex> lck(config::mtx); std::lock_guard<std::recursive_mutex> lck(config::mtx);
@ -89,7 +89,7 @@ namespace config
} }
template<typename T> template<typename T>
std::vector<T> get_list(const std::string& section, const std::string& key) std::vector<T> get_list(std::string section, std::string key)
{ {
std::lock_guard<std::recursive_mutex> lck(config::mtx); std::lock_guard<std::recursive_mutex> lck(config::mtx);
@ -108,7 +108,7 @@ namespace config
} }
template<typename T> template<typename T>
std::vector<T> get_list(const std::string& section, const std::string& key, std::vector<T> default_value) std::vector<T> get_list(std::string section, std::string key, std::vector<T> default_value)
{ {
std::lock_guard<std::recursive_mutex> lck(config::mtx); std::lock_guard<std::recursive_mutex> lck(config::mtx);

View file

@ -13,8 +13,8 @@ namespace io
{ {
namespace socket namespace socket
{ {
int open(const std::string& path); int open(std::string path);
int send(int fd, const std::string& data, int flags = 0); int send(int fd, std::string data, int flags = 0);
int recv(int fd, char *buffer, int recv_bytes, int flags = 0); int recv(int fd, char *buffer, int recv_bytes, int flags = 0);
} }
@ -28,7 +28,7 @@ namespace io
std::string path; std::string path;
std::string mode; std::string mode;
FilePtr(const std::string& path, const std::string& mode = "a+") FilePtr(std::string path, std::string mode = "a+")
: path(std::string(path)), mode(std::string(mode)) : path(std::string(path)), mode(std::string(mode))
{ {
this->fptr = fopen(this->path.c_str(), this->mode.c_str()); this->fptr = fopen(this->path.c_str(), this->mode.c_str());
@ -49,11 +49,11 @@ namespace io
} }
}; };
bool exists(const std::string& fname); bool exists(std::string fname);
std::string get_contents(const std::string& fname); std::string get_contents(std::string fname);
bool is_fifo(const std::string& fname); bool is_fifo(std::string fname);
std::size_t write(FilePtr *fptr, const std::string& data); std::size_t write(FilePtr *fptr, std::string data);
std::size_t write(const std::string& fpath, const std::string& data); std::size_t write(std::string fpath, std::string data);
} }
std::string read(int read_fd, int bytes_to_read = -1); std::string read(int read_fd, int bytes_to_read = -1);
@ -61,8 +61,8 @@ namespace io
std::string readline(int read_fd, int &bytes_read); std::string readline(int read_fd, int &bytes_read);
std::string readline(int read_fd); std::string readline(int read_fd);
int write(int write_fd, const std::string& data); int write(int write_fd, std::string data);
int writeline(int write_fd, const std::string& data); int writeline(int write_fd, std::string data);
void tail(int read_fd, std::function<void(std::string)> callback); void tail(int read_fd, std::function<void(std::string)> callback);
void tail(int read_fd, int writeback_fd); void tail(int read_fd, int writeback_fd);

View file

@ -24,7 +24,7 @@ namespace proc
pid_t fork(); pid_t fork();
bool pipe(int fds[2]); bool pipe(int fds[2]);
void exec(const std::string& cmd); void exec(std::string cmd);
bool kill(pid_t pid, int sig = SIGTERM); bool kill(pid_t pid, int sig = SIGTERM);

View file

@ -5,27 +5,27 @@
namespace string namespace string
{ {
bool compare(const std::string& s1, const std::string& s2); bool compare(std::string s1, std::string s2);
// std::string upper(const std::string& s); // std::string upper(std::string s);
std::string lower(const std::string& s); std::string lower(std::string s);
std::string replace(const std::string& haystack, const std::string& needle, const std::string& replacement); std::string replace(std::string haystack, std::string needle, std::string replacement);
std::string replace_all(const std::string& haystack, const std::string& needle, const std::string& replacement); std::string replace_all(std::string haystack, std::string needle, std::string replacement);
std::string squeeze(const std::string& haystack, const char &needle); std::string squeeze(std::string haystack, const char &needle);
// std::string strip(const std::string& haystack, const char &needle); // std::string strip(std::string haystack, const char &needle);
std::string strip_trailing_newline(const std::string& s); std::string strip_trailing_newline(std::string s);
std::string trim(const std::string& haystack, const char &needle); std::string trim(std::string haystack, const char &needle);
std::string ltrim(const std::string& haystack, const char &needle); std::string ltrim(std::string haystack, const char &needle);
std::string rtrim(const std::string& haystack, const char &needle); std::string rtrim(std::string haystack, const char &needle);
std::string join(const std::vector<std::string> &strs, const std::string& delim); std::string join(const std::vector<std::string> &strs, std::string delim);
std::vector<std::string> split(const std::string& s, const char &delim); std::vector<std::string> split(std::string s, const char &delim);
std::vector<std::string> &split_into(const std::string& s, const char &delim, std::vector<std::string> &elems); std::vector<std::string> &split_into(std::string s, const char &delim, std::vector<std::string> &elems);
std::size_t find_nth(const std::string& haystack, std::size_t pos, const std::string& needle, std::size_t nth); std::size_t find_nth(std::string haystack, std::size_t pos, std::string needle, std::size_t nth);
} }

View file

@ -25,7 +25,7 @@ namespace xlib
} }
}; };
// std::unique_ptr<Monitor> get_monitor(const std::string& monitor_name); // std::unique_ptr<Monitor> get_monitor(std::string monitor_name);
std::vector<std::unique_ptr<Monitor>> get_sorted_monitorlist(); std::vector<std::unique_ptr<Monitor>> get_sorted_monitorlist();
} }

View file

@ -7,7 +7,7 @@
namespace drawtypes namespace drawtypes
{ {
std::unique_ptr<Animation> get_config_animation(const std::string& config_path, const std::string& animation_name, bool required) std::unique_ptr<Animation> get_config_animation(std::string config_path, std::string animation_name, bool required)
{ {
std::vector<std::unique_ptr<Icon>> vec; std::vector<std::unique_ptr<Icon>> vec;
std::vector<std::string> frames; std::vector<std::string> frames;

View file

@ -7,7 +7,7 @@
namespace drawtypes namespace drawtypes
{ {
std::unique_ptr<Bar> get_config_bar(const std::string& config_path, const std::string& bar_name, bool lazy_builder_closing) std::unique_ptr<Bar> get_config_bar(std::string config_path, std::string bar_name, bool lazy_builder_closing)
{ {
std::unique_ptr<Bar> bar; std::unique_ptr<Bar> bar;
@ -28,7 +28,7 @@ namespace drawtypes
return bar; return bar;
} }
Bar::Bar(int width, const std::string& fmt, bool lazy_builder_closing) Bar::Bar(int width, std::string fmt, bool lazy_builder_closing)
: builder(std::make_unique<Builder>(lazy_builder_closing)), format(fmt) : builder(std::make_unique<Builder>(lazy_builder_closing)), format(fmt)
{ {
this->width = width; this->width = width;

View file

@ -9,24 +9,24 @@ namespace drawtypes
this->text, this->fg, this->bg, this->ul, this->ol, this->font, this->padding, this->margin) }; this->text, this->fg, this->bg, this->ul, this->ol, this->font, this->padding, this->margin) };
} }
std::unique_ptr<Icon> get_config_icon(const std::string& config_path, const std::string& icon_name, bool required, const std::string& def) std::unique_ptr<Icon> get_config_icon(std::string config_path, std::string icon_name, bool required, std::string def)
{ {
auto label = get_config_label(config_path, icon_name, required, def); auto label = get_config_label(config_path, icon_name, required, def);
return std::unique_ptr<Icon> { new Icon(label->text, label->fg, label->bg, label->ul, label->ol, label->font) }; return std::unique_ptr<Icon> { new Icon(label->text, label->fg, label->bg, label->ul, label->ol, label->font) };
} }
std::unique_ptr<Icon> get_optional_config_icon(const std::string& config_path, const std::string& icon_name, const std::string& def) { std::unique_ptr<Icon> get_optional_config_icon(std::string config_path, std::string icon_name, std::string def) {
return get_config_icon(config_path, icon_name, false, def); return get_config_icon(config_path, icon_name, false, def);
} }
// IconMap // IconMap
void IconMap::add(const std::string& id, std::unique_ptr<Icon> &&icon) { void IconMap::add(std::string id, std::unique_ptr<Icon> &&icon) {
this->icons.insert(std::make_pair(id, std::move(icon))); this->icons.insert(std::make_pair(id, std::move(icon)));
} }
std::unique_ptr<Icon> &IconMap::get(const std::string& id, const std::string& fallback_id) std::unique_ptr<Icon> &IconMap::get(std::string id, std::string fallback_id)
{ {
auto icon = this->icons.find(id); auto icon = this->icons.find(id);
if (icon == this->icons.end()) if (icon == this->icons.end())
@ -34,7 +34,7 @@ namespace drawtypes
return icon->second; return icon->second;
} }
bool IconMap::has(const std::string& id) { bool IconMap::has(std::string id) {
return this->icons.find(id) != this->icons.end(); return this->icons.find(id) != this->icons.end();
} }
} }

View file

@ -9,7 +9,7 @@ namespace drawtypes
this->text, this->fg, this->bg, this->ul, this->ol, this->font, this->padding, this->margin) }; this->text, this->fg, this->bg, this->ul, this->ol, this->font, this->padding, this->margin) };
} }
void Label::replace_token(const std::string& token, const std::string& replacement) { void Label::replace_token(std::string token, std::string replacement) {
this->text = string::replace_all(this->text, token, replacement); this->text = string::replace_all(this->text, token, replacement);
} }
@ -21,7 +21,7 @@ namespace drawtypes
if (!label->ol.empty()) this->ol = label->ol; if (!label->ol.empty()) this->ol = label->ol;
} }
std::unique_ptr<Label> get_config_label(const std::string& config_path, const std::string& label_name, bool required, const std::string& def) std::unique_ptr<Label> get_config_label(std::string config_path, std::string label_name, bool required, std::string def)
{ {
std::string label; std::string label;
@ -40,7 +40,7 @@ namespace drawtypes
config::get<int>(config_path, label_name +"-margin", 0)) }; config::get<int>(config_path, label_name +"-margin", 0)) };
} }
std::unique_ptr<Label> get_optional_config_label(const std::string& config_path, const std::string& label_name, const std::string& def) { std::unique_ptr<Label> get_optional_config_label(std::string config_path, std::string label_name, std::string def) {
return get_config_label(config_path, label_name, false, def); return get_config_label(config_path, label_name, false, def);
} }
} }

View file

@ -4,7 +4,7 @@
namespace drawtypes namespace drawtypes
{ {
std::unique_ptr<Ramp> get_config_ramp(const std::string& config_path, const std::string& ramp_name, bool required) std::unique_ptr<Ramp> get_config_ramp(std::string config_path, std::string ramp_name, bool required)
{ {
std::vector<std::unique_ptr<Icon>> vec; std::vector<std::unique_ptr<Icon>> vec;
std::vector<std::string> icons; std::vector<std::string> icons;

View file

@ -98,7 +98,7 @@ void EventLoop::wait()
this->logger->info("Termination signal received... Shutting down"); this->logger->info("Termination signal received... Shutting down");
} }
void EventLoop::add_stdin_subscriber(const std::string& module_name) void EventLoop::add_stdin_subscriber(std::string module_name)
{ {
// this->stdin_subs.insert(std::make_pair("TAG", module_name)); // this->stdin_subs.insert(std::make_pair("TAG", module_name));
this->stdin_subs.emplace_back(module_name); this->stdin_subs.emplace_back(module_name);

View file

@ -87,7 +87,7 @@ namespace alsa
// }}} // }}}
// Mixer {{{ // Mixer {{{
Mixer::Mixer(const std::string& mixer_control_name) Mixer::Mixer(std::string mixer_control_name)
{ {
snd_mixer_selem_id_t *mixer_id; snd_mixer_selem_id_t *mixer_id;

View file

@ -20,14 +20,14 @@
using namespace net; using namespace net;
bool net::is_wireless_interface(const std::string& ifname) { bool net::is_wireless_interface(std::string ifname) {
return io::file::exists("/sys/class/net/"+ ifname +"/wireless"); return io::file::exists("/sys/class/net/"+ ifname +"/wireless");
} }
// Network // Network
Network::Network(const std::string& interface) Network::Network(std::string interface)
: interface(interface) : interface(interface)
{ {
if (if_nametoindex(this->interface.c_str()) == 0) if (if_nametoindex(this->interface.c_str()) == 0)
@ -108,7 +108,7 @@ std::string Network::get_ip()
// WiredNetwork // WiredNetwork
WiredNetwork::WiredNetwork(const std::string& interface) : Network(interface) WiredNetwork::WiredNetwork(std::string interface) : Network(interface)
{ {
struct ethtool_cmd e; struct ethtool_cmd e;
@ -127,7 +127,7 @@ std::string WiredNetwork::get_link_speed() {
// WirelessNetwork // WirelessNetwork
WirelessNetwork::WirelessNetwork(const std::string& interface) : Network(interface) { WirelessNetwork::WirelessNetwork(std::string interface) : Network(interface) {
std::strcpy((char *) &this->iw.ifr_ifrn.ifrn_name, this->interface.c_str()); std::strcpy((char *) &this->iw.ifr_ifrn.ifrn_name, this->interface.c_str());
} }

View file

@ -38,7 +38,7 @@ void unregister_pid(pid_t pid) {
std::lock_guard<std::mutex> lck(pid_mtx); std::lock_guard<std::mutex> lck(pid_mtx);
pids.erase(std::remove(pids.begin(), pids.end(), pid), pids.end()); pids.erase(std::remove(pids.begin(), pids.end(), pid), pids.end());
} }
void register_command_handler(const std::string& module_name) { void register_command_handler(std::string module_name) {
eventloop->add_stdin_subscriber(module_name); eventloop->add_stdin_subscriber(module_name);
} }
@ -191,7 +191,8 @@ int main(int argc, char **argv)
if (eventloop) if (eventloop)
eventloop->cleanup(); eventloop->cleanup();
while (proc::wait_for_completion_nohang() > 0); while (proc::wait_for_completion_nohang() > 0)
;
log_trace("Reached end of application"); log_trace("Reached end of application");

View file

@ -4,7 +4,7 @@
using namespace modules; using namespace modules;
BacklightModule::BacklightModule(const std::string& name_) : InotifyModule(name_) BacklightModule::BacklightModule(std::string name_) : InotifyModule(name_)
{ {
// Load configuration values // Load configuration values
auto card = config::get<std::string>(name(), "card"); auto card = config::get<std::string>(name(), "card");
@ -57,7 +57,7 @@ bool BacklightModule::on_event(InotifyEvent *event)
return true; return true;
} }
bool BacklightModule::build(Builder *builder, const std::string& tag) bool BacklightModule::build(Builder *builder, std::string tag)
{ {
if (tag == TAG_BAR) if (tag == TAG_BAR)
builder->node(this->bar, this->percentage()); builder->node(this->bar, this->percentage());

View file

@ -6,12 +6,13 @@
namespace modules namespace modules
{ {
void broadcast_module_update(const std::string& module_name) { void broadcast_module_update(std::string module_name)
{
log_trace("Broadcasting module update for => "+ module_name); log_trace("Broadcasting module update for => "+ module_name);
get_registry()->notify(module_name); get_registry()->notify(module_name);
} }
std::string get_tag_name(const std::string& tag) { std::string get_tag_name(std::string tag) {
return tag.length() < 2 ? "" : tag.substr(1, tag.length()-2); return tag.length() < 2 ? "" : tag.substr(1, tag.length()-2);
} }
} }

View file

@ -17,7 +17,7 @@ const int modules::BatteryModule::STATE_CHARGING;
const int modules::BatteryModule::STATE_DISCHARGING; const int modules::BatteryModule::STATE_DISCHARGING;
const int modules::BatteryModule::STATE_FULL; const int modules::BatteryModule::STATE_FULL;
BatteryModule::BatteryModule(const std::string& name_) : InotifyModule(name_) BatteryModule::BatteryModule(std::string name_) : InotifyModule(name_)
{ {
this->battery = config::get<std::string>(name(), "battery", "BAT0"); this->battery = config::get<std::string>(name(), "battery", "BAT0");
this->adapter = config::get<std::string>(name(), "adapter", "ADP1"); this->adapter = config::get<std::string>(name(), "adapter", "ADP1");
@ -179,7 +179,7 @@ std::string BatteryModule::get_format()
return FORMAT_DISCHARGING; return FORMAT_DISCHARGING;
} }
bool BatteryModule::build(Builder *builder, const std::string& tag) bool BatteryModule::build(Builder *builder, std::string tag)
{ {
if (tag == TAG_ANIMATION_CHARGING) if (tag == TAG_ANIMATION_CHARGING)
builder->node(this->animation_charging); builder->node(this->animation_charging);

View file

@ -17,7 +17,7 @@ using namespace Bspwm;
#define DEFAULT_WS_ICON "workspace_icon-default" #define DEFAULT_WS_ICON "workspace_icon-default"
#define DEFAULT_WS_LABEL "%icon% %name%" #define DEFAULT_WS_LABEL "%icon% %name%"
BspwmModule::BspwmModule(const std::string& name_, const std::string& monitor) BspwmModule::BspwmModule(std::string name_, std::string monitor)
: EventModule(name_), monitor(monitor) : EventModule(name_), monitor(monitor)
{ {
this->formatter->add(DEFAULT_FORMAT, TAG_LABEL_STATE, { TAG_LABEL_STATE }, { TAG_LABEL_MODE }); this->formatter->add(DEFAULT_FORMAT, TAG_LABEL_STATE, { TAG_LABEL_STATE }, { TAG_LABEL_MODE });
@ -193,7 +193,7 @@ bool BspwmModule::update()
return true; return true;
} }
bool BspwmModule::build(Builder *builder, const std::string& tag) bool BspwmModule::build(Builder *builder, std::string tag)
{ {
if (tag != TAG_LABEL_STATE) if (tag != TAG_LABEL_STATE)
return false; return false;
@ -218,7 +218,7 @@ bool BspwmModule::build(Builder *builder, const std::string& tag)
return true; return true;
} }
bool BspwmModule::handle_command(const std::string& cmd) bool BspwmModule::handle_command(std::string cmd)
{ {
if (cmd.find(EVENT_CLICK) == std::string::npos || cmd.length() <= std::strlen(EVENT_CLICK)) if (cmd.find(EVENT_CLICK) == std::string::npos || cmd.length() <= std::strlen(EVENT_CLICK))
return false; return false;

View file

@ -6,7 +6,7 @@
using namespace modules; using namespace modules;
CounterModule::CounterModule(const std::string& module_name) : TimerModule(module_name, 1s) CounterModule::CounterModule(std::string module_name) : TimerModule(module_name, 1s)
{ {
this->interval = std::chrono::duration<double>( this->interval = std::chrono::duration<double>(
config::get<float>(name(), "interval", 1)); config::get<float>(name(), "interval", 1));
@ -22,7 +22,7 @@ bool CounterModule::update()
return true; return true;
} }
bool CounterModule::build(Builder *builder, const std::string& tag) bool CounterModule::build(Builder *builder, std::string tag)
{ {
if (tag == TAG_COUNTER) { if (tag == TAG_COUNTER) {
builder->node(std::to_string(this->counter())); builder->node(std::to_string(this->counter()));

View file

@ -7,7 +7,7 @@
using namespace modules; using namespace modules;
CpuModule::CpuModule(const std::string& name_) : TimerModule(name_, 1s) CpuModule::CpuModule(std::string name_) : TimerModule(name_, 1s)
{ {
this->interval = std::chrono::duration<double>( this->interval = std::chrono::duration<double>(
config::get<float>(name(), "interval", 1)); config::get<float>(name(), "interval", 1));
@ -60,7 +60,7 @@ bool CpuModule::update()
return true; return true;
} }
bool CpuModule::build(Builder *builder, const std::string& tag) bool CpuModule::build(Builder *builder, std::string tag)
{ {
if (tag == TAG_LABEL) if (tag == TAG_LABEL)
builder->node(this->label_tokenized); builder->node(this->label_tokenized);

View file

@ -6,7 +6,7 @@
using namespace modules; using namespace modules;
DateModule::DateModule(const std::string& name_) DateModule::DateModule(std::string name_)
: TimerModule(name_, 1s), builder(std::make_unique<Builder>()) : TimerModule(name_, 1s), builder(std::make_unique<Builder>())
{ {
this->interval = std::chrono::duration<double>( this->interval = std::chrono::duration<double>(
@ -42,14 +42,14 @@ std::string DateModule::get_output()
return this->builder->flush(); return this->builder->flush();
} }
bool DateModule::build(Builder *builder, const std::string& tag) bool DateModule::build(Builder *builder, std::string tag)
{ {
if (tag == TAG_DATE) if (tag == TAG_DATE)
builder->node(this->date_str); builder->node(this->date_str);
return tag == TAG_DATE; return tag == TAG_DATE;
} }
bool DateModule::handle_command(const std::string& cmd) bool DateModule::handle_command(std::string cmd)
{ {
if (cmd == EVENT_TOGGLE) { if (cmd == EVENT_TOGGLE) {
this->detailed = !this->detailed; this->detailed = !this->detailed;

View file

@ -22,7 +22,7 @@ using namespace modules;
// TODO: Needs more testing // TODO: Needs more testing
// TODO: Add mode indicators // TODO: Add mode indicators
i3Module::i3Module(const std::string& name_, const std::string& monitor) : EventModule(name_) i3Module::i3Module(std::string name_, std::string monitor) : EventModule(name_)
{ {
try { try {
this->ipc = std::make_unique<i3ipc::connection>(); this->ipc = std::make_unique<i3ipc::connection>();
@ -152,7 +152,7 @@ bool i3Module::update()
return true; return true;
} }
bool i3Module::build(Builder *builder, const std::string& tag) bool i3Module::build(Builder *builder, std::string tag)
{ {
if (tag != TAG_LABEL_STATE) if (tag != TAG_LABEL_STATE)
return false; return false;
@ -166,7 +166,7 @@ bool i3Module::build(Builder *builder, const std::string& tag)
return true; return true;
} }
bool i3Module::handle_command(const std::string& cmd) bool i3Module::handle_command(std::string cmd)
{ {
if (cmd.find(EVENT_CLICK) == std::string::npos || cmd.length() < std::strlen(EVENT_CLICK)) if (cmd.find(EVENT_CLICK) == std::string::npos || cmd.length() < std::strlen(EVENT_CLICK))
return false; return false;

View file

@ -5,7 +5,7 @@
using namespace modules; using namespace modules;
MemoryModule::MemoryModule(const std::string& name_) : TimerModule(name_, 1s) MemoryModule::MemoryModule(std::string name_) : TimerModule(name_, 1s)
{ {
this->interval = std::chrono::duration<double>( this->interval = std::chrono::duration<double>(
config::get<float>(name(), "interval", 1)); config::get<float>(name(), "interval", 1));
@ -63,7 +63,7 @@ bool MemoryModule::update()
this->label_tokenized->replace_token("%percentage_used%", std::to_string(this->percentage_used)+"%"); this->label_tokenized->replace_token("%percentage_used%", std::to_string(this->percentage_used)+"%");
this->label_tokenized->replace_token("%percentage_free%", std::to_string(this->percentage_free)+"%"); this->label_tokenized->replace_token("%percentage_free%", std::to_string(this->percentage_free)+"%");
auto replace_unit = [](drawtypes::Label *label, const std::string& token, float value, const std::string& unit){ auto replace_unit = [](drawtypes::Label *label, std::string token, float value, std::string unit){
if (label->text.find(token) != std::string::npos) { if (label->text.find(token) != std::string::npos) {
std::stringstream ss; std::stringstream ss;
ss.precision(2); ss.precision(2);
@ -83,7 +83,7 @@ bool MemoryModule::update()
return true; return true;
} }
bool MemoryModule::build(Builder *builder, const std::string& tag) bool MemoryModule::build(Builder *builder, std::string tag)
{ {
if (tag == TAG_BAR_USED) if (tag == TAG_BAR_USED)
builder->node(this->bar_used, this->percentage_used); builder->node(this->bar_used, this->percentage_used);

View file

@ -5,7 +5,7 @@
using namespace modules; using namespace modules;
MenuModule::MenuModule(const std::string& name_) : StaticModule(name_) MenuModule::MenuModule(std::string name_) : StaticModule(name_)
{ {
auto default_format_string = std::string(TAG_LABEL_TOGGLE) +" "+ std::string(TAG_MENU); auto default_format_string = std::string(TAG_LABEL_TOGGLE) +" "+ std::string(TAG_MENU);
@ -59,7 +59,7 @@ std::string MenuModule::get_output()
return this->builder->flush(); return this->builder->flush();
} }
bool MenuModule::build(Builder *builder, const std::string& tag) bool MenuModule::build(Builder *builder, std::string tag)
{ {
if (tag == TAG_LABEL_TOGGLE && this->current_level == -1) { if (tag == TAG_LABEL_TOGGLE && this->current_level == -1) {
builder->cmd(Cmd::LEFT_CLICK, std::string(EVENT_MENU_OPEN) +"0"); builder->cmd(Cmd::LEFT_CLICK, std::string(EVENT_MENU_OPEN) +"0");
@ -94,7 +94,7 @@ bool MenuModule::build(Builder *builder, const std::string& tag)
return true; return true;
} }
bool MenuModule::handle_command(const std::string& cmd) bool MenuModule::handle_command(std::string cmd)
{ {
std::lock_guard<std::mutex> lck(this->cmd_mtx); std::lock_guard<std::mutex> lck(this->cmd_mtx);

View file

@ -10,7 +10,7 @@
using namespace modules; using namespace modules;
using namespace mpd; using namespace mpd;
MpdModule::MpdModule(const std::string& name_) MpdModule::MpdModule(std::string name_)
: EventModule(name_), icons(std::make_unique<drawtypes::IconMap>()) : EventModule(name_), icons(std::make_unique<drawtypes::IconMap>())
{ {
// Load configuration values {{{ // Load configuration values {{{
@ -205,7 +205,7 @@ std::string MpdModule::get_format() {
return this->mpd->connected() ? FORMAT_ONLINE : FORMAT_OFFLINE; return this->mpd->connected() ? FORMAT_ONLINE : FORMAT_OFFLINE;
} }
bool MpdModule::build(Builder *builder, const std::string& tag) bool MpdModule::build(Builder *builder, std::string tag)
{ {
auto icon_cmd = [](Builder *builder, std::string cmd, std::unique_ptr<drawtypes::Icon> &icon){ auto icon_cmd = [](Builder *builder, std::string cmd, std::unique_ptr<drawtypes::Icon> &icon){
builder->cmd(Cmd::LEFT_CLICK, cmd); builder->cmd(Cmd::LEFT_CLICK, cmd);
@ -256,7 +256,7 @@ bool MpdModule::build(Builder *builder, const std::string& tag)
return true; return true;
} }
bool MpdModule::handle_command(const std::string& cmd) bool MpdModule::handle_command(std::string cmd)
{ {
if (cmd.length() < 3 || cmd.substr(0, 3) != "mpd") if (cmd.length() < 3 || cmd.substr(0, 3) != "mpd")
return false; return false;

View file

@ -11,7 +11,7 @@ using namespace modules;
// TODO: Add up-/download speed (check how ifconfig read the bytes) // TODO: Add up-/download speed (check how ifconfig read the bytes)
NetworkModule::NetworkModule(const std::string& name_) NetworkModule::NetworkModule(std::string name_)
: TimerModule(name_, 1s), connected(false), conseq_packetloss(false) : TimerModule(name_, 1s), connected(false), conseq_packetloss(false)
{ {
static const auto DEFAULT_FORMAT_CONNECTED = TAG_LABEL_CONNECTED; static const auto DEFAULT_FORMAT_CONNECTED = TAG_LABEL_CONNECTED;
@ -179,7 +179,7 @@ std::string NetworkModule::get_format()
return FORMAT_CONNECTED; return FORMAT_CONNECTED;
} }
bool NetworkModule::build(Builder *builder, const std::string& tag) bool NetworkModule::build(Builder *builder, std::string tag)
{ {
if (tag == TAG_LABEL_CONNECTED) if (tag == TAG_LABEL_CONNECTED)
builder->node(this->label_connected_tokenized); builder->node(this->label_connected_tokenized);

View file

@ -6,7 +6,7 @@
using namespace modules; using namespace modules;
ScriptModule::ScriptModule(const std::string& name_) ScriptModule::ScriptModule(std::string name_)
: TimerModule(name_, 1s), builder(std::make_unique<Builder>(true)), counter(0) : TimerModule(name_, 1s), builder(std::make_unique<Builder>(true)), counter(0)
{ {
// Load configuration values {{{ // Load configuration values {{{
@ -116,7 +116,7 @@ std::string ScriptModule::get_output()
return this->builder->flush(); return this->builder->flush();
} }
bool ScriptModule::build(Builder *builder, const std::string& tag) bool ScriptModule::build(Builder *builder, std::string tag)
{ {
if (tag == TAG_OUTPUT) if (tag == TAG_OUTPUT)
builder->node(string::replace_all(this->output, "\n", "")); builder->node(string::replace_all(this->output, "\n", ""));

View file

@ -5,7 +5,7 @@
using namespace modules; using namespace modules;
TextModule::TextModule(const std::string& name_) : StaticModule(name_) { TextModule::TextModule(std::string name_) : StaticModule(name_) {
this->formatter->add(FORMAT, "", {}); this->formatter->add(FORMAT, "", {});
if (this->formatter->get(FORMAT)->value.empty()) if (this->formatter->get(FORMAT)->value.empty())
throw UndefinedFormat(FORMAT); throw UndefinedFormat(FORMAT);

View file

@ -6,7 +6,7 @@
using namespace modules; using namespace modules;
VolumeModule::VolumeModule(const std::string& name_) : EventModule(name_) VolumeModule::VolumeModule(std::string name_) : EventModule(name_)
{ {
// Load configuration values {{{ // Load configuration values {{{
auto master_mixer = config::get<std::string>(name(), "master_mixer", "Master"); auto master_mixer = config::get<std::string>(name(), "master_mixer", "Master");
@ -182,7 +182,7 @@ std::string VolumeModule::get_output()
return this->builder->flush(); return this->builder->flush();
} }
bool VolumeModule::build(Builder *builder, const std::string& tag) bool VolumeModule::build(Builder *builder, std::string tag)
{ {
if (tag == TAG_BAR_VOLUME) if (tag == TAG_BAR_VOLUME)
builder->node(this->bar_volume, volume); builder->node(this->bar_volume, volume);
@ -198,7 +198,7 @@ bool VolumeModule::build(Builder *builder, const std::string& tag)
return true; return true;
} }
bool VolumeModule::handle_command(const std::string& cmd) bool VolumeModule::handle_command(std::string cmd)
{ {
if (cmd.length() < std::strlen(EVENT_PREFIX)) if (cmd.length() < std::strlen(EVENT_PREFIX))
return false; return false;

View file

@ -111,7 +111,7 @@ bool Registry::wait()
return true; return true;
} }
void Registry::notify(const std::string& module_name) void Registry::notify(std::string module_name)
{ {
log_trace(module_name +" - STAGE "+ std::to_string(this->stage())); log_trace(module_name +" - STAGE "+ std::to_string(this->stage()));
@ -145,12 +145,12 @@ void Registry::notify(const std::string& module_name)
this->wait_cv.notify_one(); this->wait_cv.notify_one();
} }
std::string Registry::get(const std::string& module_name) std::string Registry::get(std::string module_name)
{ {
return (*this->find(module_name)->module)(); return (*this->find(module_name)->module)();
} }
std::unique_ptr<RegistryModuleEntry>& Registry::find(const std::string& module_name) std::unique_ptr<RegistryModuleEntry>& Registry::find(std::string module_name)
{ {
for (auto &&entry : this->modules) for (auto &&entry : this->modules)
if (entry->module->name() == module_name) if (entry->module->name() == module_name)

View file

@ -12,7 +12,7 @@
// Private // Private
void Builder::tag_open(char tag, const std::string& value) { void Builder::tag_open(char tag, std::string value) {
this->append("%{"+ std::string({tag}) + value +"}"); this->append("%{"+ std::string({tag}) + value +"}");
} }
@ -67,7 +67,7 @@ std::string Builder::flush()
return string::replace_all(output, std::string(BUILDER_SPACE_TOKEN), " "); return string::replace_all(output, std::string(BUILDER_SPACE_TOKEN), " ");
} }
void Builder::append(const std::string& text) void Builder::append(std::string text)
{ {
std::string str(text); std::string str(text);
auto len = str.length(); auto len = str.length();
@ -77,7 +77,7 @@ void Builder::append(const std::string& text)
this->output += str; this->output += str;
} }
void Builder::append_module_output(Alignment alignment, const std::string& module_output, bool margin_left, bool margin_right) void Builder::append_module_output(Alignment alignment, std::string module_output, bool margin_left, bool margin_right)
{ {
if (module_output.empty()) return; if (module_output.empty()) return;
@ -102,7 +102,7 @@ void Builder::append_module_output(Alignment alignment, const std::string& modul
this->output += std::string(margin, ' '); this->output += std::string(margin, ' ');
} }
void Builder::node(const std::string& str, bool add_space) void Builder::node(std::string str, bool add_space)
{ {
std::string::size_type n, m; std::string::size_type n, m;
std::string s(str); std::string s(str);
@ -182,7 +182,7 @@ void Builder::node(const std::string& str, bool add_space)
if (add_space) this->space(); if (add_space) this->space();
} }
void Builder::node(const std::string& str, int font_index, bool add_space) void Builder::node(std::string str, int font_index, bool add_space)
{ {
this->font(font_index); this->font(font_index);
this->node(str, add_space); this->node(str, add_space);
@ -317,7 +317,7 @@ void Builder::font_close(bool force)
// Back- and foreground // Back- and foreground
void Builder::background(const std::string& color_) void Builder::background(std::string color_)
{ {
auto color(color_); auto color(color_);
@ -347,7 +347,7 @@ void Builder::background_close(bool force)
this->tag_close('B'); this->tag_close('B');
} }
void Builder::color(const std::string& color_) void Builder::color(std::string color_)
{ {
auto color(color_); auto color(color_);
if (color.length() == 2 || (color.find("#") == 0 && color.length() == 3)) { if (color.length() == 2 || (color.find("#") == 0 && color.length() == 3)) {
@ -367,7 +367,7 @@ void Builder::color(const std::string& color_)
this->tag_open('F', color); this->tag_open('F', color);
} }
void Builder::color_alpha(const std::string& alpha_) void Builder::color_alpha(std::string alpha_)
{ {
auto alpha(alpha_); auto alpha(alpha_);
std::string val = bar_opts().foreground; std::string val = bar_opts().foreground;
@ -394,7 +394,7 @@ void Builder::color_close(bool force)
// Under- and overline // Under- and overline
void Builder::line_color(const std::string& color) void Builder::line_color(std::string color)
{ {
if (color.empty() && this->U > 0) this->line_color_close(true); if (color.empty() && this->U > 0) this->line_color_close(true);
if (color.empty() || color == this->U_value) return; if (color.empty() || color == this->U_value) return;
@ -414,7 +414,7 @@ void Builder::line_color_close(bool force)
this->tag_close('U'); this->tag_close('U');
} }
void Builder::overline(const std::string& color) void Builder::overline(std::string color)
{ {
if (!color.empty()) this->line_color(color); if (!color.empty()) this->line_color(color);
if (this->o > 0) return; if (this->o > 0) return;
@ -431,7 +431,7 @@ void Builder::overline_close(bool force)
this->append("%{-o}"); this->append("%{-o}");
} }
void Builder::underline(const std::string& color) void Builder::underline(std::string color)
{ {
if (!color.empty()) this->line_color(color); if (!color.empty()) this->line_color(color);
if (this->u > 0) return; if (this->u > 0) return;

View file

@ -27,7 +27,7 @@
* std::cout << cmd->readline(); //---> 1 * std::cout << cmd->readline(); //---> 1
* std::cout << cmd->readline() << cmd->readline(); //---> 23 * std::cout << cmd->readline() << cmd->readline(); //---> 23
*/ */
Command::Command(const std::string& cmd, int stdout[2], int stdin[2]) Command::Command(std::string cmd, int stdout[2], int stdin[2])
: cmd(cmd) : cmd(cmd)
{ {
if (stdin != nullptr) { if (stdin != nullptr) {
@ -135,7 +135,7 @@ void Command::tail(std::function<void(std::string)> callback) {
io::tail(this->fd_stdout[PIPE_READ], callback); io::tail(this->fd_stdout[PIPE_READ], callback);
} }
int Command::writeline(const std::string& data) { int Command::writeline(std::string data) {
return io::writeline(this->fd_stdin[PIPE_WRITE], data); return io::writeline(this->fd_stdin[PIPE_WRITE], data);
} }

View file

@ -8,7 +8,7 @@
#include "utils/macros.hpp" #include "utils/macros.hpp"
#include "utils/proc.hpp" #include "utils/proc.hpp"
InotifyWatch::InotifyWatch(const std::string& path, int mask) InotifyWatch::InotifyWatch(std::string path, int mask)
{ {
log_trace("Installing watch at: "+ path); log_trace("Installing watch at: "+ path);

View file

@ -58,7 +58,7 @@ std::string &Store::get_string(std::string& s)
return s; return s;
} }
void Store::set_string(const std::string& s) void Store::set_string(std::string s)
{ {
log_trace("Storing: \""+ s +"\""); log_trace("Storing: \""+ s +"\"");
std::memcpy(this->region.get_address(), s.c_str(), this->region.get_size()); std::memcpy(this->region.get_address(), s.c_str(), this->region.get_size());

View file

@ -12,23 +12,23 @@ namespace cli
std::vector<Option> options; std::vector<Option> options;
std::map<std::string, std::string> values; std::map<std::string, std::string> values;
void add_option(const std::string& opt_short, const std::string& opt_long, const std::string& help) { void add_option(std::string opt_short, std::string opt_long, std::string help) {
add_option(opt_short, opt_long, "", help); add_option(opt_short, opt_long, "", help);
} }
void add_option(const std::string& opt_short, const std::string& opt_long, const std::string& placeholder, const std::string& help, std::vector<std::string> accept) { void add_option(std::string opt_short, std::string opt_long, std::string placeholder, std::string help, std::vector<std::string> accept) {
options.emplace_back(Option(opt_short, opt_long, placeholder, accept, help)); options.emplace_back(Option(opt_short, opt_long, placeholder, accept, help));
} }
bool is_option(char *opt, const std::string& opt_short, const std::string& opt_long) { bool is_option(char *opt, std::string opt_short, std::string opt_long) {
return is_option_short(opt, opt_short) || is_option_long(opt, opt_long); return is_option_short(opt, opt_short) || is_option_long(opt, opt_long);
} }
bool is_option_short(char *opt, const std::string& opt_short) { bool is_option_short(char *opt, std::string opt_short) {
return std::strncmp(opt, opt_short.c_str(), opt_short.length()) == 0; return std::strncmp(opt, opt_short.c_str(), opt_short.length()) == 0;
} }
bool is_option_long(char *opt, const std::string& opt_long) { bool is_option_long(char *opt, std::string opt_long) {
return std::strncmp(opt, opt_long.c_str(), opt_long.length()) == 0; return std::strncmp(opt, opt_long.c_str(), opt_long.length()) == 0;
} }
@ -52,18 +52,18 @@ namespace cli
return value; return value;
} }
bool has_option(const std::string& opt) { bool has_option(std::string opt) {
return values.find(opt) != values.end(); return values.find(opt) != values.end();
} }
std::string get_option_value(const std::string& opt) std::string get_option_value(std::string opt)
{ {
if (has_option(opt)) if (has_option(opt))
return values.find(opt)->second; return values.find(opt)->second;
else return ""; else return "";
} }
bool match_option_value(const std::string& opt, const std::string& val) { bool match_option_value(std::string opt, std::string val) {
return get_option_value(opt) == val; return get_option_value(opt) == val;
} }
@ -86,7 +86,7 @@ namespace cli
} }
} }
void usage(const std::string& usage, bool exit_success) void usage(std::string usage, bool exit_success)
{ {
int longest_n = 0; int longest_n = 0;

View file

@ -8,7 +8,7 @@ namespace config
std::string file_path; std::string file_path;
std::string bar_path; std::string bar_path;
void set_bar_path(const std::string &path) void set_bar_path(std::string path)
{ {
bar_path = path; bar_path = path;
} }
@ -18,7 +18,7 @@ namespace config
return bar_path; return bar_path;
} }
void load(const std::string& path) void load(std::string path)
{ {
if (!io::file::exists(path)) { if (!io::file::exists(path)) {
throw UnexistingFileError("Could not find configuration file \""+ path + "\""); throw UnexistingFileError("Could not find configuration file \""+ path + "\"");
@ -35,7 +35,7 @@ namespace config
file_path = path; file_path = path;
} }
void load(const char *dir, const std::string& path) { void load(const char *dir, std::string path) {
load(std::string(dir != nullptr ? dir : "") +"/"+ path); load(std::string(dir != nullptr ? dir : "") +"/"+ path);
} }
@ -52,7 +52,7 @@ namespace config
return pt; return pt;
} }
std::string build_path(const std::string& section, const std::string& key) { std::string build_path(std::string section, std::string key) {
return section +"."+ key; return section +"."+ key;
} }

View file

@ -18,7 +18,7 @@ namespace io
{ {
namespace socket namespace socket
{ {
int open(const std::string& path) int open(std::string path)
{ {
int fd; int fd;
struct sockaddr_un sock_addr; struct sockaddr_un sock_addr;
@ -39,7 +39,7 @@ namespace io
return fd; return fd;
} }
int send(int fd, const std::string& data, int flags) int send(int fd, std::string data, int flags)
{ {
int bytes = ::send(fd, data.c_str(), data.size()+1, flags); int bytes = ::send(fd, data.c_str(), data.size()+1, flags);
if (bytes == -1) if (bytes == -1)
@ -60,13 +60,13 @@ namespace io
namespace file namespace file
{ {
bool exists(const std::string& fname) bool exists(std::string fname)
{ {
struct stat buffer; struct stat buffer;
return (stat(fname.c_str(), &buffer) == 0); return (stat(fname.c_str(), &buffer) == 0);
} }
std::string get_contents(const std::string& fname) std::string get_contents(std::string fname)
{ {
try { try {
std::ifstream ifs(fname); std::ifstream ifs(fname);
@ -80,7 +80,7 @@ namespace io
} }
} }
bool is_fifo(const std::string& fname) bool is_fifo(std::string fname)
{ {
FILE *fp = fopen(fname.c_str(), "r"); FILE *fp = fopen(fname.c_str(), "r");
int fd = fileno(fp); int fd = fileno(fp);
@ -91,12 +91,12 @@ namespace io
return is_fifo; return is_fifo;
} }
std::size_t write(io::file::FilePtr *fptr, const std::string& data) { std::size_t write(io::file::FilePtr *fptr, std::string data) {
auto buf = data.c_str(); auto buf = data.c_str();
return fwrite(buf, sizeof(char), sizeof(buf), (*fptr)()); return fwrite(buf, sizeof(char), sizeof(buf), (*fptr)());
} }
std::size_t write(const std::string& fpath, const std::string& data) { std::size_t write(std::string fpath, std::string data) {
return io::file::write(std::make_unique<FilePtr>(fpath, "a+").get(), data); return io::file::write(std::make_unique<FilePtr>(fpath, "a+").get(), data);
} }
} }
@ -157,11 +157,11 @@ namespace io
return readline(read_fd, bytes_read); return readline(read_fd, bytes_read);
} }
int write(int write_fd, const std::string& data) { int write(int write_fd, std::string data) {
return ::write(write_fd, data.c_str(), strlen(data.c_str())); return ::write(write_fd, data.c_str(), strlen(data.c_str()));
} }
int writeline(int write_fd, const std::string& data) int writeline(int write_fd, std::string data)
{ {
if (data.length() == 0) return -1; if (data.length() == 0) return -1;
if (data.substr(data.length()-1, 1) != "\n") if (data.substr(data.length()-1, 1) != "\n")

View file

@ -51,7 +51,7 @@ namespace proc
return true; return true;
} }
void exec(const std::string& cmd) void exec(std::string cmd)
{ {
// log_trace(string::replace_all(cmd, "\n", " ")); // log_trace(string::replace_all(cmd, "\n", " "));

View file

@ -4,11 +4,11 @@
namespace string namespace string
{ {
bool compare(const std::string& s1, const std::string& s2) { bool compare(std::string s1, std::string s2) {
return lower(s1) == lower(s2); return lower(s1) == lower(s2);
} }
// std::string upper(const std::string& s) // std::string upper(std::string s)
// { // {
// std::string str(s); // std::string str(s);
// for (auto &c : str) // for (auto &c : str)
@ -16,7 +16,7 @@ namespace string
// return str; // return str;
// } // }
std::string lower(const std::string& s) std::string lower(std::string s)
{ {
std::string str(s); std::string str(s);
for (auto &c : str) for (auto &c : str)
@ -24,7 +24,7 @@ namespace string
return str; return str;
} }
std::string replace(const std::string& haystack, const std::string& needle, const std::string& replacement) std::string replace(std::string haystack, std::string needle, std::string replacement)
{ {
std::string str(haystack); std::string str(haystack);
std::string::size_type pos; std::string::size_type pos;
@ -33,15 +33,15 @@ namespace string
return str; return str;
} }
std::string replace_all(const std::string& haystack, const std::string& needle, const std::string& replacement) { std::string replace_all(std::string haystack, std::string needle, std::string replacement) {
return boost::replace_all_copy(haystack, needle, replacement); return boost::replace_all_copy(haystack, needle, replacement);
} }
std::string squeeze(const std::string& haystack, const char &needle) { std::string squeeze(std::string haystack, const char &needle) {
return replace_all(haystack, {needle, needle}, {needle}); return replace_all(haystack, {needle, needle}, {needle});
} }
// std::string strip(const std::string& haystack, const char &needle) // std::string strip(std::string haystack, const char &needle)
// { // {
// std::string str(haystack); // std::string str(haystack);
// std::string::size_type pos; // std::string::size_type pos;
@ -50,7 +50,7 @@ namespace string
// return str; // return str;
// } // }
std::string strip_trailing_newline(const std::string& haystack) std::string strip_trailing_newline(std::string haystack)
{ {
std::string str(haystack); std::string str(haystack);
if (str[str.length()-1] == '\n') if (str[str.length()-1] == '\n')
@ -58,11 +58,11 @@ namespace string
return str; return str;
} }
std::string trim(const std::string& haystack, const char &needle) { std::string trim(std::string haystack, const char &needle) {
return rtrim(ltrim(haystack, needle), needle); return rtrim(ltrim(haystack, needle), needle);
} }
std::string ltrim(const std::string& haystack, const char &needle) std::string ltrim(std::string haystack, const char &needle)
{ {
std::string str(haystack); std::string str(haystack);
while (str[0] == needle) while (str[0] == needle)
@ -70,7 +70,7 @@ namespace string
return str; return str;
} }
std::string rtrim(const std::string& haystack, const char &needle) std::string rtrim(std::string haystack, const char &needle)
{ {
std::string str(haystack); std::string str(haystack);
while (str[str.length()-1] == needle) while (str[str.length()-1] == needle)
@ -78,7 +78,7 @@ namespace string
return str; return str;
} }
std::string join(const std::vector<std::string> &strs, const std::string& delim) std::string join(const std::vector<std::string> &strs, std::string delim)
{ {
std::string str; std::string str;
for (auto &s : strs) for (auto &s : strs)
@ -86,13 +86,13 @@ namespace string
return str; return str;
} }
std::vector<std::string> split(const std::string& s, const char &delim) std::vector<std::string> split(std::string s, const char &delim)
{ {
std::vector<std::string> vec; std::vector<std::string> vec;
return split_into(s, delim, vec); return split_into(s, delim, vec);
} }
std::vector<std::string> &split_into(const std::string& s, const char &delim, std::vector<std::string> &container) std::vector<std::string> &split_into(std::string s, const char &delim, std::vector<std::string> &container)
{ {
std::string str; std::string str;
std::stringstream buffer(s); std::stringstream buffer(s);
@ -101,7 +101,7 @@ namespace string
return container; return container;
} }
std::size_t find_nth(const std::string& haystack, std::size_t pos, const std::string& needle, std::size_t nth) std::size_t find_nth(std::string haystack, std::size_t pos, std::string needle, std::size_t nth)
{ {
std::size_t found_pos = haystack.find(needle, pos); std::size_t found_pos = haystack.find(needle, pos);
if(0 == nth || std::string::npos == found_pos) return found_pos; if(0 == nth || std::string::npos == found_pos) return found_pos;

View file

@ -59,7 +59,7 @@ namespace xlib
return monitors; return monitors;
} }
// std::unique_ptr<Monitor> get_monitor(const std::string& n_monitorsame) // std::unique_ptr<Monitor> get_monitor(std::string n_monitorsame)
// { // {
// auto monitor = std::make_unique<Monitor>(); // auto monitor = std::make_unique<Monitor>();
// int n_monitors; // int n_monitors;