Skip to content

Fix C++17 support. #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ enable_testing()

# Project setup
project(inkcpp VERSION 0.1.8)
SET(CMAKE_CXX_STANDARD 20)
SET(CMAKE_CXX_STANDARD 17) # Make sure this project and all dependencies use the C++17 standard
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_INSTALL_LIBRARY_DIR lib)
SET(CMAKE_INSTALL_INCLUDE_DIR include)
Expand All @@ -59,7 +59,7 @@ set_property(CACHE INKCPP_INKLECATE PROPERTY STRINGS "NONE" "OS" "ALL")
string(TOUPPER "${INKCPP_INKLECATE}" inkcpp_inklecate_upper)
if (inkcpp_inklecate_upper STREQUAL "ALL")
FetchContent_MakeAvailable(inklecate_windows inklecate_mac inklecate_linux)
elseif(inkcpp_inklecate_upper STREQUAL "OS")
elseif(inkcpp_inklecate_upper STREQUAL "OS")
if(UNIX AND NOT APPLE)
FetchContent_MakeAvailable(inklecate_linux)
elseif(APPLE)
Expand Down Expand Up @@ -153,7 +153,7 @@ if (DOXYGEN_FOUND)
if (INKCPP_DOC_BlueprintUE AND NOT "${NODEJS_PATH}" STREQUAL "NODEJS-NOTFOUND")
# TODO: make as dependecy
file(COPY "${PROJECT_SOURCE_DIR}/unreal/blueprint_filter.js" DESTINATION ${PROJECT_BINARY_DIR})
# file(DOWNLOAD
# file(DOWNLOAD
# "https://raw.githubusercontent.com/blueprintue/blueprintue-self-hosted-edition/main/www/bue-render/render.css"
# "${PROJECT_BINARY_DIR}/render.css"
# EXPECTED_HASH SHA256=875364e36f8aa5d6c1d41d58043f13b48a499b5c969e8daef35bd29bbf7c6e8d)
Expand Down Expand Up @@ -195,7 +195,7 @@ if (DOXYGEN_FOUND)
COMMAND ${CMAKE_COMMAND} -E copy "./inkcpp_py.html" ${PY_HTML}
DEPENDS inkcpp_py
WORKING_DIRECTORY $<TARGET_FILE_DIR:inkcpp_py>
COMMENT "Generates simple python documentation")
COMMENT "Generates simple python documentation")
add_dependencies(doc inkcpp_py_doc)
else()
message(WARNING "The python target is disabled, therfore no python documentation will be build. Set INKCPP_PY to change this")
Expand Down
10 changes: 4 additions & 6 deletions inkcpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

