From 79956e3d9ffcae4885bb46b893d01f311100dca1 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Mon, 26 Apr 2021 23:38:21 -0600 Subject: [PATCH] made tally_table a vector of class tally --- Phreeqc.cpp | 2 +- Phreeqc.h | 3 ++- tally.cpp | 22 ++++++++++++---------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 1e71ab9e..343c8e15 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -1109,7 +1109,7 @@ void Phreeqc::init(void) /* tally.cpp ------------------------------- */ t_buffer = NULL; tally_count_component = 0; - tally_table = NULL; + //tally_table = NULL; count_tally_table_columns = 0; count_tally_table_rows = 0; /* transport.cpp ------------------------------- */ diff --git a/Phreeqc.h b/Phreeqc.h index c91b6ed0..30982a91 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1769,7 +1769,8 @@ protected: /* tally.cpp ------------------------------- */ class tally_buffer* t_buffer; size_t tally_count_component; - class tally* tally_table; + //class tally* tally_table; + std::vector tally_table; size_t count_tally_table_columns; size_t count_tally_table_rows; diff --git a/tally.cpp b/tally.cpp index e8e9967e..969b165d 100644 --- a/tally.cpp +++ b/tally.cpp @@ -172,7 +172,8 @@ store_tally_table(LDBLE * l_array, int row_dim_in, int col_dim, LDBLE fill_facto { int i, j; int row_dim = row_dim_in + 1; - if (tally_table == NULL) + //if (tally_table == NULL) + if (tally_table.size() == 0) { input_error++; error_msg("Tally table not defined, get_tally_table_rows_columns", @@ -245,7 +246,7 @@ get_tally_table_rows_columns(int *rows, int *columns) { *rows = 0; *columns = 0; - if (tally_table == NULL) + if (tally_table.size() == 0) { input_error++; error_msg("tally table not defined, get_tally_table_rows_columns", @@ -266,7 +267,7 @@ get_tally_table_row_heading(int row, char *string) * row is C row number */ strcpy(string, ""); - if (tally_table == NULL) + if (tally_table.size() == 0) { input_error++; error_msg("Tally table not defined, get_tally_table row_heading", @@ -295,7 +296,7 @@ get_tally_table_column_heading(int column, int *type, char *string) */ *type = -1; strcpy(string, ""); - if (tally_table == NULL) + if (tally_table.size() == 0) { input_error++; error_msg("tally table not defined, get_tally_table_column_heading", @@ -321,7 +322,7 @@ free_tally_table(void) /* ---------------------------------------------------------------------- */ { int i, k; - if (tally_table == NULL) + if (tally_table.size() == 0) return (OK); for (i = 0; i < count_tally_table_columns; i++) { @@ -333,7 +334,7 @@ free_tally_table(void) tally_table[i].total[k]); } } - tally_table = (class tally *) free_check_null(tally_table); + //tally_table = (class tally *) free_check_null(tally_table); t_buffer = (class tally_buffer *) free_check_null(t_buffer); return (OK); } @@ -1214,10 +1215,11 @@ extend_tally_table(void) * adds another column to tally_table * increments number of columns */ - tally_table = (class tally *) PHRQ_realloc((void *) tally_table, - (count_tally_table_columns + 1) * sizeof(class tally)); - if (tally_table == NULL) - malloc_error(); + //tally_table = (class tally *) PHRQ_realloc((void *) tally_table, + // (count_tally_table_columns + 1) * sizeof(class tally)); + //if (tally_table == NULL) + // malloc_error(); + tally_table.resize(count_tally_table_columns + 1); for (i = 0; i < 3; i++) { tally_table[count_tally_table_columns].total[i] = (class tally_buffer *)