Skip to content

Commit 375e3d0

Browse files
committed
Core (lv-tool): Use std::string_view for string arguments.
1 parent 4fa0bc4 commit 375e3d0

9 files changed

Lines changed: 37 additions & 27 deletions

File tree

libvisual/tools/lv-tool/display/display.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include <stdexcept>
2929
#include <string>
3030

31+
using namespace std::string_literals;
32+
3133
class Display::Impl
3234
{
3335
public:
@@ -42,13 +44,14 @@ class Display::Impl
4244
{}
4345
};
4446

45-
Display::Display (std::string const& driver_name)
47+
Display::Display (std::string_view driver_name)
4648
: m_impl (new Impl)
4749
{
4850
m_impl->driver.reset (DisplayDriverFactory::instance().make (driver_name, *this));
4951

5052
if (!m_impl->driver) {
51-
throw std::runtime_error ("Failed to load display driver '" + driver_name + "'. Valid driver set? (\"--driver\" parameter)");
53+
std::string const driver_name_str {driver_name};
54+
throw std::runtime_error {"Failed to load display driver '"s + driver_name_str + "'. Valid driver set? (\"--driver\" parameter)"};
5255
}
5356
}
5457

@@ -80,9 +83,9 @@ void Display::close ()
8083
m_impl->driver->close ();
8184
}
8285

83-
void Display::set_title(std::string const& title)
86+
void Display::set_title(std::string_view title)
8487
{
85-
m_impl->driver->set_title(title);
88+
m_impl->driver->set_title (title);
8689
}
8790

8891
void Display::lock ()

libvisual/tools/lv-tool/display/display.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727

2828
#include <libvisual/libvisual.h>
2929
#include <memory>
30-
#include <string>
30+
#include <string_view>
3131

3232
class DisplayDriver;
3333

3434
class Display final
3535
{
3636
public:
3737

38-
explicit Display (std::string const& driver_name);
38+
explicit Display (std::string_view driver_name);
3939

4040
Display (Display const&) = delete;
4141

@@ -61,7 +61,7 @@ class Display final
6161

6262
LV::VideoPtr get_video () const;
6363

64-
void set_title(std::string const& title);
64+
void set_title(std::string_view title);
6565

6666
bool is_fullscreen () const;
6767

libvisual/tools/lv-tool/display/display_driver.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#ifndef _LV_TOOL_DISPLAY_DRIVER_HPP
2626
#define _LV_TOOL_DISPLAY_DRIVER_HPP
2727

28-
#include <string>
28+
#include <string_view>
2929
#include <libvisual/libvisual.h>
3030

3131
class Display;
@@ -55,7 +55,7 @@ class DisplayDriver {
5555

5656
virtual LV::VideoPtr get_video () const = 0;
5757

58-
virtual void set_title(std::string const& title) = 0;
58+
virtual void set_title (std::string_view title) = 0;
5959

6060
virtual ~DisplayDriver () {}
6161
};

libvisual/tools/lv-tool/display/display_driver_factory.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,16 @@ DisplayDriverFactory::~DisplayDriverFactory ()
5757
// nothing to do
5858
}
5959

60-
void DisplayDriverFactory::add_driver (std::string const& name, Creator const& creator)
60+
void DisplayDriverFactory::add_driver (std::string_view name, Creator const& creator)
6161
{
62-
m_impl->creators[name] = creator;
62+
std::string const name_str {name};
63+
m_impl->creators[name_str] = creator;
6364
}
6465

