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;
int offset;
Font(const std::string& id, int offset)
Font(std::string id, int 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;
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(width, "<fill><indicator><empty>", lazy_builder_closing){}
@ -38,5 +38,5 @@ namespace drawtypes
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
{
Icon(const std::string& icon, int font = 0)
Icon(std::string icon, int font = 0)
: 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){}
std::unique_ptr<Icon> clone();
@ -24,15 +24,15 @@ namespace drawtypes
std::map<std::string, std::unique_ptr<Icon>> icons;
public:
void add(const std::string& id, std::unique_ptr<Icon> &&icon);
std::unique_ptr<Icon> &get(const std::string& id, const std::string& fallback_id = "");
bool has(const std::string& id);
void add(std::string id, std::unique_ptr<Icon> &&icon);
std::unique_ptr<Icon> &get(std::string id, std::string fallback_id = "");
bool has(std::string id);
operator bool() {
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_optional_config_icon(const std::string& module_name, const std::string& icon_name = "icon", 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(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;
int font = 0, padding = 0, margin = 0;
Label(const std::string& text, int font)
Label(std::string text, int 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){}
operator bool() {
@ -21,10 +21,10 @@ namespace drawtypes
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);
};
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_optional_config_label(const std::string& module_name, const std::string& label_name = "label", 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(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 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
{
public:
explicit Exception(const std::string& msg) : ::Exception("[Alsa] "+ msg){}
explicit Exception(std::string msg) : ::Exception("[Alsa] "+ msg){}
};
class ControlInterfaceError : public Exception
{
public:
ControlInterfaceError(int code, const std::string& msg)
ControlInterfaceError(int code, std::string msg)
: Exception(msg +" ["+ std::to_string(code) +"]") {}
};
@ -71,7 +71,7 @@ namespace alsa
snd_mixer_elem_t *mixer_element = nullptr;
public:
explicit Mixer(const std::string& mixer_control_name);
explicit Mixer(std::string mixer_control_name);
~Mixer();
Mixer(const Mixer &) = delete;
Mixer &operator=(const Mixer &) = delete;
@ -86,7 +86,7 @@ namespace alsa
bool is_muted();
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
{
public:
Exception(const std::string& msg, bool clearable)
Exception(std::string msg, bool clearable)
: ::Exception(msg + (clearable ? " (clearable)" : " (not clearable)")){}
};
class ClientError : public Exception
{
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){}
};
class ServerError : public Exception
{
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){}
};
@ -140,9 +140,9 @@ namespace mpd
void idle();
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_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; }
std::unique_ptr<Status> get_status();

View File

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

View File

@ -7,4 +7,4 @@ DefineBaseException(ApplicationError);
void register_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;
public:
explicit BacklightModule(const std::string& name);
explicit BacklightModule(std::string name);
bool on_event(InotifyEvent *event);
bool build(Builder *builder, const std::string& tag);
bool build(Builder *builder, std::string tag);
void idle() const
{

View File

@ -42,7 +42,6 @@ class ModuleFormatter
{
std::string value;
std::vector<std::string> tags;
std::string fg, bg, ul, ol;
int spacing, padding, margin, offset;
@ -78,7 +77,7 @@ class ModuleFormatter
std::map<std::string, std::unique_ptr<Format>> formats;
public:
explicit ModuleFormatter(const std::string& module_name)
explicit ModuleFormatter(std::string 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 = {})
@ -136,8 +135,8 @@ class ModuleFormatter
namespace modules
{
void broadcast_module_update(const std::string& module_name);
std::string get_tag_name(const std::string& tag);
void broadcast_module_update(std::string module_name);
std::string get_tag_name(std::string tag);
struct ModuleInterface
{
@ -152,7 +151,7 @@ namespace modules
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>
@ -219,7 +218,7 @@ namespace modules
return this->cache();
}
bool handle_command(const std::string& cmd) {
bool handle_command(std::string cmd) {
return CastModule(ModuleImpl)->handle_command(cmd);
}
@ -309,7 +308,7 @@ namespace modules
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;
}
@ -336,7 +335,7 @@ namespace modules
public:
template<typename I>
TimerModule(const std::string& name, I const &interval)
TimerModule(std::string name, I const &interval)
: Module<ModuleImpl>(name), interval(interval) {}
void start()

View File

@ -49,12 +49,12 @@ namespace modules
void subthread_routine();
public:
explicit BatteryModule(const std::string& name);
explicit BatteryModule(std::string name);
void start();
bool on_event(InotifyEvent *event);
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;
public:
BspwmModule(const std::string& name, const std::string& monitor);
BspwmModule(std::string name, std::string monitor);
~BspwmModule() { close(this->socket_fd); }
void start();
bool has_event();
bool update();
bool build(Builder *builder, const std::string& tag);
bool handle_command(const std::string& cmd);
bool build(Builder *builder, std::string tag);
bool handle_command(std::string cmd);
};
}

View File

@ -11,9 +11,9 @@ namespace modules
concurrency::Atomic<int> counter;
public:
explicit CounterModule(const std::string& name);
explicit CounterModule(std::string name);
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);
public:
explicit CpuModule(const std::string& name);
explicit CpuModule(std::string name);
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;
public:
explicit DateModule(const std::string& name);
explicit DateModule(std::string name);
bool update();
bool build(Builder *builder, const std::string& tag);
bool build(Builder *builder, std::string tag);
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;
public:
i3Module(const std::string& name, const std::string& monitor);
i3Module(std::string name, std::string monitor);
void start();
void stop();
bool has_event();
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;
public:
explicit MemoryModule(const std::string& name);
explicit MemoryModule(std::string name);
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;
public:
explicit MenuModule(const std::string& name);
explicit MenuModule(std::string name);
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;
public:
explicit MpdModule(const std::string& name);
explicit MpdModule(std::string name);
~MpdModule();
void start();
bool has_event();
bool update();
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();
public:
explicit NetworkModule(const std::string& name);
explicit NetworkModule(std::string name);
void start();
bool update();
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:
public:
explicit ScriptModule(const std::string& name);
explicit ScriptModule(std::string name);
void start();
bool update();
bool build(Builder *builder, const std::string& tag);
bool build(Builder *builder, std::string tag);
std::string get_output();
};
}

