string_view refactor

This commit is contained in:
Jack Andersen
2017-11-12 20:13:32 -10:00
parent 420dcee552
commit cb5d22eed6
18 changed files with 98 additions and 94 deletions

View File

@@ -30,7 +30,7 @@ namespace boo
{
static logvisor::Module Log("boo::ApplicationCocoa");
std::shared_ptr<IWindow> _WindowCocoaNew(const SystemString& title, NSOpenGLContext* lastGLCtx,
std::shared_ptr<IWindow> _WindowCocoaNew(SystemStringView title, NSOpenGLContext* lastGLCtx,
MetalContext* metalCtx, uint32_t sampleCount);
class ApplicationCocoa : public IApplication
@@ -58,9 +58,9 @@ private:
public:
ApplicationCocoa(IApplicationCallback& callback,
const SystemString& uniqueName,
const SystemString& friendlyName,
const SystemString& pname,
SystemStringView uniqueName,
SystemStringView friendlyName,
SystemStringView pname,
const std::vector<SystemString>& args)
: m_callback(callback),
m_uniqueName(uniqueName),
@@ -120,7 +120,7 @@ public:
/* Spawn client thread */
m_clientThread = std::thread([&]()
{
std::string thrName = getFriendlyName() + " Client Thread";
std::string thrName = std::string(getFriendlyName()) + " Client Thread";
logvisor::RegisterThreadName(thrName.c_str());
/* Run app */
@@ -161,17 +161,17 @@ public:
[NSApp terminate:nil];
}
const SystemString& getUniqueName() const
SystemStringView getUniqueName() const
{
return m_uniqueName;
}
const SystemString& getFriendlyName() const
SystemStringView getFriendlyName() const
{
return m_friendlyName;
}
const SystemString& getProcessName() const
SystemStringView getProcessName() const
{
return m_pname;
}
@@ -181,7 +181,7 @@ public:
return m_args;
}
std::shared_ptr<IWindow> newWindow(const std::string& title, uint32_t sampleCount)
std::shared_ptr<IWindow> newWindow(std::string_view title, uint32_t sampleCount)
{
auto newWindow = _WindowCocoaNew(title, m_lastGLCtx, &m_metalCtx, sampleCount);
m_windows[newWindow->getPlatformHandle()] = newWindow;
@@ -200,13 +200,13 @@ void _CocoaUpdateLastGLCtx(NSOpenGLContext* lastGLCtx)
IApplication* APP = nullptr;
int ApplicationRun(IApplication::EPlatformType platform,
IApplicationCallback& cb,
const SystemString& uniqueName,
const SystemString& friendlyName,
const SystemString& pname,
SystemStringView uniqueName,
SystemStringView friendlyName,
SystemStringView pname,
const std::vector<SystemString>& args,
bool singleInstance)
{
std::string thrName = friendlyName + " Main Thread";
std::string thrName = std::string(friendlyName) + " Main Thread";
logvisor::RegisterThreadName(thrName.c_str());
@autoreleasepool
{

View File

@@ -20,7 +20,7 @@ namespace boo {class WindowCocoa; class GraphicsContextCocoa;}
std::shared_ptr<boo::WindowCocoa> booWindow;
id touchBarProvider;
}
- (id)initWithBooWindow:(std::shared_ptr<boo::WindowCocoa>&)bw title:(const std::string&)title;
- (id)initWithBooWindow:(std::shared_ptr<boo::WindowCocoa>&)bw title:(std::string_view)title;
- (void)setFrameDefault;
- (NSRect)genFrameDefault;
- (void)setTouchBarProvider:(id)provider;
@@ -1271,7 +1271,7 @@ class WindowCocoa : public IWindow
public:
void setup(const std::string& title, NSOpenGLContext* lastGLCtx, MetalContext* metalCtx, uint32_t sampleCount)
void setup(std::string_view title, NSOpenGLContext* lastGLCtx, MetalContext* metalCtx, uint32_t sampleCount)
{
dispatch_sync(dispatch_get_main_queue(),
^{
@@ -1337,11 +1337,11 @@ public:
return [[m_nsWindow title] UTF8String];
}
void setTitle(const std::string& title)
void setTitle(std::string_view title)
{
dispatch_sync(dispatch_get_main_queue(),
^{
[m_nsWindow setTitle:[NSString stringWithUTF8String:title.c_str()]];
[m_nsWindow setTitle:[NSString stringWithUTF8String:title.data()]];
});
}
@@ -1559,7 +1559,7 @@ public:
};
std::shared_ptr<IWindow> _WindowCocoaNew(const SystemString& title, NSOpenGLContext* lastGLCtx,
std::shared_ptr<IWindow> _WindowCocoaNew(SystemStringView title, NSOpenGLContext* lastGLCtx,
MetalContext* metalCtx, uint32_t sampleCount)
{
auto ret = std::make_shared<WindowCocoa>();
@@ -1570,7 +1570,7 @@ std::shared_ptr<IWindow> _WindowCocoaNew(const SystemString& title, NSOpenGLCont
}
@implementation WindowCocoaInternal
- (id)initWithBooWindow:(std::shared_ptr<boo::WindowCocoa>&)bw title:(const boo::SystemString&)title
- (id)initWithBooWindow:(std::shared_ptr<boo::WindowCocoa>&)bw title:(std::string_view)title
{
self = [self initWithContentRect:[self genFrameDefault]
styleMask:NSWindowStyleMaskTitled|
@@ -1580,7 +1580,7 @@ std::shared_ptr<IWindow> _WindowCocoaNew(const SystemString& title, NSOpenGLCont
backing:NSBackingStoreBuffered
defer:YES];
self.releasedWhenClosed = NO;
self.title = [NSString stringWithUTF8String:title.c_str()];
self.title = [NSString stringWithUTF8String:title.data()];
booWindow = bw;
return self;
}