From 8ba83e91bf8457fd9cf3110538fc278c426c0dc0 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Mon, 6 Jun 2016 08:19:27 -0400 Subject: get rid of using std::* statements in headers --- ponymix.cc | 14 +++++------ pulse.cc | 45 ++++++++++++++++----------------- pulse.h | 84 ++++++++++++++++++++++++++++++-------------------------------- 3 files changed, 69 insertions(+), 74 deletions(-) diff --git a/ponymix.cc b/ponymix.cc index 5f1e98c..1464d9f 100644 --- a/ponymix.cc +++ b/ponymix.cc @@ -88,7 +88,7 @@ static const char* type_to_string(enum DeviceType t) { } static enum DeviceType string_to_devtype_or_die(const char* str) { - static std::map typemap{ + static std::map typemap{ { "sink", DEVTYPE_SINK }, { "source", DEVTYPE_SOURCE }, { "sink-input", DEVTYPE_SINK_INPUT }, @@ -102,7 +102,7 @@ static enum DeviceType string_to_devtype_or_die(const char* str) { } static Device* string_to_device_or_die(PulseClient& ponymix, - string arg, + std::string arg, enum DeviceType type) { Device* device = ponymix.GetDevice(arg, type); if (device == nullptr) errx(1, "no match found for device: %s", arg.c_str()); @@ -400,7 +400,7 @@ static int IsAvailable(PulseClient& ponymix, int, char*[]) { return ponymix.Availability(*device) == Device::AVAILABLE_YES; } -static bool endswith(const string& subject, const string& predicate) { +static bool endswith(const std::string& subject, const std::string& predicate) { if (subject.size() < predicate.size()) { return false; } @@ -409,9 +409,9 @@ static bool endswith(const string& subject, const string& predicate) { predicate.size(), predicate) == 0; } -static const std::pair& string_to_command( +static const std::pair& string_to_command( const char* str) { - static std::map actionmap{ + static std::map actionmap{ // command name function arg min arg max { "defaults", { ShowDefaults, { 0, 0 } } }, { "list", { List, { 0, 0 } } }, @@ -460,7 +460,7 @@ static const std::pair& string_to_command( } if (iter != match) { auto i = match; - string cand = i->first; + std::string cand = i->first; i++; while (i->first.find(str) == 0) { cand += ", " + i->first; @@ -558,7 +558,7 @@ static int CommandDispatch(PulseClient& ponymix, int argc, char *argv[]) { error_wrong_args(cmd.second, cmd.first.c_str()); } - if (endswith(cmd.first, string("-short"))) { + if (endswith(cmd.first, std::string("-short"))) { opt_short = true; } diff --git a/pulse.cc b/pulse.cc index fc450ae..ab3f3cf 100644 --- a/pulse.cc +++ b/pulse.cc @@ -8,7 +8,6 @@ #include // C++ -#include #include #include @@ -39,7 +38,7 @@ static void card_info_cb(pa_context* context, } if (!eol) { - vector* cards = static_cast*>(raw); + std::vector* cards = static_cast*>(raw); cards->push_back(info); } } @@ -56,7 +55,7 @@ static void device_info_cb(pa_context* context, } if (!eol) { - vector* devices_ = static_cast*>(raw); + std::vector* devices_ = static_cast*>(raw); devices_->push_back(info); } } @@ -91,7 +90,7 @@ static int xstrtol(const char *str, long *out) { } // anonymous namespace -PulseClient::PulseClient(string client_name) : +PulseClient::PulseClient(std::string client_name) : client_name_(client_name), volume_range_(0, 150), balance_range_(-100, 100), @@ -145,7 +144,7 @@ Card* PulseClient::GetCard(const uint32_t index) { return nullptr; } -Card* PulseClient::GetCard(const string& name) { +Card* PulseClient::GetCard(const std::string& name) { long val; if (xstrtol(name.c_str(), &val) == 0) { return GetCard(val); @@ -161,7 +160,7 @@ Card* PulseClient::GetCard(const Device& device) { return nullptr; } -Device* PulseClient::get_device(vector& devices, +Device* PulseClient::get_device(std::vector& devices, const uint32_t index) { for (Device& device : devices) { if (device.index_ == index) return &device; @@ -169,7 +168,7 @@ Device* PulseClient::get_device(vector& devices, return nullptr; } -Device* PulseClient::get_device(vector& devices, const string& name) { +Device* PulseClient::get_device(std::vector& devices, const std::string& name) { long val; if (xstrtol(name.c_str(), &val) == 0) { return get_device(devices, val); @@ -193,7 +192,7 @@ Device* PulseClient::GetDevice(const uint32_t index, enum DeviceType type) { throw unreachable(); } -Device* PulseClient::GetDevice(const string& name, enum DeviceType type) { +Device* PulseClient::GetDevice(const std::string& name, enum DeviceType type) { switch (type) { case DEVTYPE_SINK: return GetSink(name); @@ -208,7 +207,7 @@ Device* PulseClient::GetDevice(const string& name, enum DeviceType type) { throw unreachable(); } -const vector& PulseClient::GetDevices(enum DeviceType type) const { +const std::vector& PulseClient::GetDevices(enum DeviceType type) const { switch (type) { case DEVTYPE_SINK: return GetSinks(); @@ -227,7 +226,7 @@ Device* PulseClient::GetSink(const uint32_t index) { return get_device(sinks_, index); } -Device* PulseClient::GetSink(const string& name) { +Device* PulseClient::GetSink(const std::string& name) { return get_device(sinks_, name); } @@ -235,7 +234,7 @@ Device* PulseClient::GetSource(const uint32_t index) { return get_device(sources_, index); } -Device* PulseClient::GetSource(const string& name) { +Device* PulseClient::GetSource(const std::string& name) { return get_device(sources_, name); } @@ -243,7 +242,7 @@ Device* PulseClient::GetSinkInput(const uint32_t index) { return get_device(sink_inputs_, index); } -Device* PulseClient::GetSinkInput(const string& name) { +Device* PulseClient::GetSinkInput(const std::string& name) { return get_device(sink_inputs_, name); } @@ -251,7 +250,7 @@ Device* PulseClient::GetSourceOutput(const uint32_t index) { return get_device(source_outputs_, index); } -Device* PulseClient::GetSourceOutput(const string& name) { +Device* PulseClient::GetSourceOutput(const std::string& name) { return get_device(source_outputs_, name); } @@ -263,11 +262,11 @@ void PulseClient::mainloop_iterate(pa_operation* op) { } template -T* PulseClient::find_fuzzy(vector& haystack, const string& needle) { - vector res; +T* PulseClient::find_fuzzy(std::vector& haystack, const std::string& needle) { + std::vector res; for (T& item : haystack) { - if (item.name_.find(needle) != string::npos) res.push_back(&item); + if (item.name_.find(needle) != std::string::npos) res.push_back(&item); } switch (res.size()) { @@ -283,7 +282,7 @@ T* PulseClient::find_fuzzy(vector& haystack, const string& needle) { } void PulseClient::populate_cards() { - vector cards; + std::vector cards; pa_operation* op = pa_context_get_card_info_list(context_, card_info_cb, static_cast(&cards)); @@ -303,13 +302,13 @@ void PulseClient::populate_server_info() { } void PulseClient::populate_sinks() { - vector sinks; + std::vector sinks; pa_operation* op = pa_context_get_sink_info_list( context_, device_info_cb, static_cast(&sinks)); mainloop_iterate(op); pa_operation_unref(op); - vector sink_inputs; + std::vector sink_inputs; op = pa_context_get_sink_input_info_list( context_, device_info_cb, static_cast(&sink_inputs)); mainloop_iterate(op); @@ -321,13 +320,13 @@ void PulseClient::populate_sinks() { } void PulseClient::populate_sources() { - vector sources; + std::vector sources; pa_operation* op = pa_context_get_source_info_list( context_, device_info_cb, static_cast(&sources)); mainloop_iterate(op); pa_operation_unref(op); - vector source_outputs; + std::vector source_outputs; op = pa_context_get_source_output_info_list( context_, device_info_cb, static_cast(&source_outputs)); mainloop_iterate(op); @@ -441,7 +440,7 @@ int PulseClient::GetBalance(const Device& device) const { return device.Balance(); } -bool PulseClient::SetProfile(Card& card, const string& profile) { +bool PulseClient::SetProfile(Card& card, const std::string& profile) { int success; pa_operation* op = pa_context_set_card_profile_by_index(context_, @@ -537,7 +536,7 @@ bool PulseClient::SetDefault(Device& device) { } void PulseClient::remove_device(Device& device) { - vector* devlist; + std::vector* devlist; switch (device.type_) { case DEVTYPE_SINK: diff --git a/pulse.h b/pulse.h index a825d62..9f2d447 100644 --- a/pulse.h +++ b/pulse.h @@ -14,10 +14,6 @@ // external #include -using std::string; -using std::vector; -using std::unique_ptr; - enum DeviceType { DEVTYPE_SINK, DEVTYPE_SOURCE, @@ -31,8 +27,8 @@ struct Profile { desc(info.description) { } - string name; - string desc; + std::string name; + std::string desc; }; struct Operations { @@ -61,8 +57,8 @@ class Device { Device(const pa_source_output_info* info); uint32_t Index() const { return index_; } - const string& Name() const { return name_; } - const string& Desc() const { return desc_; } + const std::string& Name() const { return name_; } + const std::string& Desc() const { return desc_; } int Volume() const { return volume_percent_; } int Balance() const { return balance_; } bool Muted() const { return mute_; } @@ -75,8 +71,8 @@ class Device { enum DeviceType type_; uint32_t index_; - string name_; - string desc_; + std::string name_; + std::string desc_; pa_cvolume volume_; int volume_percent_; pa_channel_map channels_; @@ -91,30 +87,30 @@ class Card { public: Card(const pa_card_info* info); - const string& Name() const { return name_; } + const std::string& Name() const { return name_; } uint32_t Index() const { return index_; } - const string& Driver() const { return driver_; } + const std::string& Driver() const { return driver_; } - const vector& Profiles() const { return profiles_; } + const std::vector& Profiles() const { return profiles_; } const Profile& ActiveProfile() const { return active_profile_; } private: friend class PulseClient; uint32_t index_; - string name_; + std::string name_; uint32_t owner_module_; - string driver_; - vector profiles_; + std::string driver_; + std::vector profiles_; Profile active_profile_; }; struct ServerInfo { - string sink; - string source; - string empty = ""; + std::string sink; + std::string source; + std::string empty = ""; - const string& GetDefault(enum DeviceType type) { + const std::string& GetDefault(enum DeviceType type) { switch (type) { case DEVTYPE_SINK: return sink; @@ -146,7 +142,7 @@ struct Range { class PulseClient { public: - PulseClient(string client_name); + PulseClient(std::string client_name); ~PulseClient(); // Populates all known devices and cards. Any currently known @@ -155,35 +151,35 @@ class PulseClient { // Get a device by index or name and type, or all devices by type. Device* GetDevice(const uint32_t index, enum DeviceType type); - Device* GetDevice(const string& name, enum DeviceType type); - const vector& GetDevices(enum DeviceType type) const; + Device* GetDevice(const std::string& name, enum DeviceType type); + const std::vector& GetDevices(enum DeviceType type) const; // Get a sink by index or name, or all sinks. Device* GetSink(const uint32_t index); - Device* GetSink(const string& name); - const vector& GetSinks() const { return sinks_; } + Device* GetSink(const std::string& name); + const std::vector& GetSinks() const { return sinks_; } // Get a source by index or name, or all sources. Device* GetSource(const uint32_t index); - Device* GetSource(const string& name); - const vector& GetSources() const { return sources_; } + Device* GetSource(const std::string& name); + const std::vector& GetSources() const { return sources_; } // Get a sink input by index or name, or all sink inputs. Device* GetSinkInput(const uint32_t name); - Device* GetSinkInput(const string& name); - const vector& GetSinkInputs() const { return sink_inputs_; } + Device* GetSinkInput(const std::string& name); + const std::vector& GetSinkInputs() const { return sink_inputs_; } // Get a source output by index or name, or all source outputs. Device* GetSourceOutput(const uint32_t name); - Device* GetSourceOutput(const string& name); - const vector& GetSourceOutputs() const { return source_outputs_; } + Device* GetSourceOutput(const std::string& name); + const std::vector& GetSourceOutputs() const { return source_outputs_; } // Get a card by index or name, all cards, or get the card which // a sink is attached to. Card* GetCard(const uint32_t index); - Card* GetCard(const string& name); + Card* GetCard(const std::string& name); Card* GetCard(const Device& device); - const vector& GetCards() const { return cards_; } + const std::vector& GetCards() const { return cards_; } // Get or set the volume of a device. int GetVolume(const Device& device) const; @@ -210,7 +206,7 @@ class PulseClient { } // Set the profile for a card by name. - bool SetProfile(Card& card, const string& profile); + bool SetProfile(Card& card, const std::string& profile); // Move a given source output or sink input to the destination. bool Move(Device& source, Device& dest); @@ -236,30 +232,30 @@ class PulseClient { private: void mainloop_iterate(pa_operation* op); - template T* find_fuzzy(vector& haystack, const string& needle); + template T* find_fuzzy(std::vector& haystack, const std::string& needle); void populate_server_info(); void populate_cards(); void populate_sinks(); void populate_sources(); - Device* get_device(vector& devices, const uint32_t index); - Device* get_device(vector& devices, const string& name); + Device* get_device(std::vector& devices, const uint32_t index); + Device* get_device(std::vector& devices, const std::string& name); void remove_device(Device& device); - string client_name_; + std::string client_name_; pa_context* context_; pa_mainloop* mainloop_; - vector sinks_; - vector sources_; - vector sink_inputs_; - vector source_outputs_; - vector cards_; + std::vector sinks_; + std::vector sources_; + std::vector sink_inputs_; + std::vector source_outputs_; + std::vector cards_; ServerInfo defaults_; Range volume_range_; Range balance_range_; - unique_ptr notifier_; + std::unique_ptr notifier_; }; class unreachable : public std::runtime_error { -- cgit v1.2.3