[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 5423df7 25/46: Remove separate table_type_con
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 5423df7 25/46: Remove separate table_type_converter::type() |
Date: |
Wed, 22 Jul 2020 11:05:13 -0400 (EDT) |
branch: master
commit 5423df772d866b1c2dc798b5fbec4aa0da492b58
Author: Vadim Zeitlin <vadim@tt-solutions.com>
Commit: Vadim Zeitlin <vadim@tt-solutions.com>
Remove separate table_type_converter::type()
The difference between it and grid_value_type() was not obvious and
only the latter one is actually needed, so remove type() from the base
class and replace it with value-independent grid_type() for the custom
type converters for which it can be implemented generically, in terms of
typeid().
As table_custom_type_converter is now a template class, register_all()
can't be its method any longer, so just inline it at the point of use.
---
census_view.cpp | 94 +++++++++++++++++++--------------------------------------
1 file changed, 31 insertions(+), 63 deletions(-)
diff --git a/census_view.cpp b/census_view.cpp
index 484241e..e37eda6 100644
--- a/census_view.cpp
+++ b/census_view.cpp
@@ -1171,14 +1171,8 @@ class table_type_converter
return value.ToStdString(wxConvUTF8);
}
- // Returns the name of derived type.
- virtual char const* type() const = 0;
-
// Returns the grid value type, used by wxGridTypeRegistry.
- virtual wxString grid_value_type(any_member<Input> const&) const
- {
- return type();
- }
+ virtual wxString grid_value_type(any_member<Input> const& value) const = 0;
static table_type_converter const& get(any_member<Input> const& value);
@@ -1188,22 +1182,36 @@ class table_type_converter
};
// The base class for table type converters using custom renderer and editor.
+// It uses CRTP pattern, i.e. the derived class should pass itself as the
+// template parameter to this one.
+template<typename T>
class table_custom_type_converter : public table_type_converter
{
public:
- static void register_all(wxGrid* grid);
+ wxString grid_value_type(any_member<Input> const&) const override
+ {
+ return grid_type();
+ }
- private:
void register_data_type(wxGrid* grid) const
{
grid->RegisterDataType
- (type()
+ (grid_type()
,create_renderer()
,create_editor()
);
}
+ private:
+ // Currently the grid data type used for custom converters doesn't depend
+ // on the concrete value, which allows us to define this function and use
+ // it in both grid_value_type() and register_data_type().
+ wxString grid_type() const
+ {
+ return typeid(T).name();
+ }
+
virtual wxGridCellRenderer* create_renderer() const = 0;
virtual wxGridCellEditor* create_editor() const = 0;
@@ -1219,11 +1227,6 @@ class table_bool_converter : public table_type_converter
wxGridCellBoolEditor::UseStringValues("Yes", "No");
}
- char const* type() const override
- {
- return typeid(table_bool_converter).name();
- }
-
wxString grid_value_type(any_member<Input> const&) const override
{
return wxGRID_VALUE_BOOL;
@@ -1235,11 +1238,6 @@ class table_bool_converter : public table_type_converter
class table_enum_converter : public table_type_converter
{
public:
- char const* type() const override
- {
- return typeid(table_enum_converter).name();
- }
-
wxString grid_value_type(any_member<Input> const& value) const override
{
wxString type = wxGRID_VALUE_CHOICE;
@@ -1260,14 +1258,9 @@ class table_enum_converter : public table_type_converter
// class table_sequence_converter
-class table_sequence_converter : public table_custom_type_converter
+class table_sequence_converter
+ :public table_custom_type_converter<table_sequence_converter>
{
- public:
- char const* type() const override
- {
- return typeid(table_sequence_converter).name();
- }
-
private:
wxGridCellRenderer* create_renderer() const override
{
@@ -1285,11 +1278,6 @@ class table_sequence_converter : public
table_custom_type_converter
class table_int_range_converter : public table_type_converter
{
public:
- char const* type() const override
- {
- return typeid(table_int_range_converter).name();
- }
-
wxString grid_value_type(any_member<Input> const& value) const override
{
auto const* as_range = member_cast<tn_range_base>(value);
@@ -1305,14 +1293,9 @@ class table_int_range_converter : public
table_type_converter
// class table_double_range_converter
-class table_double_range_converter : public table_custom_type_converter
+class table_double_range_converter
+ :public table_custom_type_converter<table_double_range_converter>
{
- public:
- char const* type() const override
- {
- return typeid(table_double_range_converter).name();
- }
-
private:
wxGridCellRenderer* create_renderer() const override
{
@@ -1329,7 +1312,8 @@ class table_double_range_converter : public
table_custom_type_converter
// class table_date_converter
-class table_date_converter : public table_custom_type_converter
+class table_date_converter
+ :public table_custom_type_converter<table_date_converter>
{
public:
wxString to_renderer_value(std::string const& value) const override
@@ -1347,11 +1331,6 @@ class table_date_converter : public
table_custom_type_converter
return value_cast<std::string>(ConvertDateFromWx(date));
}
- char const* type() const override
- {
- return typeid(table_date_converter).name();
- }
-
private:
wxGridCellRenderer* create_renderer() const override
{
@@ -1369,29 +1348,12 @@ class table_date_converter : public
table_custom_type_converter
class table_string_converter : public table_type_converter
{
public:
- char const* type() const override
- {
- return typeid(table_string_converter).name();
- }
-
wxString grid_value_type(any_member<Input> const&) const override
{
return wxGRID_VALUE_STRING;
}
};
-void
-table_custom_type_converter::register_all(wxGrid* grid)
-{
- // We could implement some kind of automatic registration, but it doesn't
- // seem to be worth it for now, as we only have a few custom converters,
- // all of which defined in this single file, so it's simpler to just list
- // them explicitly here.
- table_sequence_converter{}.register_data_type(grid);
- table_double_range_converter{}.register_data_type(grid);
- table_date_converter{}.register_data_type(grid);
-}
-
table_type_converter const&
table_type_converter::get(any_member<Input> const& value)
{
@@ -2022,7 +1984,13 @@ wxWindow* CensusGridView::CreateChildWindow()
grid_window_->DisableDragRowSize();
grid_window_->SelectRow(0);
- table_custom_type_converter::register_all(grid_window_);
+ // We could implement some kind of automatic registration, but it doesn't
+ // seem to be worth it for now, as we only have a few custom converters,
+ // all of which defined in this single file, so it's simpler to just list
+ // them explicitly here.
+ table_sequence_converter{}.register_data_type(grid_window_);
+ table_double_range_converter{}.register_data_type(grid_window_);
+ table_date_converter{}.register_data_type(grid_window_);
// Show headers.
document().Modify(false);
- [lmi-commits] [lmi] master 7b62d49 21/46: Rename table_type_converter::get_by_value() to just get(), (continued)
- [lmi-commits] [lmi] master 7b62d49 21/46: Rename table_type_converter::get_by_value() to just get(), Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master 1dacd5c 22/46: Move register_all() to table_custom_type_converter, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master a43eb0f 23/46: Add a comment explaining register_all() approach, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master 4dcae52 34/46: Don't change default wxGrid lines colour, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master 342b9f5 27/46: Always resize columns in CensusGridView::update_visible_columns(), Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master f217203 29/46: Rename "columns_count" to "old_columns_count" for consistency, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master 395e268 41/46: Remove unnecessary calls to Update() when toggling autosize, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master 713d56f 46/46: Fix defect introduced 20200608T2219Z: warning not suppressed, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master 6281a6d 20/46: Make object returned by table_type_converter::get_impl() const, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master b85da3e 24/46: Clarify the comment about CensusViewDataViewModel wrappers, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master 5423df7 25/46: Remove separate table_type_converter::type(),
Greg Chicares <=
- [lmi-commits] [lmi] master f82b136 31/46: Remove unnecessary make_cell_number_column_read_only() function, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master 9f1cb2e 39/46: Only auto-size columns when they change, not after each update, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master b3ac65b 43/46: Allow wxGrid to compute census view column sizes more efficiently, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master ece93a0 17/46: Make check for Alt-Enter more obvious in the code, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master b57ed4a 18/46: Remove deleted DatumSequenceEditor copy-related methods, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master 041ccfc 30/46: Optimize changing grid columns number too, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master 53a288a 33/46: Restore "delete_cells" update UI handler for CensusDVCView, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master 3c3d0c0 36/46: Explain grid customizations in the function creating it, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master 337d81f 37/46: Make UponDeleteCells() more efficient for large censuses, Greg Chicares, 2020/07/22
- [lmi-commits] [lmi] master 2922db9 44/46: Disallow single cell operations when non-current row is selected, Greg Chicares, 2020/07/22