Skip to content

Commit

Permalink
Rearrange headers in base target
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-johansson committed Oct 10, 2024
1 parent f4f5a27 commit e6c54be
Show file tree
Hide file tree
Showing 17 changed files with 150 additions and 164 deletions.
2 changes: 1 addition & 1 deletion source/base/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ add_library(tactile::base ALIAS tactile-base)

target_sources(tactile-base
INTERFACE FILE_SET "HEADERS" BASE_DIRS "inc" FILES
"inc/tactile/base/container/buffer.hpp"
"inc/tactile/base/container/string_map.hpp"
"inc/tactile/base/container/lookup.hpp"
"inc/tactile/base/document/component_view.hpp"
Expand Down Expand Up @@ -53,7 +54,6 @@ target_sources(tactile-base
"inc/tactile/base/render/window.hpp"
"inc/tactile/base/runtime/plugin.hpp"
"inc/tactile/base/runtime/runtime.hpp"
"inc/tactile/base/util/buffer.hpp"
"inc/tactile/base/util/chrono.hpp"
"inc/tactile/base/util/concepts.hpp"
"inc/tactile/base/util/format.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Buffer final
}

/**
* Adds an value to the buffer.
* Adds a value to the buffer.
*
* \details
* This function has no effect if there is no room left in the buffer.
Expand Down
2 changes: 1 addition & 1 deletion source/base/lib/inc/tactile/base/debug/error_code.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ enum class ErrorCode : int
/** An invalid image was detected. */
kBadImage,

/** A file could not be parsed. */
/** A parse operation failed. */
kParseError,

/** A compression operation failed. */
Expand Down
122 changes: 120 additions & 2 deletions source/base/lib/inc/tactile/base/meta/attribute_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

#pragma once

#include <cstdint> // uint8_t
#include <cstdint> // uint8_t
#include <expected> // expected
#include <ostream> // ostream
#include <stdexcept> // invalid_argument
#include <string_view> // string_view

#include "tactile/base/prelude.hpp"
#include "tactile/base/debug/error_code.hpp"

namespace tactile {

Expand All @@ -28,4 +32,118 @@ enum class AttributeType : std::uint8_t
kObject,
};

/**
* Parses an attribute type from a string.
*
* \param str The attribute type name.
*
* \return
* An attribute type if successful; an error code otherwise.
*/
[[nodiscard]]
constexpr auto parse_attribute_type(const std::string_view str)
-> std::expected<AttributeType, ErrorCode>
{
if (str == "string") {
return AttributeType::kStr;
}

if (str == "int") {
return AttributeType::kInt;
}

if (str == "int2") {
return AttributeType::kInt2;
}

if (str == "int3") {
return AttributeType::kInt3;
}

if (str == "int4") {
return AttributeType::kInt4;
}

if (str == "float") {
return AttributeType::kFloat;
}

if (str == "float2") {
return AttributeType::kFloat2;
}

if (str == "float3") {
return AttributeType::kFloat3;
}

if (str == "float4") {
return AttributeType::kFloat4;
}

if (str == "bool") {
return AttributeType::kBool;
}

if (str == "path" || str == "file") {
return AttributeType::kPath;
}

if (str == "color") {
return AttributeType::kColor;
}

if (str == "object") {
return AttributeType::kObject;
}

return std::unexpected {ErrorCode::kParseError};
}

/**
* Converts an attribute type to a string.
*
* \details
* The returned string is guaranteed to be null-terminated.
*
* \param type An attribute type.
*
* \return
* A string.
*/
[[nodiscard]]
constexpr auto to_string(const AttributeType type) -> std::string_view
{
switch (type) {
case AttributeType::kStr: return "string";
case AttributeType::kInt: return "int";
case AttributeType::kInt2: return "int2";
case AttributeType::kInt3: return "int3";
case AttributeType::kInt4: return "int4";
case AttributeType::kFloat: return "float";
case AttributeType::kFloat2: return "float2";
case AttributeType::kFloat3: return "float3";
case AttributeType::kFloat4: return "float4";
case AttributeType::kBool: return "bool";
case AttributeType::kPath: return "path";
case AttributeType::kColor: return "color";
case AttributeType::kObject: return "object";
}

throw std::invalid_argument {"bad attribute type"};
}

/**
* Outputs an attribute type to a stream for debugging purposes.
*
* \param stream The output stream to use.
* \param type The attribute type to output.
*
* \return
* The provided stream.
*/
inline auto operator<<(std::ostream& stream, const AttributeType type) -> std::ostream&
{
return stream << to_string(type);
}

} // namespace tactile
2 changes: 1 addition & 1 deletion source/base/lib/inc/tactile/base/util/format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <version> // __cpp_lib_format

#include "tactile/base/prelude.hpp"
#include "tactile/base/util/buffer.hpp"
#include "tactile/base/container/buffer.hpp"

