Skip to content

Commit

Permalink
Remove string header
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-johansson committed Aug 23, 2024
1 parent 0a2cf76 commit 3a81888
Show file tree
Hide file tree
Showing 107 changed files with 500 additions and 439 deletions.
2 changes: 1 addition & 1 deletion source/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ add_library(tactile::base ALIAS tactile-base)

target_sources(tactile-base
INTERFACE FILE_SET "HEADERS" BASE_DIRS "inc" FILES
"inc/tactile/base/container/string.hpp"
"inc/tactile/base/container/string_map.hpp"
"inc/tactile/base/document/component_view.hpp"
"inc/tactile/base/document/document.hpp"
Expand Down Expand Up @@ -45,6 +44,7 @@ target_sources(tactile-base
"inc/tactile/base/numeric/vec_stream.hpp"
"inc/tactile/base/platform/bits.hpp"
"inc/tactile/base/platform/filesystem.hpp"
"inc/tactile/base/platform/native_string.hpp"
"inc/tactile/base/render/renderer.hpp"
"inc/tactile/base/render/texture.hpp"
"inc/tactile/base/render/window.hpp"
Expand Down
29 changes: 0 additions & 29 deletions source/base/inc/tactile/base/container/string.hpp

This file was deleted.

11 changes: 6 additions & 5 deletions source/base/inc/tactile/base/container/string_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,39 @@
#pragma once

#include <functional> // hash, equal_to
#include <string> // string
#include <string_view> // string_view
#include <type_traits> // true_type
#include <unordered_map> // unordered_map

#include "tactile/base/container/string.hpp"
#include "tactile/base/int.hpp"

namespace tactile {

/** Custom hash object capable of hashing several string types. */
struct StringHash final
{
using hash_type = std::hash<StringView>;
using hash_type = std::hash<std::string_view>;
using is_transparent [[maybe_unused]] = std::true_type;

[[nodiscard]] auto operator()(const char* str) const -> usize
{
return hash_type {}(str);
}

[[nodiscard]] auto operator()(StringView str) const -> usize
[[nodiscard]] auto operator()(const std::string_view str) const -> usize
{
return hash_type {}(str);
}

[[nodiscard]] auto operator()(const String& str) const -> usize
[[nodiscard]] auto operator()(const std::string& str) const -> usize
{
return hash_type {}(str);
}
};

/** A hash map optimized for string keys, using heterogeneous lookups. */
template <typename T>
using StringMap = std::unordered_map<String, T, StringHash, std::equal_to<>>;
using StringMap = std::unordered_map<std::string, T, StringHash, std::equal_to<>>;

} // namespace tactile
7 changes: 4 additions & 3 deletions source/base/inc/tactile/base/document/component_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
#pragma once

#include <expected> // expected
#include <string> // string
#include <string_view> // string_view
#include <system_error> // error_code
#include <utility> // pair

#include "tactile/base/container/string.hpp"
#include "tactile/base/int.hpp"
#include "tactile/base/prelude.hpp"

Expand Down Expand Up @@ -42,7 +43,7 @@ class IComponentView
* A component name.
*/
[[nodiscard]]
virtual auto get_name() const -> StringView = 0;
virtual auto get_name() const -> std::string_view = 0;

/**
* Returns an attribute in the component.
Expand All @@ -54,7 +55,7 @@ class IComponentView
*/
[[nodiscard]]
virtual auto get_attribute(usize index) const
-> std::pair<const String&, const Attribute&> = 0;
-> std::pair<const std::string&, const Attribute&> = 0;

/**
* Returns the number of attributes in the component.
Expand Down
1 change: 0 additions & 1 deletion source/base/inc/tactile/base/document/layer_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <optional> // optional
#include <system_error> // error_code

#include "tactile/base/container/string.hpp"
#include "tactile/base/id.hpp"
#include "tactile/base/io/byte_stream.hpp"
#include "tactile/base/io/compress/compression_format.hpp"
Expand Down
9 changes: 5 additions & 4 deletions source/base/inc/tactile/base/document/meta_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

#pragma once

#include <utility> // pair
#include <string> // string
#include <string_view> // string_view
#include <utility> // pair

#include "tactile/base/container/string.hpp"
#include "tactile/base/int.hpp"
#include "tactile/base/prelude.hpp"

Expand All @@ -27,7 +28,7 @@ class IMetaView
* A context name.
*/
[[nodiscard]]
virtual auto get_name() const -> StringView = 0;
virtual auto get_name() const -> std::string_view = 0;

/**
* Returns a property attached to the context.
Expand All @@ -39,7 +40,7 @@ class IMetaView
*/
[[nodiscard]]
virtual auto get_property(usize index) const
-> std::pair<const String&, const Attribute&> = 0;
-> std::pair<const std::string&, const Attribute&> = 0;

/**
* Returns the number of properties attached to the context.
Expand Down
4 changes: 2 additions & 2 deletions source/base/inc/tactile/base/document/object_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#pragma once

#include <expected> // expected
#include <string_view> // string_view
#include <system_error> // error_code

#include "tactile/base/container/string.hpp"
#include "tactile/base/id.hpp"
#include "tactile/base/layer/object_type.hpp"
#include "tactile/base/numeric/vec.hpp"
Expand Down Expand Up @@ -99,7 +99,7 @@ class IObjectView
* A type tag.
*/
[[nodiscard]]
virtual auto get_tag() const -> StringView = 0;
virtual auto get_tag() const -> std::string_view = 0;

/**
* Indicates whether the object is visible.
Expand Down
4 changes: 2 additions & 2 deletions source/base/inc/tactile/base/document/tileset_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

#include <expected> // expected
#include <filesystem> // path
#include <string> // string
#include <system_error> // error_code

#include "tactile/base/container/string.hpp"
#include "tactile/base/id.hpp"
#include "tactile/base/numeric/vec.hpp"
#include "tactile/base/prelude.hpp"
Expand Down Expand Up @@ -120,7 +120,7 @@ class ITilesetView
* A filename without a file extension.
*/
[[nodiscard]]
virtual auto get_filename() const -> String = 0;
virtual auto get_filename() const -> std::string = 0;
};

} // namespace tactile
11 changes: 6 additions & 5 deletions source/base/inc/tactile/base/io/color_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

