[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi] access to mc_enum type information [patch 1/3]
From: |
Vaclav Slavik |
Subject: |
[lmi] access to mc_enum type information [patch 1/3] |
Date: |
Tue, 29 Mar 2011 20:40:06 +0200 |
User-agent: |
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 |
Hi,
I've hit a small problem when implementing inline editing of cell values in
CensusView: I need to know the type of values displayed in given column, in
order to determine what the appropriate editor control is. For example,
enums should use a wxChoice control, boolean values should use checkboxes,
input sequences should use their own editor etc.
This information is exposed via any_member<>::type(), but that's not enough
for me, unfortunately: I need to identify all enums or tn_range types and it's
impractical to test for every type derived from mc_enum_base. And I can't use
member_cast<mc_enum_base>, because it throws on failure.
Here's a series of three patches that together address this problem; with
them, I'm able to create appropriate wxChoice control for any mc_enum<>
field. Are these changes OK?
Thanks,
Vaclav
[PATCH 1/3] Add virtual mc_enum_base::get_all_strings().
This is a companion to static mc_enum<T>::all_strings() and returns
the same thing. Unlike all_strings(), it's virtual and so can be called
without knowing the exact enum type.
---
ce_product_name.cpp | 5 +++++
ce_product_name.hpp | 2 ++
mc_enum.hpp | 3 +++
mc_enum.tpp | 6 ++++++
4 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/ce_product_name.cpp b/ce_product_name.cpp
index ce5b523..16678ac 100644
--- a/ce_product_name.cpp
+++ b/ce_product_name.cpp
@@ -114,6 +114,11 @@ std::vector<std::string> const&
ce_product_name::product_names()
return ::product_names();
}
+std::vector<std::string> const& ce_product_name::get_all_strings() const
+{
+ return product_names();
+}
+
std::istream& ce_product_name::read(std::istream& is)
{
std::locale old_locale = is.imbue(blank_is_not_whitespace_locale());
diff --git a/ce_product_name.hpp b/ce_product_name.hpp
index 809a11b..213471a 100644
--- a/ce_product_name.hpp
+++ b/ce_product_name.hpp
@@ -89,6 +89,8 @@ class ce_product_name
std::string str() const;
std::string value() const;
+ virtual std::vector<std::string> const& get_all_strings() const;
+
private:
static std::vector<std::string> const& product_names();
diff --git a/mc_enum.hpp b/mc_enum.hpp
index 8c3ef92..6fea532 100644
--- a/mc_enum.hpp
+++ b/mc_enum.hpp
@@ -71,6 +71,8 @@ class LMI_SO mc_enum_base
virtual std::size_t ordinal() const = 0;
virtual std::string str(int) const = 0;
+ virtual std::vector<std::string> const& get_all_strings() const = 0;
+
private:
std::deque<bool> allowed_;
};
@@ -129,6 +131,7 @@ class mc_enum
T value() const;
static std::vector<std::string> const& all_strings();
+ virtual std::vector<std::string> const& get_all_strings() const;
private:
static std::size_t n();
diff --git a/mc_enum.tpp b/mc_enum.tpp
index d8ab517..269b723 100644
--- a/mc_enum.tpp
+++ b/mc_enum.tpp
@@ -236,3 +236,9 @@ std::vector<std::string> const& mc_enum<T>::all_strings()
return v;
}
+template<typename T>
+std::vector<std::string> const& mc_enum<T>::get_all_strings() const
+{
+ return all_strings();
+}
+
- [lmi] access to mc_enum type information [patch 1/3],
Vaclav Slavik <=