lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master b957c49 1/9: Rewrite write_tsv()


From: Greg Chicares
Subject: [lmi-commits] [lmi] master b957c49 1/9: Rewrite write_tsv()
Date: Thu, 4 Oct 2018 19:24:14 -0400 (EDT)

branch: master
commit b957c49c80d06dab595db1b7baf02c2472eb6328
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Rewrite write_tsv()
    
    Reformatted a conditional statement. Reversed its sense, using it only
    to conditionalize an early exit. Outdented the former conditional block.
    Renamed a local variable. Reformatted a comment block.
---
 ledger_evaluator.cpp | 79 ++++++++++++++++++++++++++++------------------------
 1 file changed, 42 insertions(+), 37 deletions(-)

diff --git a/ledger_evaluator.cpp b/ledger_evaluator.cpp
index 42f43f9..cb90029 100644
--- a/ledger_evaluator.cpp
+++ b/ledger_evaluator.cpp
@@ -1003,48 +1003,53 @@ void ledger_evaluator::write_tsv
     ,Ledger   const& ledger
     ) const
 {
-    if(ledger.is_composite() && contains(global_settings::instance().pyx(), 
"values_tsv"))
+    if
+        (  !ledger.is_composite()
+        || !contains(global_settings::instance().pyx(), "values_tsv")
+        )
         {
-        configurable_settings const& z = configurable_settings::instance();
-        fs::path filepath
-            (   z.print_directory()
-            +   "/values"
-            +   z.spreadsheet_file_extension()
-            );
-        fs::ofstream ofs(filepath, ios_out_trunc_binary());
-
-        // Copy 'vectors_' to a (sorted) std::map in order to
-        // show columns alphabetically. Other, more complicated
-        // techniques are faster, but direct copying favors simplicity
-        // over speed--appropriately, as this facility is rarely used.
-        using map_t = std::map<std::string,std::vector<std::string>> const;
-        map_t sorted_stringvectors(vectors_.begin(), vectors_.end());
-
-        for(auto const& j : sorted_stringvectors)
-            {
-            ofs << j.first << '\t';
-            }
-        ofs << '\n';
+        return;
+        }
+
+    configurable_settings const& z = configurable_settings::instance();
+    fs::path filepath
+        (   z.print_directory()
+        +   "/values"
+        +   z.spreadsheet_file_extension()
+        );
+    fs::ofstream ofs(filepath, ios_out_trunc_binary());
+
+    // Copy 'vectors_' to a (sorted) std::map in order to show columns
+    // alphabetically. Other, more complicated techniques are faster,
+    // but direct copying favors simplicity over speed--appropriately,
+    // as this facility is rarely used.
+    using map_t = std::map<std::string,std::vector<std::string>> const;
+    map_t sorted_vectors(vectors_.begin(), vectors_.end());
+
+    for(auto const& j : sorted_vectors)
+        {
+        ofs << j.first << '\t';
+        }
+    ofs << '\n';
 
-        for(int i = 0; i < ledger.GetMaxLength(); ++i)
+    for(int i = 0; i < ledger.GetMaxLength(); ++i)
+        {
+        for(auto const& j : sorted_vectors)
             {
-            for(auto const& j : sorted_stringvectors)
+            std::vector<std::string> const& v = j.second;
+            if(i < lmi::ssize(v))
                 {
-                std::vector<std::string> const& v = j.second;
-                if(i < lmi::ssize(v))
-                    {
-                    ofs << v[i] << '\t';
-                    }
-                else
-                    {
-                    ofs << '\t';
-                    }
+                ofs << v[i] << '\t';
+                }
+            else
+                {
+                ofs << '\t';
                 }
-            ofs << '\n';
-            }
-        if(!ofs)
-            {
-            alarum() << "Unable to write '" << filepath << "'." << LMI_FLUSH;
             }
+        ofs << '\n';
+        }
+    if(!ofs)
+        {
+        alarum() << "Unable to write '" << filepath << "'." << LMI_FLUSH;
         }
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]