list(APPEND SOURCES
list(APPEND SOURCES
array.h
choice.cpp
functional.cpp
functions.h functions.cpp
functions.h functions.cpp
globals_impl.h globals_impl.cpp
output.h output.cpp
platform.h
Expand Down Expand Up @@ -33,7 +33,7 @@ list(APPEND SOURCES
random.h
)
list(APPEND COLLECTION_SOURCES
collections/restorable.h
collections/restorable.h
collections/restorable.cpp
)
FILE(GLOB PUBLIC_HEADERS "include/*")
Expand All @@ -51,11 +51,9 @@ target_include_directories(inkcpp PUBLIC
)
set_target_properties(inkcpp PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADERS}")

# Make sure the include directory is included
# Make sure the include directory is included
target_link_libraries(inkcpp_o PRIVATE inkcpp_shared)
target_link_libraries(inkcpp PRIVATE inkcpp_shared)
# Make sure this project and all dependencies use the C++17 standard
target_compile_features(inkcpp PUBLIC cxx_std_17)


# Unreal installation
Expand Down
2 changes: 1 addition & 1 deletion inkcpp/globals_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ bool globals_impl::set_var(hash_t name, const ink::runtime::value& val)

void globals_impl::internal_observe(hash_t name, callback_base* callback)
{
_callbacks.push() = Callback{.name = name, .operation = callback};
_callbacks.push() = Callback{name, callback};
if (_globals_initialized) {
value* p_var = _variables.get(name);
inkAssert(
Expand Down
2 changes: 1 addition & 1 deletion inkcpp/list_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void list_impl::next(const char*& flag_name, const char*& list_name, int& i, boo
return;
}

list_flag flag{.list_id = static_cast<int16_t>(i >> 16), .flag = static_cast<int16_t>(i & 0xFF)};
list_flag flag{static_cast<int16_t>(i >> 16), static_cast<int16_t>(i & 0xFF)};
if (flag_name != nullptr) {
++flag.flag;
}
Expand Down
9 changes: 2 additions & 7 deletions inkcpp/list_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,9 +699,7 @@ optional<list_flag> list_table::toFlag(const char* flag_name) const
int list_begin = list.list_id == 0 ? 0 : _list_end[list.list_id - 1];
for (int i = list_begin; i != _list_end[list.list_id]; ++i) {
if (str_equal(flag_name, _flag_names[i])) {
return {
list_flag{.list_id = list.list_id, .flag = static_cast<int16_t>(i - list_begin)}
};
return list_flag{list.list_id, static_cast<int16_t>(i - list_begin)};
}
}
} else {
Expand All @@ -717,10 +715,7 @@ optional<list_flag> list_table::toFlag(const char* flag_name) const
}
begin = *list_itr;
}
return {
list_flag{
.list_id = static_cast<int16_t>(lid), .flag = static_cast<int16_t>(fid - begin)}
};
return list_flag{static_cast<int16_t>(lid), static_cast<int16_t>(fid - begin)};
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions inkcpp/runner_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ void runner_impl::jump(ip_t dest, bool record_visits, bool track_knot_visit)
break;
}
if (_container.empty() || _container.top().id != id) {
_container.push({.id = id, .offset = offset});
_container.push({id, offset});
} else {
_container.pop();
if (_container.size() < comm_end) {
Expand All @@ -373,7 +373,7 @@ void runner_impl::jump(ip_t dest, bool record_visits, bool track_knot_visit)
_entered_knot = true;
}
_ptr += 6;
_container.push({.id = id, .offset = offset});
_container.push({id, offset});
if (reversed && comm_end == _container.size() - 1) {
++comm_end;
}
Expand Down Expand Up @@ -1394,7 +1394,7 @@ void runner_impl::step()
// Keep track of current container
auto index = read<uint32_t>();
// offset points to command, command has size 6
_container.push({.id = index, .offset = _ptr - 6});
_container.push({index, _ptr - 6});

// Increment visit count
if (flag & CommandFlag::CONTAINER_MARKER_TRACK_VISITS
Expand Down
6 changes: 1 addition & 5 deletions inkcpp_compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
list(APPEND SOURCES
compiler.cpp binary_stream.h binary_stream.cpp json.hpp
json_compiler.h json_compiler.cpp
json_compiler.h json_compiler.cpp
emitter.h emitter.cpp
reporter.h reporter.cpp
binary_emitter.h binary_emitter.cpp
Expand All @@ -25,10 +25,6 @@ set_target_properties(inkcpp_compiler PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADERS
target_link_libraries(inkcpp_compiler PRIVATE inkcpp_shared)
target_link_libraries(inkcpp_compiler_o PRIVATE inkcpp_shared)

# Make sure this project and all dependencies use the C++17 standard
target_compile_features(inkcpp_compiler PUBLIC cxx_std_17)
target_compile_features(inkcpp_compiler PUBLIC cxx_std_17)

# Unreal installation
list(REMOVE_ITEM SOURCES "json.hpp")
configure_file("json.hpp" "${CMAKE_BINARY_DIR}/unreal/inkcpp/Source/ThirdParty/Private/json.hpp" COPYONLY)
Expand Down
3 changes: 2 additions & 1 deletion inkcpp_compiler/json_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ void json_compiler::compile_container(
bool is_knot = name_override != "" && index_in_parent == -1;
if (is_knot) {
// it is not a wave or choice
if (name_override.starts_with("c-") || name_override.starts_with("g-")) {
if (::ink::internal::starts_with(name_override.c_str(), "c-")
|| ::ink::internal::starts_with(name_override.c_str(), "g-")) {
is_knot = false;
for (auto itr = name_override.begin() + 2; itr != name_override.end(); ++itr) {
if (*itr > '9' || *itr < '0') {
Expand Down
5 changes: 3 additions & 2 deletions inkcpp_compiler/list_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ void list_data::new_flag(const std::string& flag_name, int value)
_flags.emplace_back(
&flag_name,
list_flag{
.list_id = static_cast<decltype(list_flag::list_id)>(_list_name.size() - 1),
.flag = static_cast<decltype(list_flag::flag)>(value)}
static_cast<decltype(list_flag::list_id)>(_list_name.size() - 1),
static_cast<decltype(list_flag::flag)>(value)
}
);
}

Expand Down
13 changes: 13 additions & 0 deletions shared/public/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ constexpr list_flag empty_flag{-1, 0};

namespace internal
{
/** Checks if a string starts with a given prefix*/
static bool starts_with(const char* string, const char* prefix)
{
while (*prefix) {
if (*string != *prefix) {
return false;
}
string++;
prefix++;
}
return true;
}

/** Checks if a string is only whitespace*/
static bool is_whitespace(const char* string, bool includeNewline = true)
{
Expand Down
Loading