[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 39d1ed2: Revert to brute simplicity
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 39d1ed2: Revert to brute simplicity |
Date: |
Wed, 8 Feb 2017 13:43:19 -0500 (EST) |
branch: master
commit 39d1ed2673b2d35724222a19c5a59ca33f96136e
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Revert to brute simplicity
See:
http://lists.nongnu.org/archive/html/lmi/2017-02/msg00030.html
---
input_sequence.cpp | 34 ++++++++++++++++++++++------------
input_sequence.hpp | 4 ----
2 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/input_sequence.cpp b/input_sequence.cpp
index 04c0f6b..957e705 100644
--- a/input_sequence.cpp
+++ b/input_sequence.cpp
@@ -50,16 +50,6 @@ ValueInterval::ValueInterval()
,insane (false)
{}
-void ValueInterval::value(double d)
-{
- value_number = d;
-}
-
-void ValueInterval::value(std::string const& s)
-{
- value_keyword = s;
-}
-
SequenceParser::SequenceParser
(std::string const& input_expression
,int a_years_to_maturity
@@ -809,6 +799,26 @@ InputSequence::InputSequence(std::vector<std::string>
const& v)
realize_intervals();
}
+namespace
+{
+// Naturally {value_number, value_keyword} constitute a discriminated
+// union: perhaps std::variant when lmi someday requires C++17. See:
+// http://lists.nongnu.org/archive/html/lmi/2017-02/msg00025.html
+// Until then...
+
+void set_value(ValueInterval& v, double d)
+{
+ LMI_ASSERT(!v.value_is_keyword);
+ v.value_number = d;
+}
+
+void set_value(ValueInterval& v, std::string const& s)
+{
+ LMI_ASSERT(v.value_is_keyword);
+ v.value_keyword = s;
+}
+} // Unnamed namespace.
+
// Constructors taking only one (vector) argument are used to convert
// flat vectors with one value per year to input sequences, compacted
// with run-length encoding.
@@ -847,7 +857,7 @@ void InputSequence::initialize_from_vector(std::vector<T>
const& v)
T current_value = prior_value;
intervals_.push_back(dummy);
- intervals_.back().value(current_value);
+ set_value(intervals_.back(), current_value);
for(auto const& vi : v)
{
@@ -860,7 +870,7 @@ void InputSequence::initialize_from_vector(std::vector<T>
const& v)
{
int value_change_duration = intervals_.back().end_duration;
intervals_.push_back(dummy);
- intervals_.back().value(current_value);
+ set_value(intervals_.back(), current_value);
intervals_.back().begin_duration = value_change_duration;
intervals_.back().end_duration = ++value_change_duration;
prior_value = current_value;
diff --git a/input_sequence.hpp b/input_sequence.hpp
index d0f7071..cc10a54 100644
--- a/input_sequence.hpp
+++ b/input_sequence.hpp
@@ -158,10 +158,6 @@ struct ValueInterval
{
ValueInterval();
- // Should this struct become a class because these members have been added?
- void value(double);
- void value(std::string const&);
-
double value_number;
std::string value_keyword;
bool value_is_keyword;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [lmi] master 39d1ed2: Revert to brute simplicity,
Greg Chicares <=