From 97e574d25992594f3b8ab0f0e56e8a1be12fe910 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Mon, 15 Mar 2021 10:00:15 -0600 Subject: [PATCH] vector calculate_value** --- Phreeqc.cpp | 28 ++++------------------------ Phreeqc.h | 4 +--- isotopes.cpp | 18 ++++-------------- mainsubs.cpp | 6 +----- structures.cpp | 8 ++------ tidy.cpp | 1 - 6 files changed, 12 insertions(+), 53 deletions(-) diff --git a/Phreeqc.cpp b/Phreeqc.cpp index e561642e..54bf7f4b 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -982,9 +982,6 @@ void Phreeqc::init(void) master_isotope = NULL; max_master_isotope = MAX_ELTS; initial_solution_isotopes = FALSE; - count_calculate_value = 0; - calculate_value = NULL; - max_calculate_value = MAX_ELTS; calculate_value_hash_table = NULL; count_isotope_ratio = 0; isotope_ratio = 0; @@ -2309,34 +2306,17 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) } } initial_solution_isotopes = pSrc->initial_solution_isotopes; - /* - count_calculate_value = 0; - calculate_value = NULL; - max_calculate_value = MAX_ELTS; - calculate_value_hash_table = NULL; - */ - for (int i = 0; i < pSrc->count_calculate_value; i++) + + for (int i = 0; i < pSrc->calculate_value.size(); i++) { - struct calculate_value *calculate_value_ptr = calculate_value_store(pSrc->calculate_value[i]->name, FALSE); - //memcpy(calculate_value_ptr, pSrc->calculate_value[i], sizeof(struct calculate_value)); + struct calculate_value* calculate_value_ptr = calculate_value_store(pSrc->calculate_value[i]->name, FALSE); calculate_value_ptr->value = pSrc->calculate_value[i]->value; - //calculate_value_ptr->commands = NULL; if (pSrc->calculate_value[i]->commands) { calculate_value_ptr->commands = string_duplicate(pSrc->calculate_value[i]->commands); } - //calculate_value_ptr->new_def = TRUE; - //calculate_value_ptr->calculated = FALSE; - //calculate_value_ptr->linebase = NULL; - //calculate_value_ptr->varbase = NULL; - //calculate_value_ptr->loopbase = NULL; } - /* - count_isotope_ratio = 0; - isotope_ratio = 0; - max_isotope_ratio = MAX_ELTS; - isotope_ratio_hash_table = 0; - */ + for (int i = 0; i < pSrc->count_isotope_ratio; i++) { struct isotope_ratio *isotope_ratio_ptr = isotope_ratio_store(pSrc->isotope_ratio[i]->name, FALSE); diff --git a/Phreeqc.h b/Phreeqc.h index 530af68a..6562717e 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1731,9 +1731,7 @@ protected: struct master_isotope **master_isotope; int max_master_isotope; int initial_solution_isotopes; - int count_calculate_value; - struct calculate_value **calculate_value; - int max_calculate_value; + std::vector calculate_value; HashTable *calculate_value_hash_table; int count_isotope_ratio; struct isotope_ratio **isotope_ratio; diff --git a/isotopes.cpp b/isotopes.cpp index 1fada086..9e4f28ac 100644 --- a/isotopes.cpp +++ b/isotopes.cpp @@ -892,11 +892,7 @@ punch_calculate_values(void) if (current_selected_output->Get_calculate_values().size() == 0) return OK; - //if (punch.in == FALSE || punch.calculate_values == FALSE) - // return (OK); - //if (punch.count_calculate_values == 0) - // return (OK); - //for (i = 0; i < punch.count_calculate_values; i++) + for (size_t i = 0; i < current_selected_output->Get_calculate_values().size(); i++) { result = MISSING; @@ -1132,7 +1128,7 @@ calculate_values(void) /* * initialize ratios as missing */ - for (j = 0; j < count_calculate_value; j++) + for (j = 0; j < calculate_value.size(); j++) { calculate_value[j]->calculated = FALSE; calculate_value[j]->value = MISSING; @@ -1522,14 +1518,8 @@ calculate_value_store(const char *name, int replace_if_found) } else { - n = count_calculate_value++; - /* make sure there is space in s */ - if (count_calculate_value >= max_calculate_value) - { - space((void **) ((void *) &calculate_value), - count_calculate_value, &max_calculate_value, - sizeof(struct calculate_value *)); - } + n = (int)calculate_value.size(); + calculate_value.resize((size_t)n+1); /* Make new calculate_value structure */ calculate_value[n] = calculate_value_alloc(); calculate_value_ptr = calculate_value[n]; diff --git a/mainsubs.cpp b/mainsubs.cpp index 877a3984..9df03df9 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -177,11 +177,7 @@ initialize(void) #endif /* calculate_value */ - max_calculate_value = MAX_ELTS; - count_calculate_value = 0; - space((void **) ((void *) &calculate_value), INIT, &max_calculate_value, - sizeof(struct calculate_value *)); - hcreate_multi((unsigned) max_calculate_value, + hcreate_multi((unsigned) MAX_ELTS, &calculate_value_hash_table); /* isotope_ratio */ diff --git a/structures.cpp b/structures.cpp index 6ffe4445..bef9008e 100644 --- a/structures.cpp +++ b/structures.cpp @@ -236,14 +236,11 @@ clean_up(void) master_isotope_hash_table = NULL; /* calculate_value */ - for (i = 0; i < count_calculate_value; i++) + for (i = 0; i < (int) calculate_value.size(); i++) { calculate_value_free(calculate_value[i]); - calculate_value[i] = - (struct calculate_value *) free_check_null(calculate_value[i]); + calculate_value[i] = (struct calculate_value*)free_check_null(calculate_value[i]); } - calculate_value = - (struct calculate_value **) free_check_null(calculate_value); hdestroy_multi(calculate_value_hash_table); calculate_value_hash_table = NULL; @@ -334,7 +331,6 @@ clean_up(void) llnl_count_bdot = 0; llnl_count_co2_coefs = 0; - count_calculate_value = 0; count_isotope_ratio = 0; count_isotope_alpha = 0; diff --git a/tidy.cpp b/tidy.cpp index 453aaaa5..665e8a5f 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -2227,7 +2227,6 @@ tidy_punch(void) /* calculate_values */ - //for (i = 0; i < punch.count_calculate_values; i++) for (size_t i = 0; i < current_selected_output->Get_calculate_values().size(); i++) { std::pair< std::string, void *> &pair_ref = current_selected_output->Get_calculate_values()[i];