#pragma once

#include <optional> // optional, nullopt
#include <optional> // optional, nullopt
#include <string> // string
#include <string_view> // string_view

#include "tactile/base/container/string.hpp"
#include "tactile/base/io/int_parser.hpp"
#include "tactile/base/meta/color.hpp"
#include "tactile/base/prelude.hpp"
Expand All @@ -20,7 +21,7 @@ namespace tactile {
* A color if successful; an empty optional otherwise.
*/
[[nodiscard]]
constexpr auto parse_color_rgb(const StringView rgb) noexcept -> std::optional<UColor>
constexpr auto parse_color_rgb(const std::string_view rgb) noexcept -> std::optional<UColor>
{
if (rgb.length() != 7 || rgb.front() != '#') {
return std::nullopt;
Expand Down Expand Up @@ -49,7 +50,7 @@ constexpr auto parse_color_rgb(const StringView rgb) noexcept -> std::optional<U
* A color if successful; an empty optional otherwise.
*/
[[nodiscard]]
constexpr auto parse_color_rgba(const StringView rgba) noexcept -> std::optional<UColor>
constexpr auto parse_color_rgba(const std::string_view rgba) noexcept -> std::optional<UColor>
{
if (rgba.length() != 9 || rgba.front() != '#') {
return std::nullopt;
Expand Down Expand Up @@ -79,7 +80,7 @@ constexpr auto parse_color_rgba(const StringView rgba) noexcept -> std::optional
* A color if successful; an empty optional otherwise.
*/
[[nodiscard]]
constexpr auto parse_color_argb(const StringView argb) noexcept -> std::optional<UColor>
constexpr auto parse_color_argb(const std::string_view argb) noexcept -> std::optional<UColor>
{
if (argb.length() != 9 || argb.front() != '#') {
return std::nullopt;
Expand Down
7 changes: 4 additions & 3 deletions source/base/inc/tactile/base/io/file_io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include <ios> // ios
#include <iterator> // istreambuf_iterator
#include <optional> // optional
#include <string> // string

#include "tactile/base/container/string.hpp"
#include "tactile/base/prelude.hpp"

namespace tactile {
Expand All @@ -21,12 +21,13 @@ namespace tactile {
* \return
* The file content if successful; an empty optional otherwise.
*/
inline auto read_binary_file(const std::filesystem::path& path) -> std::optional<String>
inline auto read_binary_file(const std::filesystem::path& path) -> std::optional<std::string>
{
std::ifstream stream {path, std::ios::in | std::ios::binary};

if (stream.good()) {
return String {std::istreambuf_iterator<char> {stream}, std::istreambuf_iterator<char> {}};
return std::string {std::istreambuf_iterator<char> {stream},
std::istreambuf_iterator<char> {}};
}

return std::nullopt;
Expand Down
7 changes: 4 additions & 3 deletions source/base/inc/tactile/base/io/int_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

#include <charconv> // from_chars
#include <optional> // optional
#include <string> // string
#include <string_view> // string_view
#include <system_error> // errc

#include "tactile/base/container/string.hpp"
#include "tactile/base/int.hpp"
#include "tactile/base/prelude.hpp"

Expand All @@ -24,8 +25,8 @@ namespace tactile {
* An integer if successful; an empty optional otherwise.
*/
template <std::integral T>
[[nodiscard]] constexpr auto parse(StringView str,
const int base = 10) noexcept -> std::optional<T>
[[nodiscard]] constexpr auto parse(std::string_view str, const int base = 10) noexcept
-> std::optional<T>
{
const auto* const begin = str.data();
const auto* const end = begin + str.size();
Expand Down
Loading

0 comments on commit 3a81888

Please sign in to comment.