// Despite Clang having implemented most of std::format, they don't (yet)
// provide the associated version macros. Making it difficult to write portable
Expand Down
1 change: 1 addition & 0 deletions source/base/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ target_sources(tactile-base-test
"src/io/int_parser_test.cpp"
"src/io/tile_io_test.cpp"
"src/meta/attribute_test.cpp"
"src/meta/attribute_type_test.cpp"
"src/numeric/extent_2d_test.cpp"
"src/numeric/index_2d_test.cpp"
"src/numeric/offset_2d_test.cpp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (C) 2024 Albin Johansson (GNU General Public License v3.0)

#include "tactile/core/meta/attribute_type.hpp"
#include "tactile/base/meta/attribute_type.hpp"

#include <gtest/gtest.h>

namespace tactile::core {
namespace tactile {

/** \trace tactile::core::parse_attribute_type */
// tactile::parse_attribute_type
TEST(AttributeType, ParseAttributeType)
{
EXPECT_EQ(parse_attribute_type("string"), AttributeType::kStr);
Expand All @@ -28,22 +28,22 @@ TEST(AttributeType, ParseAttributeType)
EXPECT_FALSE(parse_attribute_type("int ").has_value());
}

/** \trace tactile::core::serialize [AttributeType] */
TEST(AttributeType, Serialize)
// tactile::to_string [AttributeType]
TEST(AttributeType, ToString)
{
EXPECT_EQ(serialize(AttributeType::kStr), "string");
EXPECT_EQ(serialize(AttributeType::kInt), "int");
EXPECT_EQ(serialize(AttributeType::kInt2), "int2");
EXPECT_EQ(serialize(AttributeType::kInt3), "int3");
EXPECT_EQ(serialize(AttributeType::kInt4), "int4");
EXPECT_EQ(serialize(AttributeType::kFloat), "float");
EXPECT_EQ(serialize(AttributeType::kFloat2), "float2");
EXPECT_EQ(serialize(AttributeType::kFloat3), "float3");
EXPECT_EQ(serialize(AttributeType::kFloat4), "float4");
EXPECT_EQ(serialize(AttributeType::kBool), "bool");
EXPECT_EQ(serialize(AttributeType::kPath), "path");
EXPECT_EQ(serialize(AttributeType::kColor), "color");
EXPECT_EQ(serialize(AttributeType::kObject), "object");
EXPECT_EQ(to_string(AttributeType::kStr), "string");
EXPECT_EQ(to_string(AttributeType::kInt), "int");
EXPECT_EQ(to_string(AttributeType::kInt2), "int2");
EXPECT_EQ(to_string(AttributeType::kInt3), "int3");
EXPECT_EQ(to_string(AttributeType::kInt4), "int4");
EXPECT_EQ(to_string(AttributeType::kFloat), "float");
EXPECT_EQ(to_string(AttributeType::kFloat2), "float2");
EXPECT_EQ(to_string(AttributeType::kFloat3), "float3");
EXPECT_EQ(to_string(AttributeType::kFloat4), "float4");
EXPECT_EQ(to_string(AttributeType::kBool), "bool");
EXPECT_EQ(to_string(AttributeType::kPath), "path");
EXPECT_EQ(to_string(AttributeType::kColor), "color");
EXPECT_EQ(to_string(AttributeType::kObject), "object");
}

} // namespace tactile::core
} // namespace tactile
2 changes: 1 addition & 1 deletion source/base/test/src/util/buffer_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) 2024 Albin Johansson (GNU General Public License v3.0)

#include "tactile/base/util/buffer.hpp"
#include "tactile/base/container/buffer.hpp"

#include <algorithm> // fill_n
#include <array> // array
Expand Down
2 changes: 0 additions & 2 deletions source/core/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ target_sources(tactile-core
"src/log/terminal_log_sink.cpp"
"src/map/map.cpp"
"src/map/map_spec.cpp"
"src/meta/attribute_type.cpp"
"src/meta/color.cpp"
"src/meta/meta.cpp"
"src/model/model.cpp"
Expand Down Expand Up @@ -194,7 +193,6 @@ target_sources(tactile-core
"inc/tactile/core/log/terminal_log_sink.hpp"
"inc/tactile/core/map/map.hpp"
"inc/tactile/core/map/map_spec.hpp"
"inc/tactile/core/meta/attribute_type.hpp"
"inc/tactile/core/meta/color.hpp"
"inc/tactile/core/meta/meta.hpp"
"inc/tactile/core/model/model.hpp"
Expand Down
51 changes: 0 additions & 51 deletions source/core/lib/inc/tactile/core/meta/attribute_type.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion source/core/lib/inc/tactile/core/ui/common/text.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <imgui.h>

#include "tactile/base/prelude.hpp"
#include "tactile/base/util/buffer.hpp"
#include "tactile/base/container/buffer.hpp"
#include "tactile/base/util/format.hpp"

namespace tactile::core {
Expand Down
2 changes: 1 addition & 1 deletion source/core/lib/inc/tactile/core/ui/dock/layer_dock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#pragma once

#include "tactile/base/prelude.hpp"
#include "tactile/base/util/buffer.hpp"
#include "tactile/base/container/buffer.hpp"
#include "tactile/core/entity/entity.hpp"

namespace tactile::core {
Expand Down
2 changes: 1 addition & 1 deletion source/core/lib/src/log/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <exception> // exception
#include <iterator> // back_inserter

#include "tactile/base/util/buffer.hpp"
#include "tactile/base/container/buffer.hpp"

namespace tactile::core {
namespace {
Expand Down
Loading

0 comments on commit e6c54be

Please sign in to comment.