65-
DisplayDriver* DisplayDriverFactory::make (std::string const& name, Display& display)
66+
DisplayDriver* DisplayDriverFactory::make (std::string_view name, Display& display)
6667
{
67-
auto entry = m_impl->creators.find (name);
68+
std::string const name_str {name};
69+
auto entry = m_impl->creators.find (name_str);
6870

6971
if (entry == m_impl->creators.end ()) {
7072
return nullptr;
@@ -73,9 +75,10 @@ DisplayDriver* DisplayDriverFactory::make (std::string const& name, Display& dis
7375
return entry->second (display);
7476
}
7577

76-
bool DisplayDriverFactory::has_driver (std::string const& name) const
78+
bool DisplayDriverFactory::has_driver (std::string_view name) const
7779
{
78-
return (m_impl->creators.find (name) != m_impl->creators.end ());
80+
std::string const name_str {name};
81+
return (m_impl->creators.find (name_str) != m_impl->creators.end ());
7982
}
8083

8184
DisplayDriverList DisplayDriverFactory::get_driver_list () const

libvisual/tools/lv-tool/display/display_driver_factory.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "display_driver.hpp"
2929
#include <memory>
3030
#include <functional>
31+
#include <string_view>
3132
#include <vector>
3233

3334
typedef std::function<DisplayDriver* (Display& display)> DisplayDriverCreator;
@@ -46,11 +47,11 @@ class DisplayDriverFactory final
4647
return m_instance;
4748
}
4849

49-
DisplayDriver* make (std::string const& name, Display& display);
50+
DisplayDriver* make (std::string_view name, Display& display);
5051

51-
void add_driver (std::string const& name, Creator const& creator);
52+
void add_driver (std::string_view name, Creator const& creator);
5253

53-
bool has_driver (std::string const& name) const;
54+
bool has_driver (std::string_view name) const;
5455

5556
DisplayDriverList get_driver_list () const;
5657

libvisual/tools/lv-tool/display/sdl_driver.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,10 @@ namespace {
216216
return m_screen_video;
217217
}
218218

219-
void set_title(std::string const& title) override
219+
void set_title (std::string_view title) override
220220
{
221-
SDL_WM_SetCaption (title.c_str(), nullptr);
221+
std::string const title_str {title};
222+
SDL_WM_SetCaption (title_str.c_str (), nullptr);
222223
}
223224

224225
void update_rect (LV::Rect const& rect) override

libvisual/tools/lv-tool/display/stdout_driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ namespace {
104104
return m_screen_video;
105105
}
106106

107-
void set_title(std::string const& title) override
107+
void set_title (std::string_view title) override
108108
{
109109
(void)title;
110110

libvisual/tools/lv-tool/display/stdout_sdl_driver.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,10 @@ namespace {
233233
return m_screen_video;
234234
}
235235

236-
void set_title(std::string const& title) override
236+
void set_title (std::string_view title) override
237237
{
238-
SDL_WM_SetCaption (title.c_str(), nullptr);
238+
std::string title_str {title};
239+
SDL_WM_SetCaption (title_str.c_str (), nullptr);
239240
}
240241

241242
void update_rect (LV::Rect const& rect) override

libvisual/tools/lv-tool/lv-tool.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
#include <atomic>
3333
#include <stdexcept>
3434
#include <iostream>
35-
#include <unordered_set>
3635
#include <string>
36+
#include <string_view>
37+
#include <unordered_set>
3738
#include <cstdio>
3839
#include <cstdlib>
3940
#include <csignal>
@@ -211,8 +212,9 @@ namespace {
211212
}
212213

213214
/** print commandline help */
214-
void print_help(std::string const& name)
215+
void print_help (std::string_view name)
215216
{
217+
std::string const name_str {name};
216218
printf("Usage: %s [options]\n\n"
217219
"Valid options:\n"
218220
"\t--help\t\t\t-h\t\tThis help text\n"
@@ -230,7 +232,7 @@ namespace {
230232
"\t--switch <n>\t\t-S <n>\t\tSwitch actor after n frames.\n"
231233
"\t--exclude <actors>\t-x <actors>\tProvide a list of actors to exclude.\n"
232234
"\n",
233-
name.c_str (),
235+
name_str.c_str (),
234236
width, height,
235237
driver_name.c_str (),
236238
input_name.c_str (),
@@ -244,7 +246,6 @@ namespace {
244246
{
245247
printf("\t%s\n", driver_name.c_str());
246248
}
247-
248249
}
249250

250251

0 commit comments

Comments
 (0)