Cogs.Core
StringViewCharPtr.h
1#pragma once
2#include "Base.h"
3
4#include "Foundation/StringView.h"
5#include <string>
6
7namespace Cogs::Core
8{
17 class COGSCORE_DLL_API [[nodiscard]] StringViewCharPtr {
18 using traits_type = std::char_traits<char>;
19
20 public:
22 StringViewCharPtr(const char* data) = delete;
23
27
29 StringViewCharPtr(const std::string& data) = delete;
30
31 StringViewCharPtr(const StringViewCharPtr&) = delete;
32 StringViewCharPtr& operator=(const StringViewCharPtr&) = delete;
33
35 [[nodiscard]] constexpr operator const char* () const noexcept { return view.data(); }
36
38 [[nodiscard]] constexpr const char* c_str() const noexcept { return view.data(); }
39
41 [[nodiscard]] constexpr operator Cogs::StringView() const noexcept { return view; }
42
43 private:
45 std::string copy;
46 };
47}
Utility class to ensure that a StringView string is null terminated.
StringViewCharPtr(const char *data)=delete
Construct from constant C-string. Always null terminated.
StringViewCharPtr(const std::string &data)=delete
Deleted to avoid passing a std::string converted to string_view in constructor above.
constexpr const char * c_str() const noexcept
Gets null terminated C-string.
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:24
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....