[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master c5b7e4a 4/4: Make a member a free function
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master c5b7e4a 4/4: Make a member a free function |
Date: |
Sun, 26 Feb 2017 12:39:01 -0500 (EST) |
branch: master
commit c5b7e4a025790c8c5cdb6631073933a5f4aa215e
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Make a member a free function
---
input_sequence.cpp | 74 ++++++++++++++++++++++++++++++++++--------------------
input_sequence.hpp | 2 --
2 files changed, 47 insertions(+), 29 deletions(-)
diff --git a/input_sequence.cpp b/input_sequence.cpp
index 4277d07..d3d44e9 100644
--- a/input_sequence.cpp
+++ b/input_sequence.cpp
@@ -51,6 +51,13 @@ void fill_interval_gaps
,std::string const& default_keyword
);
+void realize_intervals
+ (std::vector<ValueInterval> const& intervals
+ ,std::vector<std::string> & keyword_result
+ ,std::vector<double> & number_result
+ ,int years_to_maturity
+ );
+
void assert_sane_and_ordered_partition
(std::vector<ValueInterval> const& intervals
,int years_to_maturity
@@ -112,7 +119,13 @@ InputSequence::InputSequence
,a_default_keyword
);
- realize_intervals();
+ realize_intervals
+ (intervals_
+ ,keyword_result_
+ ,number_result_
+ ,years_to_maturity_
+ );
+
assert_sane_and_ordered_partition(intervals_, a_years_to_maturity);
}
@@ -430,32 +443,6 @@ std::vector<ValueInterval> const&
InputSequence::interval_representation() const
return intervals_;
}
-void InputSequence::realize_intervals()
-{
- for(auto const& interval_i : intervals_)
- {
- LMI_ASSERT(0 <= interval_i.begin_duration);
- LMI_ASSERT(interval_i.begin_duration <= interval_i.end_duration);
- LMI_ASSERT(interval_i.end_duration <= years_to_maturity_);
- if(interval_i.value_is_keyword)
- {
- std::fill
- (keyword_result_.begin() + interval_i.begin_duration
- ,keyword_result_.begin() + interval_i.end_duration
- ,interval_i.value_keyword
- );
- }
- else
- {
- std::fill
- (number_result_.begin() + interval_i.begin_duration
- ,number_result_.begin() + interval_i.end_duration
- ,interval_i.value_number
- );
- }
- }
-}
-
namespace
{
void assert_not_insane_or_disordered
@@ -636,6 +623,39 @@ void fill_interval_gaps
assert_sane_and_ordered_partition(out, years_to_maturity);
}
+/// Decode RLE intervals into keyword and numeric vectors.
+
+void realize_intervals
+ (std::vector<ValueInterval> const& intervals
+ ,std::vector<std::string> & keyword_result
+ ,std::vector<double> & number_result
+ ,int years_to_maturity
+ )
+{
+ for(auto const& interval_i : intervals)
+ {
+ LMI_ASSERT(0 <= interval_i.begin_duration);
+ LMI_ASSERT(interval_i.begin_duration <= interval_i.end_duration);
+ LMI_ASSERT(interval_i.end_duration <= years_to_maturity);
+ if(interval_i.value_is_keyword)
+ {
+ std::fill
+ (keyword_result.begin() + interval_i.begin_duration
+ ,keyword_result.begin() + interval_i.end_duration
+ ,interval_i.value_keyword
+ );
+ }
+ else
+ {
+ std::fill
+ (number_result.begin() + interval_i.begin_duration
+ ,number_result.begin() + interval_i.end_duration
+ ,interval_i.value_number
+ );
+ }
+ }
+}
+
/// Assert postconditions established by all ctors.
///
/// What is actually asserted here, for now at least, is only that the
diff --git a/input_sequence.hpp b/input_sequence.hpp
index 3279e47..7581668 100644
--- a/input_sequence.hpp
+++ b/input_sequence.hpp
@@ -174,8 +174,6 @@ class LMI_SO InputSequence
template<typename T>
void initialize_from_vector(std::vector<T> const&);
- void realize_intervals();
-
int years_to_maturity_;
int issue_age_;