View File

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

View File

@ -43,16 +43,15 @@ namespace modules
concurrency::Atomic<bool> has_changed;
public:
explicit VolumeModule(const std::string& name);
~VolumeModule();
explicit VolumeModule(std::string name);
bool has_event();
bool update();
std::string get_format();
bool build(Builder *builder, const std::string& tag);
bool build(Builder *builder, std::string tag);
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 unload();
bool wait();
void notify(const std::string& module_name);
std::string get(const std::string& module_name);
std::unique_ptr<RegistryModuleEntry>& find(const std::string& module_name);
void notify(std::string module_name);
std::string get(std::string module_name);
std::unique_ptr<RegistryModuleEntry>& find(std::string module_name);
};
std::shared_ptr<Registry> &get_registry();

View File

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

View File

@ -22,14 +22,14 @@ class Command
int fork_status;
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();
int exec(bool wait_for_completion = true);
int wait();
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_stdin(int);

View File

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

View File

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

View File

@ -16,23 +16,23 @@ namespace cli
std::string help;
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){}
};
void add_option(const std::string& opt_short, const std::string& opt_long, const 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 help);
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_short(char *opt, const std::string& opt_short);
bool is_option_long(char *opt, const std::string& opt_long);
bool is_option(char *opt, std::string opt_short, std::string opt_long);
bool is_option_short(char *opt, std::string opt_short);
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 = {});
bool has_option(const std::string& opt);
std::string get_option_value(const std::string& opt);
bool match_option_value(const std::string& opt, const std::string& val);
bool has_option(std::string opt);
std::string get_option_value(std::string opt);
bool match_option_value(std::string opt, std::string val);
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;
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(const char *dir, const std::string& path);
void load(std::string path);
void load(const char *dir, std::string path);
// void reload();
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();
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);
@ -63,7 +63,7 @@ namespace config
}
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);
@ -78,7 +78,7 @@ namespace config
}
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);
@ -89,7 +89,7 @@ namespace config
}
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);
@ -108,7 +108,7 @@ namespace config
}
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);

View File

