aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2021-05-31 12:27:58 -0700
committerrtk0c <[email protected]>2021-05-31 12:27:58 -0700
commit8157678eba97d7de5c53b424a9866d327392bbd9 (patch)
tree26348a926040ccfc91f74cdfe49f7153db271f87
parenteef2514908cdec3ec02888b7467cc877d33c1ceb (diff)
Fix standard incompetence found by MSVC
- requires-expression still not working, because they aren't supported yet outside of a concept
-rw-r--r--core/CMakeLists.txt19
-rw-r--r--core/src/Model/Project.hpp2
-rw-r--r--core/src/Model/Template/TableTemplate.cpp17
-rw-r--r--core/src/Model/Template/TableTemplate.hpp23
-rw-r--r--core/src/Model/Template/Template.hpp4
-rw-r--r--core/src/Model/Template/Template_Main.cpp2
-rw-r--r--core/src/Model/Workflow/Values/BasicValues.cpp16
-rw-r--r--core/src/Model/Workflow/Workflow.hpp44
-rw-r--r--core/src/Model/Workflow/Workflow_Main.cpp16
-rw-r--r--core/src/UI/UI_DatabaseView.cpp10
-rw-r--r--core/src/Utils/Color.hpp9
-rw-r--r--core/src/Utils/Math.hpp11
-rw-r--r--core/src/Utils/Time.cpp4
-rw-r--r--core/src/Utils/Time.hpp4
14 files changed, 106 insertions, 75 deletions
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
index a8fa7af..c4751a5 100644
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -177,17 +177,9 @@ function(add_executable_variant TARGET_NAME)
endif()
endif()
- # Platform specific dependencies for Utils/Dialog, not covered by conan
- if(APPLE)
- target_link_libraries(${TARGET_NAME} PUBLIC ${COCOA_LIBRARY})
- elseif(LINUX)
- target_link_libraries(${TARGET_NAME} PUBLIC ${GTK3_LIBRARIES})
- target_include_directories(${TARGET_NAME} PRIVATE ${GTK3_INCLUDE_DIRS})
- endif()
-
if(WIN32)
- # No console window when targeting windows
function(handle_gnu_style_compiler)
+ # No console window when targeting windows
# Supposedly the flag -mwindows would automatically make the executable use GUI subsystem
# But, when subsystem is set to GUI, linker will only search WinMain and wWinMain but not the standard main (it seems like)
# so creating GUI executable fails and the linker silently reverts to the default, CUI subsystem
@@ -196,6 +188,7 @@ function(add_executable_variant TARGET_NAME)
endfunction()
function(handle_msvc_style_compiler)
+ # No console window when targeting windows
target_link_options(${TARGET_NAME} PRIVATE /SUBSYSTEM:windows /ENTRY:mainCRTStartup)
endfunction()
@@ -203,15 +196,19 @@ function(add_executable_variant TARGET_NAME)
# GCC (MinGW)
handle_gnu_style_compiler()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
- if("x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
+ if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
# MSVC-style argument clang (clang-cl.exe)
handle_msvc_style_compiler()
- else()
+ elseif(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
# GNU-style argument clang (clang.exe and clang++.exe)
handle_gnu_style_compiler()
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
handle_msvc_style_compiler()
+
+ # Use updated __cplusplus macro
+ # https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus
+ target_compile_options(${TARGET_NAME} PUBLIC /Zc:__cplusplus)
endif()
endif()
diff --git a/core/src/Model/Project.hpp b/core/src/Model/Project.hpp
index bce58c2..1eca09d 100644
--- a/core/src/Model/Project.hpp
+++ b/core/src/Model/Project.hpp
@@ -59,7 +59,7 @@ public:
const tsl::array_map<char, TemplateInfo>& GetTemplates() const;
std::unique_ptr<Template> LoadTemplate(std::string_view name);
- bool InsertTemplate(std::string_view name, TemplateInfo info);
+ TemplateInfo* InsertTemplate(std::string_view name, TemplateInfo info);
bool RemoveTemplate(std::string_view name);
bool RenameTemplate(std::string_view oldName, std::string_view newName);
diff --git a/core/src/Model/Template/TableTemplate.cpp b/core/src/Model/Template/TableTemplate.cpp
index 0ad1cca..b8444b7 100644
--- a/core/src/Model/Template/TableTemplate.cpp
+++ b/core/src/Model/Template/TableTemplate.cpp
@@ -1,6 +1,7 @@
#include "TableTemplate.hpp"
#include <xlsxwriter.h>
+#include <iostream>
#include <map>
bool TableCell::IsDataHoldingCell() const
@@ -189,14 +190,14 @@ TableTemplate::BreakCellsResult TableTemplate::BreakCells(Vec2i topLeft)
return BCR_Success;
}
-lxw_workbook* TableTemplate::InstanciateToExcelWorkbook(const TableInstanciationParameters& params) const
+lxw_workbook* TableTemplate::InstantiateToExcelWorkbook(const TableInstanciationParameters& params) const
{
auto workbook = workbook_new("Table.xlsx");
- InstanciateToExcelWorksheet(workbook, params);
+ InstantiateToExcelWorksheet(workbook, params);
return workbook;
}
-lxw_worksheet* TableTemplate::InstanciateToExcelWorksheet(lxw_workbook* workbook, const TableInstanciationParameters& params) const
+lxw_worksheet* TableTemplate::InstantiateToExcelWorksheet(lxw_workbook* workbook, const TableInstanciationParameters& params) const
{
auto worksheet = workbook_add_worksheet(workbook, "CpltExport.xlsx");
@@ -301,3 +302,13 @@ lxw_worksheet* TableTemplate::InstanciateToExcelWorksheet(lxw_workbook* workbook
return worksheet;
}
+Template::ReadResult TableTemplate::ReadFrom(std::istream& stream)
+{
+ // TODO
+ return ReadResult::RR_Success;
+}
+
+void TableTemplate::WriteTo(std::ostream& stream) const
+{
+ // TODO
+}
diff --git a/core/src/Model/Template/TableTemplate.hpp b/core/src/Model/Template/TableTemplate.hpp
index 688192a..f7a79e9 100644
--- a/core/src/Model/Template/TableTemplate.hpp
+++ b/core/src/Model/Template/TableTemplate.hpp
@@ -34,12 +34,12 @@ public:
Vec2i Location;
/// Location of the primary (top left) cell, if this cell is a part of a merged group.
/// Otherwise, either component of this field shall be -1.
- Vec2i PrimaryCellLocation;
- int SpanX;
- int SpanY;
- TextAlignment HorizontalAlignment = AlignAxisMin;
- TextAlignment VerticalAlignment = AlignAxisMin;
- CellType Type;
+ Vec2i PrimaryCellLocation{ -1, -1 };
+ int SpanX = 0;
+ int SpanY = 0;
+ TextAlignment HorizontalAlignment = AlignCenter;
+ TextAlignment VerticalAlignment = AlignCenter;
+ CellType Type = ConstantCell;
/// The id of the group description object, if this cell isn't a constant or singluar parameter cell. Otherwise, this value is -1.
int DataId = -1;
@@ -56,7 +56,7 @@ public:
// TODO support horizontal filling order
/// Parameter group information for a grouped array of cells. When instanciated, an array of 0 or more
/// elements shall be provided by the user, which will replace the group of templated cells with a list
-/// of rows, each instanciated with the n-th element in the provided array.
+/// of rows, each instantiated with the n-th element in the provided array.
/// \code
/// [["foo", "bar", "foobar"],
/// ["a", "b", c"],
@@ -124,7 +124,7 @@ public:
const TableTemplate& GetTable() const;
};
-/// A table template, where individual cells can be filled by workflows instanciating this template. Merged cells,
+/// A table template, where individual cells can be filled by workflows instantiating this template. Merged cells,
/// parametric rows/columns, and grids are also supported.
///
/// This current supports exporting to xlsx files.
@@ -163,6 +163,9 @@ public:
};
BreakCellsResult BreakCells(Vec2i topLeft);
- lxw_workbook* InstanciateToExcelWorkbook(const TableInstanciationParameters& params) const;
- lxw_worksheet* InstanciateToExcelWorksheet(lxw_workbook* workbook, const TableInstanciationParameters& params) const;
+ lxw_workbook* InstantiateToExcelWorkbook(const TableInstanciationParameters& params) const;
+ lxw_worksheet* InstantiateToExcelWorksheet(lxw_workbook* workbook, const TableInstanciationParameters& params) const;
+
+ virtual ReadResult ReadFrom(std::istream& stream) override;
+ virtual void WriteTo(std::ostream& stream) const override;
};
diff --git a/core/src/Model/Template/Template.hpp b/core/src/Model/Template/Template.hpp
index 0901a1b..f7dd898 100644
--- a/core/src/Model/Template/Template.hpp
+++ b/core/src/Model/Template/Template.hpp
@@ -29,8 +29,8 @@ public:
RR_Success,
RR_InvalidFormat,
};
- ReadResult ReadFrom(std::istream& stream) = 0;
- void WriteTo(std::ostream& stream) const = 0;
+ virtual ReadResult ReadFrom(std::istream& stream) = 0;
+ virtual void WriteTo(std::ostream& stream) const = 0;
};
class TemplateInfo
diff --git a/core/src/Model/Template/Template_Main.cpp b/core/src/Model/Template/Template_Main.cpp
index eeb6871..08437b7 100644
--- a/core/src/Model/Template/Template_Main.cpp
+++ b/core/src/Model/Template/Template_Main.cpp
@@ -2,4 +2,6 @@
std::unique_ptr<Template> TemplateInfo::LoadFromDisk() const
{
+ // TODO
+ return nullptr;
}
diff --git a/core/src/Model/Workflow/Values/BasicValues.cpp b/core/src/Model/Workflow/Values/BasicValues.cpp
index a7cf635..748c652 100644
--- a/core/src/Model/Workflow/Values/BasicValues.cpp
+++ b/core/src/Model/Workflow/Values/BasicValues.cpp
@@ -14,14 +14,13 @@ NumericValue::NumericValue()
{
}
-template <class T>
+template <class T, int kMaxSize>
static std::string NumberToString(T value)
{
- constexpr auto kSize = std::numeric_limits<T>::max_digits10;
- char buf[kSize];
+ char buf[kMaxSize];
#if PLATFORM_WIN32
- auto res = std::to_chars(buf, buf + kSize, value);
+ auto res = std::to_chars(buf, buf + kMaxSize, value);
if (res.ec == std::errc()) {
return std::string(buf, res.ptr);
} else {
@@ -35,17 +34,20 @@ static std::string NumberToString(T value)
std::string NumericValue::GetTruncatedString() const
{
- return ::NumberToString((int64_t)mValue);
+ constexpr auto kMaxSize = std::numeric_limits<int64_t>::digits10;
+ return ::NumberToString<int64_t, kMaxSize>((int64_t)mValue);
}
std::string NumericValue::GetRoundedString() const
{
- return ::NumberToString((int64_t)std::round(mValue));
+ constexpr auto kMaxSize = std::numeric_limits<int64_t>::digits10;
+ return ::NumberToString<int64_t, kMaxSize>((int64_t)std::round(mValue));
}
std::string NumericValue::GetString() const
{
- return ::NumberToString(mValue);
+ constexpr auto kMaxSize = std::numeric_limits<double>::max_digits10;
+ return ::NumberToString<double, kMaxSize>(mValue);
}
int64_t NumericValue::GetInt() const
diff --git a/core/src/Model/Workflow/Workflow.hpp b/core/src/Model/Workflow/Workflow.hpp
index ded9bfb..161400e 100644
--- a/core/src/Model/Workflow/Workflow.hpp
+++ b/core/src/Model/Workflow/Workflow.hpp
@@ -5,6 +5,7 @@
#include "cplt_fwd.hpp"
#include <imgui_node_editor.h>
+#include <any>
#include <cstddef>
#include <cstdint>
#include <filesystem>
@@ -240,34 +241,27 @@ public:
/* Graph rebuild */
- struct GraphUpdateResult
+ enum GraphUpdateResult
{
- struct Success
- {
- };
-
- struct NoWorkToDo
- {
- };
-
- struct UnsatisfiedDependencies
- {
- std::vector<uint32_t> UnsatisfiedNodes;
- };
-
- struct UnreachableNodes
- {
- std::vector<uint32_t> UnreachableNodes;
- };
-
- using T = std::variant<
- Success,
- NoWorkToDo,
- UnsatisfiedDependencies,
- UnreachableNodes>;
+ /// Successfully rebuilt graph dependent data.
+ /// Details: nothing is written.
+ GUR_Success,
+ /// Nothing has changed since last time UpdateGraph() was called.
+ /// Details: nothing is written.
+ GUR_NoWorkToDo,
+ /// Details: list of nodes is written.
+ GUR_UnsatisfiedDependencies,
+ /// Details: list of nodes is written.
+ GUR_UnreachableNodes,
};
- GraphUpdateResult::T UpdateGraph();
+ using GraphUpdateDetails = std::variant<
+ // Case: nothing
+ std::monostate,
+ // Case: list of nodes (ids)
+ std::vector<uint32_t>>;
+
+ GraphUpdateResult UpdateGraph(GraphUpdateDetails* details = nullptr);
/* Serialization */
diff --git a/core/src/Model/Workflow/Workflow_Main.cpp b/core/src/Model/Workflow/Workflow_Main.cpp
index bfe007c..61cd510 100644
--- a/core/src/Model/Workflow/Workflow_Main.cpp
+++ b/core/src/Model/Workflow/Workflow_Main.cpp
@@ -524,10 +524,10 @@ bool Workflow::DisconnectByDestination(WorkflowNode& destinationNode, uint32_t d
return true;
}
-Workflow::GraphUpdateResult::T Workflow::UpdateGraph()
+Workflow::GraphUpdateResult Workflow::UpdateGraph(GraphUpdateDetails* details)
{
if (!mDepthsDirty) {
- return GraphUpdateResult::NoWorkToDo{};
+ return GUR_NoWorkToDo;
}
// Terminology:
@@ -577,7 +577,10 @@ Workflow::GraphUpdateResult::T Workflow::UpdateGraph()
}
if (!unsatisfiedNodes.empty()) {
- return GraphUpdateResult::UnsatisfiedDependencies{ std::move(unsatisfiedNodes) };
+ if (details) {
+ details->emplace<decltype(unsatisfiedNodes)>(std::move(unsatisfiedNodes));
+ }
+ return GUR_UnsatisfiedDependencies;
}
}
@@ -624,10 +627,13 @@ Workflow::GraphUpdateResult::T Workflow::UpdateGraph()
unreachableNodes.push_back(i);
}
- return GraphUpdateResult::UnreachableNodes{ std::move(unreachableNodes) };
+ if (details) {
+ details->emplace<decltype(unreachableNodes)>(std::move(unreachableNodes));
+ }
+ return GUR_UnreachableNodes;
}
- return GraphUpdateResult::Success{};
+ return GUR_Success;
}
Workflow::ReadResult Workflow::ReadFrom(std::istream& stream)
diff --git a/core/src/UI/UI_DatabaseView.cpp b/core/src/UI/UI_DatabaseView.cpp
index 73ea657..06326ae 100644
--- a/core/src/UI/UI_DatabaseView.cpp
+++ b/core/src/UI/UI_DatabaseView.cpp
@@ -489,8 +489,8 @@ private:
entries.push_back(DeliveryEntry{
.Items = std::move(items),
.ItemsSummary = std::move(summary),
- .ShipmentTime = StringifyTimeStamp(stmt.getColumn(arrivalTimeCol).getInt64()),
- .ArriveTime = StringifyTimeStamp(stmt.getColumn(sendTimeCol).getInt64()),
+ .ShipmentTime = TimeUtils::StringifyTimeStamp(stmt.getColumn(arrivalTimeCol).getInt64()),
+ .ArriveTime = TimeUtils::StringifyTimeStamp(stmt.getColumn(sendTimeCol).getInt64()),
.Direction = type,
});
}
@@ -557,7 +557,7 @@ private:
if constexpr (kHasDeadline) {
auto timeStamp = stmt.getColumn(deadlineCol).getInt64();
- entry.Deadline = StringifyTimeStamp(timeStamp);
+ entry.Deadline = TimeUtils::StringifyTimeStamp(timeStamp);
}
if constexpr (kHasFactory) {
@@ -567,12 +567,12 @@ private:
if constexpr (kHasOrderTime) {
auto timeStamp = stmt.getColumn(orderTimeCol).getInt64();
- entry.OrderTime = StringifyTimeStamp(timeStamp);
+ entry.OrderTime = TimeUtils::StringifyTimeStamp(timeStamp);
}
if constexpr (kHasCompletionTime) {
auto timeStamp = stmt.getColumn(deliveryTimeCol).getInt64();
- entry.DeliveryTime = StringifyTimeStamp(timeStamp);
+ entry.DeliveryTime = TimeUtils::StringifyTimeStamp(timeStamp);
}
}
diff --git a/core/src/Utils/Color.hpp b/core/src/Utils/Color.hpp
index 8e159ea..46435c3 100644
--- a/core/src/Utils/Color.hpp
+++ b/core/src/Utils/Color.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include "Utils/Math.hpp"
#include "Utils/Vector.hpp"
#include "Utils/fwd.hpp"
@@ -167,7 +168,7 @@ constexpr HsvColor RgbaColor::ToHsv() const noexcept
auto p = fg < fb ? Vec4f{ fb, fg, -1, 2.0f / 3.0f } : Vec4f{ fg, fb, 0, -1.0f / 3.0f };
auto q = fr < p.x ? Vec4f{ p.x, p.y, p.w, fr } : Vec4f{ fr, p.y, p.z, p.x };
float c = q.x - std::min(q.w, q.y);
- float h = std::abs((q.w - q.y) / (6 * c + std::numeric_limits<float>::epsilon()) + q.z);
+ float h = MathUtils::Abs((q.w - q.y) / (6 * c + std::numeric_limits<float>::epsilon()) + q.z);
Vec3f hcv{ h, c, q.x };
float s = hcv.y / (hcv.z + std::numeric_limits<float>::epsilon());
@@ -176,9 +177,9 @@ constexpr HsvColor RgbaColor::ToHsv() const noexcept
constexpr RgbaColor HsvColor::ToRgba() const noexcept
{
- float r = std::abs(h * 6 - 3) - 1;
- float g = 2 - std::abs(h * 6 - 2);
- float b = 2 - std::abs(h * 6 - 4);
+ float r = MathUtils::Abs(h * 6 - 3) - 1;
+ float g = 2 - MathUtils::Abs(h * 6 - 2);
+ float b = 2 - MathUtils::Abs(h * 6 - 4);
auto rgb = Vec3f{
std::clamp(r, 0.0f, 1.0f),
diff --git a/core/src/Utils/Math.hpp b/core/src/Utils/Math.hpp
new file mode 100644
index 0000000..2d0c0cd
--- /dev/null
+++ b/core/src/Utils/Math.hpp
@@ -0,0 +1,11 @@
+#pragma once
+
+namespace MathUtils {
+
+template <class T>
+constexpr T Abs(T t)
+{
+ return t < 0 ? -t : t;
+}
+
+} // namespace Math
diff --git a/core/src/Utils/Time.cpp b/core/src/Utils/Time.cpp
index bbdc313..9086e31 100644
--- a/core/src/Utils/Time.cpp
+++ b/core/src/Utils/Time.cpp
@@ -2,7 +2,7 @@
#include <ctime>
-std::string StringifyTimePoint(std::chrono::time_point<std::chrono::system_clock> tp)
+std::string TimeUtils::StringifyTimePoint(std::chrono::time_point<std::chrono::system_clock> tp)
{
auto t = std::chrono::system_clock::to_time_t(tp);
@@ -15,7 +15,7 @@ std::string StringifyTimePoint(std::chrono::time_point<std::chrono::system_clock
return std::string(data);
}
-std::string StringifyTimeStamp(int64_t timeStamp)
+std::string TimeUtils::StringifyTimeStamp(int64_t timeStamp)
{
if (timeStamp == 0) {
return "";
diff --git a/core/src/Utils/Time.hpp b/core/src/Utils/Time.hpp
index 13e12a1..fbbd3b2 100644
--- a/core/src/Utils/Time.hpp
+++ b/core/src/Utils/Time.hpp
@@ -3,5 +3,9 @@
#include <chrono>
#include <string>
+namespace TimeUtils {
+
std::string StringifyTimePoint(std::chrono::time_point<std::chrono::system_clock> tp);
std::string StringifyTimeStamp(int64_t timeStamp);
+
+} // namespace TimeUtils