Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2021-03-21 16:29:26 +0300
committerJacques Lucke <jacques@blender.org>2021-03-21 16:29:26 +0300
commit9e437aabdb3d14c32584afb4bfa9e6eb35f06e51 (patch)
tree534033c46cb5092cb1338957dddfe1d69532e52f /source/blender/editors
parentdcf1a1045dfee527bd691113385cfa61df1499fe (diff)
Cleanup: fix compiling with older compiler on macos
We cannot use `std::variant` yet, because not all of the compilers we support have a working version of it yet. For now, I just replaced it with multiple `std::option` which is good enough, because currently `CellValue` is only used for the cells that are actually drawn in the spreadsheet.
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/space_spreadsheet/spreadsheet_column_layout.cc20
-rw-r--r--source/blender/editors/space_spreadsheet/spreadsheet_column_layout.hh17
-rw-r--r--source/blender/editors/space_spreadsheet/spreadsheet_from_geometry.cc22
3 files changed, 31 insertions, 28 deletions
diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_column_layout.cc b/source/blender/editors/space_spreadsheet/spreadsheet_column_layout.cc
index 00724ffd4b0..46760c0dd4e 100644
--- a/source/blender/editors/space_spreadsheet/spreadsheet_column_layout.cc
+++ b/source/blender/editors/space_spreadsheet/spreadsheet_column_layout.cc
@@ -118,8 +118,8 @@ class ColumnLayoutDrawer : public SpreadsheetDrawer {
CellValue cell_value;
column.get_value(real_index, cell_value);
- if (std::holds_alternative<int>(cell_value.value)) {
- const int value = *std::get_if<int>(&cell_value.value);
+ if (cell_value.value_int.has_value()) {
+ const int value = *cell_value.value_int;
const std::string value_str = std::to_string(value);
uiDefIconTextBut(params.block,
UI_BTYPE_LABEL,
@@ -137,8 +137,8 @@ class ColumnLayoutDrawer : public SpreadsheetDrawer {
0,
nullptr);
}
- else if (std::holds_alternative<float>(cell_value.value)) {
- const float value = *std::get_if<float>(&cell_value.value);
+ else if (cell_value.value_float.has_value()) {
+ const float value = *cell_value.value_float;
std::stringstream ss;
ss << std::fixed << std::setprecision(3) << value;
const std::string value_str = ss.str();
@@ -158,8 +158,8 @@ class ColumnLayoutDrawer : public SpreadsheetDrawer {
0,
nullptr);
}
- else if (std::holds_alternative<bool>(cell_value.value)) {
- const bool value = *std::get_if<bool>(&cell_value.value);
+ else if (cell_value.value_bool.has_value()) {
+ const bool value = *cell_value.value_bool;
const int icon = value ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT;
uiDefIconTextBut(params.block,
UI_BTYPE_LABEL,
@@ -177,8 +177,8 @@ class ColumnLayoutDrawer : public SpreadsheetDrawer {
0,
nullptr);
}
- else if (std::holds_alternative<ObjectCellValue>(cell_value.value)) {
- const ObjectCellValue value = *std::get_if<ObjectCellValue>(&cell_value.value);
+ else if (cell_value.value_object.has_value()) {
+ const ObjectCellValue value = *cell_value.value_object;
uiDefIconTextBut(params.block,
UI_BTYPE_LABEL,
0,
@@ -195,8 +195,8 @@ class ColumnLayoutDrawer : public SpreadsheetDrawer {
0,
nullptr);
}
- else if (std::holds_alternative<CollectionCellValue>(cell_value.value)) {
- const CollectionCellValue value = *std::get_if<CollectionCellValue>(&cell_value.value);
+ else if (cell_value.value_collection.has_value()) {
+ const CollectionCellValue value = *cell_value.value_collection;
uiDefIconTextBut(params.block,
UI_BTYPE_LABEL,
0,
diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_column_layout.hh b/source/blender/editors/space_spreadsheet/spreadsheet_column_layout.hh
index cfbf6963a9d..611337df007 100644
--- a/source/blender/editors/space_spreadsheet/spreadsheet_column_layout.hh
+++ b/source/blender/editors/space_spreadsheet/spreadsheet_column_layout.hh
@@ -16,7 +16,7 @@
#pragma once
-#include <variant>
+#include <optional>
#include "spreadsheet_draw.hh"
@@ -39,12 +39,15 @@ struct CollectionCellValue {
*/
class CellValue {
public:
- /* The implementation just uses a `std::variant` for simplicity. It can be encapsulated better,
- * but it's not really worth the complexity for now. */
- using VariantType =
- std::variant<std::monostate, int, float, bool, ObjectCellValue, CollectionCellValue>;
-
- VariantType value;
+ /* The implementation just uses a bunch of `std::option` for now. Unfortunately, we cannot use
+ * `std::variant` yet, due to missing compiler support. This type can really be optimized more,
+ * but it does not really matter too much currently. */
+
+ std::optional<int> value_int;
+ std::optional<float> value_float;
+ std::optional<bool> value_bool;
+ std::optional<ObjectCellValue> value_object;
+ std::optional<CollectionCellValue> value_collection;
};
/**
diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_from_geometry.cc b/source/blender/editors/space_spreadsheet/spreadsheet_from_geometry.cc
index f5a4f09a5a2..590fbfb5024 100644
--- a/source/blender/editors/space_spreadsheet/spreadsheet_from_geometry.cc
+++ b/source/blender/editors/space_spreadsheet/spreadsheet_from_geometry.cc
@@ -54,12 +54,12 @@ static void add_columns_for_instances(const InstancesComponent &instances_compon
const InstancedData &data = instance_data[index];
if (data.type == INSTANCE_DATA_TYPE_OBJECT) {
if (data.data.object != nullptr) {
- r_cell_value.value = ObjectCellValue{data.data.object};
+ r_cell_value.value_object = ObjectCellValue{data.data.object};
}
}
else if (data.type == INSTANCE_DATA_TYPE_COLLECTION) {
if (data.data.collection != nullptr) {
- r_cell_value.value = CollectionCellValue{data.data.collection};
+ r_cell_value.value_collection = CollectionCellValue{data.data.collection};
}
}
}));
@@ -71,7 +71,7 @@ static void add_columns_for_instances(const InstancesComponent &instances_compon
std::string name = std::string("Position ") + axis_char[i];
columns.append(spreadsheet_column_from_function(
name, [transforms, i](int index, CellValue &r_cell_value) {
- r_cell_value.value = transforms[index].translation()[i];
+ r_cell_value.value_float = transforms[index].translation()[i];
}));
}
@@ -79,7 +79,7 @@ static void add_columns_for_instances(const InstancesComponent &instances_compon
std::string name = std::string("Rotation ") + axis_char[i];
columns.append(spreadsheet_column_from_function(
name, [transforms, i](int index, CellValue &r_cell_value) {
- r_cell_value.value = transforms[index].to_euler()[i];
+ r_cell_value.value_float = transforms[index].to_euler()[i];
}));
}
@@ -87,7 +87,7 @@ static void add_columns_for_instances(const InstancesComponent &instances_compon
std::string name = std::string("Scale ") + axis_char[i];
columns.append(spreadsheet_column_from_function(
name, [transforms, i](int index, CellValue &r_cell_value) {
- r_cell_value.value = transforms[index].scale()[i];
+ r_cell_value.value_float = transforms[index].scale()[i];
}));
}
@@ -129,7 +129,7 @@ static void add_columns_for_attribute(const ReadAttribute *attribute,
attribute_name, [attribute](int index, CellValue &r_cell_value) {
float value;
attribute->get(index, &value);
- r_cell_value.value = value;
+ r_cell_value.value_float = value;
}));
break;
}
@@ -141,7 +141,7 @@ static void add_columns_for_attribute(const ReadAttribute *attribute,
name, [attribute, i](int index, CellValue &r_cell_value) {
float2 value;
attribute->get(index, &value);
- r_cell_value.value = value[i];
+ r_cell_value.value_float = value[i];
}));
}
break;
@@ -154,7 +154,7 @@ static void add_columns_for_attribute(const ReadAttribute *attribute,
name, [attribute, i](int index, CellValue &r_cell_value) {
float3 value;
attribute->get(index, &value);
- r_cell_value.value = value[i];
+ r_cell_value.value_float = value[i];
}));
}
break;
@@ -167,7 +167,7 @@ static void add_columns_for_attribute(const ReadAttribute *attribute,
name, [attribute, i](int index, CellValue &r_cell_value) {
Color4f value;
attribute->get(index, &value);
- r_cell_value.value = value[i];
+ r_cell_value.value_float = value[i];
}));
}
break;
@@ -177,7 +177,7 @@ static void add_columns_for_attribute(const ReadAttribute *attribute,
attribute_name, [attribute](int index, CellValue &r_cell_value) {
int value;
attribute->get(index, &value);
- r_cell_value.value = value;
+ r_cell_value.value_int = value;
}));
break;
}
@@ -186,7 +186,7 @@ static void add_columns_for_attribute(const ReadAttribute *attribute,
attribute_name, [attribute](int index, CellValue &r_cell_value) {
bool value;
attribute->get(index, &value);
- r_cell_value.value = value;
+ r_cell_value.value_bool = value;
}));
break;
}