@ -13,8 +13,8 @@ namespace io
{
namespace socket
{
int open(const std::string& path);
int send(int fd, const std::string& data, int flags = 0);
int open(std::string path);
int send(int fd, std::string data, 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 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))
{
this->fptr = fopen(this->path.c_str(), this->mode.c_str());
@ -49,11 +49,11 @@ namespace io
}
};
bool exists(const std::string& fname);
std::string get_contents(const std::string& fname);
bool is_fifo(const std::string& fname);
std::size_t write(FilePtr *fptr, const std::string& data);
std::size_t write(const std::string& fpath, const std::string& data);
bool exists(std::string fname);
std::string get_contents(std::string fname);
bool is_fifo(std::string fname);
std::size_t write(FilePtr *fptr, std::string data);
std::size_t write(std::string fpath, std::string data);
}
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 write(int write_fd, const std::string& data);
int writeline(int write_fd, const std::string& data);
int write(int write_fd, 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, int writeback_fd);

View File

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

View File

@ -5,27 +5,27 @@
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 lower(const std::string& s);
// std::string upper(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_all(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(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_trailing_newline(const std::string& s);
// std::string strip(std::string haystack, const char &needle);
std::string strip_trailing_newline(std::string s);
std::string trim(const std::string& haystack, const char &needle);
std::string ltrim(const std::string& haystack, const char &needle);
std::string rtrim(const std::string& haystack, const char &needle);
std::string trim(std::string haystack, const char &needle);
std::string ltrim(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_into(const std::string& s, const char &delim, std::vector<std::string> &elems);
std::vector<std::string> split(std::string s, const char &delim);
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();
}

View File

@ -7,7 +7,7 @@
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::string> frames;

View File

@ -7,7 +7,7 @@
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;
@ -28,7 +28,7 @@ namespace drawtypes
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)
{
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) };
}
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);
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);
}
// 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)));
}
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);
if (icon == this->icons.end())
@ -34,7 +34,7 @@ namespace drawtypes
return icon->second;
}
bool IconMap::has(const std::string& id) {
bool IconMap::has(std::string id) {
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) };
}
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);
}
@ -21,7 +21,7 @@ namespace drawtypes
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;
@ -40,7 +40,7 @@ namespace drawtypes
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);
}
}

View File

@ -4,7 +4,7 @@
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::string> icons;

View File

@ -98,7 +98,7 @@ void EventLoop::wait()
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.emplace_back(module_name);

View File

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

View File

@ -20,14 +20,14 @@
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");
}
// Network
Network::Network(const std::string& interface)
Network::Network(std::string interface)
: interface(interface)
{
if (if_nametoindex(this->interface.c_str()) == 0)
@ -108,7 +108,7 @@ std::string Network::get_ip()
// WiredNetwork
WiredNetwork::WiredNetwork(const std::string& interface) : Network(interface)
WiredNetwork::WiredNetwork(std::string interface) : Network(interface)
{
struct ethtool_cmd e;
@ -127,7 +127,7 @@ std::string WiredNetwork::get_link_speed() {
// 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());
}

View File

@ -38,7 +38,7 @@ void unregister_pid(pid_t pid) {
std::lock_guard<std::mutex> lck(pid_mtx);
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);
}
@ -191,7 +191,8 @@ int main(int argc, char **argv)
if (eventloop)
eventloop->cleanup();
while (proc::wait_for_completion_nohang() > 0);
while (proc::wait_for_completion_nohang() > 0)
;
log_trace("Reached end of application");

View File

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

View File

@ -6,12 +6,13 @@
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);
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);
}
}

View File

@ -17,7 +17,7 @@ const int modules::BatteryModule::STATE_CHARGING;
const int modules::BatteryModule::STATE_DISCHARGING;
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->adapter = config::get<std::string>(name(), "adapter", "ADP1");
@ -179,7 +179,7 @@ std::string BatteryModule::get_format()
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)
builder->node(this->animation_charging);

View File

@ -17,7 +17,7 @@ using namespace Bspwm;
#define DEFAULT_WS_ICON "workspace_icon-default"
#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)
{
this->formatter->add(DEFAULT_FORMAT, TAG_LABEL_STATE, { TAG_LABEL_STATE }, { TAG_LABEL_MODE });
@ -193,7 +193,7 @@ bool BspwmModule::update()
return true;
}
bool BspwmModule::build(Builder *builder, const std::string& tag)
bool BspwmModule::build(Builder *builder, std::string tag)
{
if (tag != TAG_LABEL_STATE)
return false;
@ -218,7 +218,7 @@ bool BspwmModule::build(Builder *builder, const std::string& tag)
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))
return false;

View File

@ -6,7 +6,7 @@
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>(
config::get<float>(name(), "interval", 1));
@ -22,7 +22,7 @@ bool CounterModule::update()
return true;
}
bool CounterModule::build(Builder *builder, const std::string& tag)
bool CounterModule::build(Builder *builder, std::string tag)
{
if (tag == TAG_COUNTER) {
builder->node(std::to_string(this->counter()));

View File

@ -7,7 +7,7 @@
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>(
config::get<float>(name(), "interval", 1));
@ -60,7 +60,7 @@ bool CpuModule::update()
return true;
}
bool CpuModule::build(Builder *builder, const std::string& tag)
bool CpuModule::build(Builder *builder, std::string tag)
{
if (tag == TAG_LABEL)
builder->node(this->label_tokenized);

View File

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

View File

@ -22,7 +22,7 @@ using namespace modules;
// TODO: Needs more testing
// 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 {
this->ipc = std::make_unique<i3ipc::connection>();
@ -152,7 +152,7 @@ bool i3Module::update()
return true;
}
bool i3Module::build(Builder *builder, const std::string& tag)
bool i3Module::build(Builder *builder, std::string tag)
{
if (tag != TAG_LABEL_STATE)
return false;
@ -166,7 +166,7 @@ bool i3Module::build(Builder *builder, const std::string& tag)
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))
return false;

View File

@ -5,7 +5,7 @@
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>(
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_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) {
std::stringstream ss;
ss.precision(2);
@ -83,7 +83,7 @@ bool MemoryModule::update()
return true;
}
bool MemoryModule::build(Builder *builder, const std::string& tag)
bool MemoryModule::build(Builder *builder, std::string tag)
{
if (tag == TAG_BAR_USED)
builder->node(this->bar_used, this->percentage_used);

View File

@ -5,7 +5,7 @@
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);
@ -59,7 +59,7 @@ std::string MenuModule::get_output()
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) {
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;
}
bool MenuModule::handle_command(const std::string& cmd)
bool MenuModule::handle_command(std::string cmd)
{
std::lock_guard<std::mutex> lck(this->cmd_mtx);

View File

@ -10,7 +10,7 @@
using namespace modules;
using namespace mpd;
MpdModule::MpdModule(const std::string& name_)
MpdModule::MpdModule(std::string name_)
: EventModule(name_), icons(std::make_unique<drawtypes::IconMap>())
{
// Load configuration values {{{
@ -205,7 +205,7 @@ std::string MpdModule::get_format() {
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){
builder->cmd(Cmd::LEFT_CLICK, cmd);
@ -256,7 +256,7 @@ bool MpdModule::build(Builder *builder, const std::string& tag)
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")
return false;

View File

@ -11,7 +11,7 @@ using namespace modules;
// 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)
{
static const auto DEFAULT_FORMAT_CONNECTED = TAG_LABEL_CONNECTED;
@ -179,7 +179,7 @@ std::string NetworkModule::get_format()
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)
builder->node(this->label_connected_tokenized);

View File

@ -6,7 +6,7 @@
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)
{
// Load configuration values {{{
@ -116,7 +116,7 @@ std::string ScriptModule::get_output()
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)
builder->node(string::replace_all(this->output, "\n", ""));

View File

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

View File

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

View File

@ -111,7 +111,7 @@ bool Registry::wait()
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()));
@ -145,12 +145,12 @@ void Registry::notify(const std::string& module_name)
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)();
}
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)
if (entry->module->name() == module_name)

View File

@ -12,7 +12,7 @@
// 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 +"}");
}
@ -67,7 +67,7 @@ std::string Builder::flush()
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);
auto len = str.length();
@ -77,7 +77,7 @@ void Builder::append(const std::string& text)
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;
@ -102,7 +102,7 @@ void Builder::append_module_output(Alignment alignment, const std::string& modul
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 s(str);
@ -182,7 +182,7 @@ void Builder::node(const std::string& str, bool add_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->node(str, add_space);
@ -317,7 +317,7 @@ void Builder::font_close(bool force)
// Back- and foreground
void Builder::background(const std::string& color_)
void Builder::background(std::string color_)
{
auto color(color_);
@ -347,7 +347,7 @@ void Builder::background_close(bool force)
this->tag_close('B');
}
void Builder::color(const std::string& color_)
void Builder::color(std::string color_)
{
auto color(color_);
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);
}
void Builder::color_alpha(const std::string& alpha_)
void Builder::color_alpha(std::string alpha_)
{
auto alpha(alpha_);
std::string val = bar_opts().foreground;
@ -394,7 +394,7 @@ void Builder::color_close(bool force)
// 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() || color == this->U_value) return;
@ -414,7 +414,7 @@ void Builder::line_color_close(bool force)
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 (this->o > 0) return;
@ -431,7 +431,7 @@ void Builder::overline_close(bool force)
this->append("%{-o}");
}
void Builder::underline(const std::string& color)
void Builder::underline(std::string color)
{
if (!color.empty()) this->line_color(color);
if (this->u > 0) return;

View File

@ -27,7 +27,7 @@
* std::cout << cmd->readline(); //---> 1
* 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)
{
if (stdin != nullptr) {
@ -135,7 +135,7 @@ void Command::tail(std::function<void(std::string)> 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);
}

View File

@ -8,7 +8,7 @@
#include "utils/macros.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);

View File

@ -58,7 +58,7 @@ std::string &Store::get_string(std::string& s)
return s;
}
void Store::set_string(const std::string& s)
void Store::set_string(std::string s)
{
log_trace("Storing: \""+ s +"\"");
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::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);
}
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));
}
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);
}
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;
}
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;
}
@ -52,18 +52,18 @@ namespace cli
return value;
}
bool has_option(const std::string& opt) {
bool has_option(std::string opt) {
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))
return values.find(opt)->second;
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;
}
@ -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;

View File

@ -8,7 +8,7 @@ namespace config
std::string file_path;
std::string bar_path;
void set_bar_path(const std::string &path)
void set_bar_path(std::string path)
{
bar_path = path;
}
@ -18,7 +18,7 @@ namespace config
return bar_path;
}
void load(const std::string& path)
void load(std::string path)
{
if (!io::file::exists(path)) {
throw UnexistingFileError("Could not find configuration file \""+ path + "\"");
@ -35,7 +35,7 @@ namespace config
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);
}
@ -52,7 +52,7 @@ namespace config
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;
}

View File

@ -18,7 +18,7 @@ namespace io
{
namespace socket
{
int open(const std::string& path)
int open(std::string path)
{
int fd;
struct sockaddr_un sock_addr;
@ -39,7 +39,7 @@ namespace io
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);
if (bytes == -1)
@ -60,13 +60,13 @@ namespace io
namespace file
{
bool exists(const std::string& fname)
bool exists(std::string fname)
{
struct stat buffer;
return (stat(fname.c_str(), &buffer) == 0);
}
std::string get_contents(const std::string& fname)
std::string get_contents(std::string fname)
{
try {
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");
int fd = fileno(fp);
@ -91,12 +91,12 @@ namespace io
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();
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);
}
}
@ -157,11 +157,11 @@ namespace io
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()));
}
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.substr(data.length()-1, 1) != "\n")

View File

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

View File

@ -4,11 +4,11 @@
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);
}
// std::string upper(const std::string& s)
// std::string upper(std::string s)
// {
// std::string str(s);
// for (auto &c : str)
@ -16,7 +16,7 @@ namespace string
// return str;
// }
std::string lower(const std::string& s)
std::string lower(std::string s)
{
std::string str(s);
for (auto &c : str)
@ -24,7 +24,7 @@ namespace string
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::size_type pos;
@ -33,15 +33,15 @@ namespace string
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);
}
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});
}
// 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::size_type pos;
@ -50,7 +50,7 @@ namespace string
// return str;
// }
std::string strip_trailing_newline(const std::string& haystack)
std::string strip_trailing_newline(std::string haystack)
{
std::string str(haystack);
if (str[str.length()-1] == '\n')
@ -58,11 +58,11 @@ namespace string
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);
}
std::string ltrim(const std::string& haystack, const char &needle)
std::string ltrim(std::string haystack, const char &needle)
{
std::string str(haystack);
while (str[0] == needle)
@ -70,7 +70,7 @@ namespace string
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);
while (str[str.length()-1] == needle)
@ -78,7 +78,7 @@ namespace string
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;
for (auto &s : strs)
@ -86,13 +86,13 @@ namespace string
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;
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::stringstream buffer(s);
@ -101,7 +101,7 @@ namespace string
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);
if(0 == nth || std::string::npos == found_pos) return found_pos;

View File

@ -59,7 +59,7 @@ namespace xlib
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>();
// int n_monitors;