From faf8197aadbc69f8069a8b7aa2911b478cc38ea6 Mon Sep 17 00:00:00 2001 From: Eugen Betke Date: Wed, 18 Sep 2024 13:59:39 +0200 Subject: [PATCH] Modernisation: Make accessor member variables private (except BURF and base classes) --- ...grib_accessor_class_bufr_elements_table.cc | 32 ++--- .../grib_accessor_class_bufr_elements_table.h | 7 +- ...accessor_class_bufr_extract_area_subsets.h | 1 + ...ssor_class_bufr_extract_datetime_subsets.h | 1 + ...grib_accessor_class_bufr_extract_subsets.h | 1 + ...rib_accessor_class_bufr_simple_thinning.cc | 20 ++- ...grib_accessor_class_bufr_simple_thinning.h | 4 +- .../grib_accessor_class_bufr_string_values.cc | 13 +- .../grib_accessor_class_bufr_string_values.h | 4 +- ...cessor_class_bufrdc_expanded_descriptors.h | 1 + .../grib_accessor_class_cf_var_name.h | 2 +- src/accessor/grib_accessor_class_codeflag.cc | 17 ++- src/accessor/grib_accessor_class_codeflag.h | 4 +- src/accessor/grib_accessor_class_codetable.cc | 36 ++--- src/accessor/grib_accessor_class_codetable.h | 5 + src/accessor/grib_accessor_class_constant.h | 1 + .../grib_accessor_class_data_apply_bitmap.cc | 39 +++--- .../grib_accessor_class_data_apply_bitmap.h | 4 +- ...cessor_class_data_apply_boustrophedonic.cc | 33 +++-- ...ccessor_class_data_apply_boustrophedonic.h | 4 +- .../grib_accessor_class_data_ccsds_packing.cc | 43 +++--- .../grib_accessor_class_data_ccsds_packing.h | 4 +- ...ass_data_g1second_order_general_packing.cc | 41 +++--- ...lass_data_g1second_order_general_packing.h | 4 +- ..._data_g1second_order_row_by_row_packing.cc | 63 +++++---- ...s_data_g1second_order_row_by_row_packing.h | 4 +- ...ib_accessor_class_data_g22order_packing.cc | 61 ++++----- ...rib_accessor_class_data_g22order_packing.h | 4 +- ...accessor_class_data_g2bifourier_packing.cc | 67 +++------ ..._accessor_class_data_g2bifourier_packing.h | 33 ++++- ...b_accessor_class_data_run_length_packing.h | 2 +- .../grib_accessor_class_dictionary.cc | 30 ++-- src/accessor/grib_accessor_class_dictionary.h | 4 +- ...grib_accessor_class_expanded_descriptors.h | 1 + .../grib_accessor_class_g1forecastmonth.cc | 25 ++-- .../grib_accessor_class_g1forecastmonth.h | 4 +- .../grib_accessor_class_g2_mars_labeling.cc | 33 +++-- .../grib_accessor_class_g2_mars_labeling.h | 4 +- .../grib_accessor_class_g2end_step.cc | 128 +++++++++--------- src/accessor/grib_accessor_class_g2end_step.h | 8 +- src/accessor/grib_accessor_class_gen.h | 2 +- .../grib_accessor_class_hash_array.cc | 31 ++--- src/accessor/grib_accessor_class_hash_array.h | 4 +- src/accessor/grib_accessor_class_iterator.h | 4 +- src/accessor/grib_accessor_class_nearest.h | 4 +- ...ccessor_class_number_of_points_gaussian.cc | 58 ++++---- ...accessor_class_number_of_points_gaussian.h | 5 +- .../grib_accessor_class_signed_bits.cc | 17 ++- .../grib_accessor_class_signed_bits.h | 4 +- .../grib_accessor_class_smart_table.cc | 68 +++++----- .../grib_accessor_class_smart_table.h | 8 +- src/accessor/grib_accessor_class_spd.cc | 19 ++- src/accessor/grib_accessor_class_spd.h | 4 +- .../grib_accessor_class_step_in_units.cc | 21 ++- .../grib_accessor_class_step_in_units.h | 4 +- .../grib_accessor_class_suppressed.cc | 23 ++-- src/accessor/grib_accessor_class_suppressed.h | 4 +- .../grib_accessor_class_unsigned_bits.cc | 19 ++- .../grib_accessor_class_unsigned_bits.h | 4 +- src/accessor/grib_accessor_class_variable.h | 4 +- 60 files changed, 573 insertions(+), 526 deletions(-) diff --git a/src/accessor/grib_accessor_class_bufr_elements_table.cc b/src/accessor/grib_accessor_class_bufr_elements_table.cc index 244d42f7b..e286ae3d4 100644 --- a/src/accessor/grib_accessor_class_bufr_elements_table.cc +++ b/src/accessor/grib_accessor_class_bufr_elements_table.cc @@ -55,9 +55,8 @@ void grib_accessor_bufr_elements_table_t::init(const long len, grib_arguments* p flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err) +grib_trie* grib_accessor_bufr_elements_table_t::load_bufr_elements_table(int* err) { - grib_accessor_bufr_elements_table_t* self = (grib_accessor_bufr_elements_table_t*)a; char* filename = NULL; char line[1024] = { 0, @@ -83,17 +82,17 @@ static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err) size_t len = 1024; grib_trie* dictionary = NULL; FILE* f = NULL; - grib_handle* h = grib_handle_of_accessor(a); - grib_context* c = a->context_; + grib_handle* h = grib_handle_of_accessor(this); + grib_context* c = context_; *err = GRIB_SUCCESS; len = 1024; - if (self->masterDir_ != NULL) - grib_get_string(h, self->masterDir_, masterDir, &len); + if (masterDir_ != NULL) + grib_get_string(h, masterDir_, masterDir, &len); len = 1024; - if (self->localDir_ != NULL) - grib_get_string(h, self->localDir_, localDir, &len); + if (localDir_ != NULL) + grib_get_string(h, localDir_, localDir, &len); GRIB_MUTEX_INIT_ONCE(&once, &init_mutex); GRIB_MUTEX_LOCK(&mutex1); @@ -102,19 +101,19 @@ static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err) char name[4096] = { 0, }; - snprintf(name, 4096, "%s/%s", masterDir, self->dictionary_); + snprintf(name, 4096, "%s/%s", masterDir, dictionary_); grib_recompose_name(h, NULL, name, masterRecomposed, 0); filename = grib_context_full_defs_path(c, masterRecomposed); } else { - filename = grib_context_full_defs_path(c, self->dictionary_); + filename = grib_context_full_defs_path(c, dictionary_); } if (*localDir != 0) { char localName[2048] = { 0, }; - snprintf(localName, 2048, "%s/%s", localDir, self->dictionary_); + snprintf(localName, 2048, "%s/%s", localDir, dictionary_); grib_recompose_name(h, NULL, localName, localRecomposed, 0); localFilename = grib_context_full_defs_path(c, localRecomposed); snprintf(dictName, 1024, "%s:%s", localFilename, filename); @@ -124,7 +123,7 @@ static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err) } if (!filename) { - grib_context_log(c, GRIB_LOG_ERROR, "Unable to find definition file %s", self->dictionary_); + grib_context_log(c, GRIB_LOG_ERROR, "Unable to find definition file %s", dictionary_); if (strlen(masterRecomposed) > 0) grib_context_log(c, GRIB_LOG_DEBUG, "master path=%s", masterRecomposed); if (strlen(localRecomposed) > 0) grib_context_log(c, GRIB_LOG_DEBUG, "local path=%s", localRecomposed); *err = GRIB_FILE_NOT_FOUND; @@ -138,7 +137,7 @@ static grib_trie* load_bufr_elements_table(grib_accessor* a, int* err) goto the_end; } else { - grib_context_log(c, GRIB_LOG_DEBUG, "using dictionary %s from file %s", self->dictionary_, filename); + grib_context_log(c, GRIB_LOG_DEBUG, "using dictionary %s from file %s", dictionary_, filename); } f = codes_fopen(filename, "r"); @@ -229,14 +228,14 @@ static long atol_fast(const char* input) return atol(input); } -static int bufr_get_from_table(grib_accessor* a, bufr_descriptor* v) +int grib_accessor_bufr_elements_table_t::bufr_get_from_table(bufr_descriptor* v) { int ret = 0; char** list = 0; char code[7] = { 0 }; const size_t codeLen = sizeof(code); - grib_trie* table = load_bufr_elements_table(a, &ret); + grib_trie* table = load_bufr_elements_table(&ret); if (ret) return ret; @@ -288,6 +287,7 @@ int bufr_descriptor_is_marker(bufr_descriptor* d) bufr_descriptor* accessor_bufr_elements_table_get_descriptor(grib_accessor* a, int code, int* err) { + grib_accessor_bufr_elements_table_t* self = (grib_accessor_bufr_elements_table_t*)a; grib_context* c; bufr_descriptor* v = NULL; @@ -310,7 +310,7 @@ bufr_descriptor* accessor_bufr_elements_table_get_descriptor(grib_accessor* a, i switch (v->F) { case 0: - *err = bufr_get_from_table(a, v); + *err = self->bufr_get_from_table(v); break; case 1: v->type = BUFR_DESCRIPTOR_TYPE_REPLICATION; diff --git a/src/accessor/grib_accessor_class_bufr_elements_table.h b/src/accessor/grib_accessor_class_bufr_elements_table.h index afe545034..36c566622 100644 --- a/src/accessor/grib_accessor_class_bufr_elements_table.h +++ b/src/accessor/grib_accessor_class_bufr_elements_table.h @@ -26,10 +26,15 @@ public: int value_count(long*) override; void init(const long, grib_arguments*) override; -public: +private: const char* dictionary_; const char* masterDir_; const char* localDir_; + + grib_trie* load_bufr_elements_table(int* err); + int bufr_get_from_table(bufr_descriptor* v); + + friend bufr_descriptor* accessor_bufr_elements_table_get_descriptor(grib_accessor* a, int code, int* err); }; int bufr_descriptor_is_marker(bufr_descriptor* d); diff --git a/src/accessor/grib_accessor_class_bufr_extract_area_subsets.h b/src/accessor/grib_accessor_class_bufr_extract_area_subsets.h index 325c857b3..5d8b07bb7 100644 --- a/src/accessor/grib_accessor_class_bufr_extract_area_subsets.h +++ b/src/accessor/grib_accessor_class_bufr_extract_area_subsets.h @@ -24,6 +24,7 @@ public: void init(const long, grib_arguments*) override; public: + // TODO(maee): make private const char* doExtractSubsets_; const char* numberOfSubsets_; const char* extractSubsetList_; diff --git a/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.h b/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.h index 553866caf..cdfbecab9 100644 --- a/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.h +++ b/src/accessor/grib_accessor_class_bufr_extract_datetime_subsets.h @@ -24,6 +24,7 @@ public: void init(const long, grib_arguments*) override; public: + // TODO(maee): make private const char* doExtractSubsets_; const char* numberOfSubsets_; const char* extractSubsetList_; diff --git a/src/accessor/grib_accessor_class_bufr_extract_subsets.h b/src/accessor/grib_accessor_class_bufr_extract_subsets.h index 3915195c6..94019bc58 100644 --- a/src/accessor/grib_accessor_class_bufr_extract_subsets.h +++ b/src/accessor/grib_accessor_class_bufr_extract_subsets.h @@ -24,6 +24,7 @@ public: void init(const long, grib_arguments*) override; public: + // TODO(maee): make private const char* numericValues_; const char* pack_; grib_accessor* numericValuesAccessor_; diff --git a/src/accessor/grib_accessor_class_bufr_simple_thinning.cc b/src/accessor/grib_accessor_class_bufr_simple_thinning.cc index 451d3a6c7..543e1d97b 100644 --- a/src/accessor/grib_accessor_class_bufr_simple_thinning.cc +++ b/src/accessor/grib_accessor_class_bufr_simple_thinning.cc @@ -36,12 +36,10 @@ long grib_accessor_bufr_simple_thinning_t::get_native_type() return GRIB_TYPE_LONG; } -static int apply_thinning(grib_accessor* a) +int grib_accessor_bufr_simple_thinning_t::apply_thinning() { - const grib_accessor_bufr_simple_thinning_t* self = (grib_accessor_bufr_simple_thinning_t*)a; - long skip; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); grib_context* c = h->context; long compressed = 0, nsubsets; grib_iarray* subsets; @@ -53,21 +51,21 @@ static int apply_thinning(grib_accessor* a) return ret; if (compressed) { long numberOfSubsets = 0; - ret = grib_get_long(h, self->numberOfSubsets_, &numberOfSubsets); + ret = grib_get_long(h, numberOfSubsets_, &numberOfSubsets); if (ret) return ret; - ret = grib_get_long(h, self->simpleThinningStart_, &start); + ret = grib_get_long(h, simpleThinningStart_, &start); if (ret) return ret; - ret = grib_get_long(h, self->simpleThinningSkip_, &skip); + ret = grib_get_long(h, simpleThinningSkip_, &skip); if (ret) return ret; if (skip <= 0) return GRIB_INVALID_KEY_VALUE; - ret = grib_get_long(h, self->simpleThinningMissingRadius_, &radius); + ret = grib_get_long(h, simpleThinningMissingRadius_, &radius); if (ret) return ret; @@ -80,7 +78,7 @@ static int apply_thinning(grib_accessor* a) if (nsubsets != 0) { subsets_ar = grib_iarray_get_array(subsets); - ret = grib_set_long_array(h, self->extractSubsetList_, subsets_ar, nsubsets); + ret = grib_set_long_array(h, extractSubsetList_, subsets_ar, nsubsets); grib_context_free(c, subsets_ar); if (ret) return ret; @@ -89,7 +87,7 @@ static int apply_thinning(grib_accessor* a) if (ret) return ret; - ret = grib_set_long(h, self->doExtractSubsets_, 1); + ret = grib_set_long(h, doExtractSubsets_, 1); if (ret) return ret; } @@ -106,7 +104,7 @@ int grib_accessor_bufr_simple_thinning_t::pack_long(const long* val, size_t* len { if (*len == 0) return GRIB_SUCCESS; - int err = apply_thinning(this); + int err = apply_thinning(); if (err) return err; diff --git a/src/accessor/grib_accessor_class_bufr_simple_thinning.h b/src/accessor/grib_accessor_class_bufr_simple_thinning.h index f28af36f7..612d41937 100644 --- a/src/accessor/grib_accessor_class_bufr_simple_thinning.h +++ b/src/accessor/grib_accessor_class_bufr_simple_thinning.h @@ -23,11 +23,13 @@ public: int pack_long(const long* val, size_t* len) override; void init(const long, grib_arguments*) override; -public: +private: const char* doExtractSubsets_; const char* numberOfSubsets_; const char* extractSubsetList_; const char* simpleThinningStart_; const char* simpleThinningMissingRadius_; const char* simpleThinningSkip_; + + int apply_thinning(); }; diff --git a/src/accessor/grib_accessor_class_bufr_string_values.cc b/src/accessor/grib_accessor_class_bufr_string_values.cc index 4f3cebeea..7b0fb2ccb 100644 --- a/src/accessor/grib_accessor_class_bufr_string_values.cc +++ b/src/accessor/grib_accessor_class_bufr_string_values.cc @@ -30,13 +30,12 @@ void grib_accessor_bufr_string_values_t::dump(grib_dumper* dumper) grib_dump_string_array(dumper, this, NULL); } -static grib_accessor* get_accessor(grib_accessor* a) +grib_accessor* grib_accessor_bufr_string_values_t::get_accessor() { - grib_accessor_bufr_string_values_t* self = (grib_accessor_bufr_string_values_t*)a; - if (!self->dataAccessor_) { - self->dataAccessor_ = grib_find_accessor(grib_handle_of_accessor(a), self->dataAccessorName_); + if (!dataAccessor_) { + dataAccessor_ = grib_find_accessor(grib_handle_of_accessor(this), dataAccessorName_); } - return self->dataAccessor_; + return dataAccessor_; } int grib_accessor_bufr_string_values_t::unpack_string_array(char** buffer, size_t* len) @@ -48,7 +47,7 @@ int grib_accessor_bufr_string_values_t::unpack_string_array(char** buffer, size_ size_t i, j, n = 0; char** b = buffer; - data = get_accessor(this); + data = get_accessor(); if (!data) return GRIB_NOT_FOUND; @@ -80,7 +79,7 @@ int grib_accessor_bufr_string_values_t::unpack_string(char* val, size_t* len) int grib_accessor_bufr_string_values_t::value_count(long* rlen) { - grib_accessor* descriptors = get_accessor(this); + grib_accessor* descriptors = get_accessor(); return descriptors->value_count(rlen); } diff --git a/src/accessor/grib_accessor_class_bufr_string_values.h b/src/accessor/grib_accessor_class_bufr_string_values.h index a3c4d50e0..e794213a4 100644 --- a/src/accessor/grib_accessor_class_bufr_string_values.h +++ b/src/accessor/grib_accessor_class_bufr_string_values.h @@ -26,7 +26,9 @@ public: void dump(grib_dumper*) override; void init(const long, grib_arguments*) override; -public: +private: const char* dataAccessorName_; grib_accessor* dataAccessor_; + + grib_accessor* get_accessor(); }; diff --git a/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.h b/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.h index c20cd2f74..d81149cb4 100644 --- a/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.h +++ b/src/accessor/grib_accessor_class_bufrdc_expanded_descriptors.h @@ -26,6 +26,7 @@ public: void init(const long, grib_arguments*) override; public: + // TODO(maee): make private const char* expandedDescriptors_; grib_accessor* expandedDescriptorsAccessor_; }; diff --git a/src/accessor/grib_accessor_class_cf_var_name.h b/src/accessor/grib_accessor_class_cf_var_name.h index f536bfec9..8073d91d1 100644 --- a/src/accessor/grib_accessor_class_cf_var_name.h +++ b/src/accessor/grib_accessor_class_cf_var_name.h @@ -22,7 +22,7 @@ public: size_t string_length() override; void init(const long, grib_arguments*) override; -public: +private: /* Members defined in cf_var_name */ const char* defaultKey_; }; diff --git a/src/accessor/grib_accessor_class_codeflag.cc b/src/accessor/grib_accessor_class_codeflag.cc index 95ca77364..6921c5b17 100644 --- a/src/accessor/grib_accessor_class_codeflag.cc +++ b/src/accessor/grib_accessor_class_codeflag.cc @@ -28,9 +28,8 @@ static int test_bit(long a, long b) return a & (1 << b); } -static int grib_get_codeflag(grib_accessor* a, long code, char* codename) +int grib_accessor_codeflag_t::grib_get_codeflag(long code, char* codename) { - const grib_accessor_codeflag_t* self = (grib_accessor_codeflag_t*)a; FILE* f = NULL; char fname[1024]; char bval[50]; @@ -41,21 +40,21 @@ static int grib_get_codeflag(grib_accessor* a, long code, char* codename) int j = 0; int err = 0; - err = grib_recompose_name(grib_handle_of_accessor(a), NULL, self->tablename_, fname, 1); + err = grib_recompose_name(grib_handle_of_accessor(this), NULL, tablename_, fname, 1); if (err) { - strncpy(fname, self->tablename_, sizeof(fname) - 1); + strncpy(fname, tablename_, sizeof(fname) - 1); fname[sizeof(fname) - 1] = '\0'; } - if ((filename = grib_context_full_defs_path(a->context_, fname)) == NULL) { - grib_context_log(a->context_, GRIB_LOG_WARNING, "Cannot open flag table %s", filename); + if ((filename = grib_context_full_defs_path(context_, fname)) == NULL) { + grib_context_log(context_, GRIB_LOG_WARNING, "Cannot open flag table %s", filename); strcpy(codename, "Cannot open flag table"); return GRIB_FILE_NOT_FOUND; } f = codes_fopen(filename, "r"); if (!f) { - grib_context_log(a->context_, (GRIB_LOG_WARNING) | (GRIB_LOG_PERROR), "Cannot open flag table %s", filename); + grib_context_log(context_, (GRIB_LOG_WARNING) | (GRIB_LOG_PERROR), "Cannot open flag table %s", filename); strcpy(codename, "Cannot open flag table"); return GRIB_FILE_NOT_FOUND; } @@ -68,7 +67,7 @@ static int grib_get_codeflag(grib_accessor* a, long code, char* codename) sscanf(line, "%49s %49s", num, bval); if (num[0] != '#') { - if ((test_bit(code, self->length_ * 8 - atol(num)) > 0) == atol(bval)) { + if ((test_bit(code, length_ * 8 - atol(num)) > 0) == atol(bval)) { size_t linelen = strlen(line); codename[j++] = '('; codename[j++] = num[0]; @@ -117,7 +116,7 @@ void grib_accessor_codeflag_t::dump(grib_dumper* dumper) grib_recompose_name(grib_handle_of_accessor(this), NULL, tablename_, fname, 1); unpack_long(&v, &llen); - grib_get_codeflag(this, v, flagname); + grib_get_codeflag(v, flagname); grib_dump_bits(dumper, this, flagname); } diff --git a/src/accessor/grib_accessor_class_codeflag.h b/src/accessor/grib_accessor_class_codeflag.h index fa394a650..af055fd2f 100644 --- a/src/accessor/grib_accessor_class_codeflag.h +++ b/src/accessor/grib_accessor_class_codeflag.h @@ -23,6 +23,8 @@ public: void dump(grib_dumper*) override; void init(const long, grib_arguments*) override; -public: +private: const char* tablename_; + + int grib_get_codeflag(long code, char* codename); }; diff --git a/src/accessor/grib_accessor_class_codetable.cc b/src/accessor/grib_accessor_class_codetable.cc index 884bbfe3b..39ab257b5 100644 --- a/src/accessor/grib_accessor_class_codetable.cc +++ b/src/accessor/grib_accessor_class_codetable.cc @@ -163,11 +163,11 @@ static void dump_codetable(grib_codetable* atable) } } #endif -static grib_codetable* load_table(grib_accessor* a) + +grib_codetable* grib_accessor_codetable_t::load_table() { - grib_accessor_codetable_t* self = (grib_accessor_codetable_t*)a; size_t size = 0; - grib_handle* h = ((grib_accessor*)self)->parent_->h; + grib_handle* h = parent_->h; grib_context* c = h->context; grib_codetable* t = NULL; grib_codetable* next = NULL; @@ -187,23 +187,23 @@ static grib_codetable* load_table(grib_accessor* a) }; size_t len = 1024; - if (self->masterDir_ != NULL) - grib_get_string(h, self->masterDir_, masterDir, &len); + if (masterDir_ != NULL) + grib_get_string(h, masterDir_, masterDir, &len); len = 1024; - if (self->localDir_ != NULL) - grib_get_string(h, self->localDir_, localDir, &len); + if (localDir_ != NULL) + grib_get_string(h, localDir_, localDir, &len); if (*masterDir != 0) { char name[2048] = { 0, }; - snprintf(name, sizeof(name), "%s/%s", masterDir, self->tablename_); + snprintf(name, sizeof(name), "%s/%s", masterDir, tablename_); grib_recompose_name(h, NULL, name, recomposed, 0); filename = grib_context_full_defs_path(c, recomposed); } else { - grib_recompose_name(h, NULL, self->tablename_, recomposed, 0); + grib_recompose_name(h, NULL, tablename_, recomposed, 0); filename = grib_context_full_defs_path(c, recomposed); } @@ -211,7 +211,7 @@ static grib_codetable* load_table(grib_accessor* a) char localName[2048] = { 0, }; - snprintf(localName, sizeof(localName), "%s/%s", localDir, self->tablename_); + snprintf(localName, sizeof(localName), "%s/%s", localDir, tablename_); grib_recompose_name(h, NULL, localName, localRecomposed, 0); localFilename = grib_context_full_defs_path(c, localRecomposed); } @@ -243,12 +243,12 @@ static grib_codetable* load_table(grib_accessor* a) next = next->next; } - if (self->flags_ & GRIB_ACCESSOR_FLAG_TRANSIENT) { - Assert(self->vvalue_ != NULL); - size = self->vvalue_->length * 8; + if (flags_ & GRIB_ACCESSOR_FLAG_TRANSIENT) { + Assert(vvalue_ != NULL); + size = vvalue_->length * 8; } else { - size = ((grib_accessor*)self)->byte_count() * 8; + size = byte_count() * 8; } size = (1ULL << size); /* 2^size - 64bits */ @@ -531,7 +531,7 @@ void grib_accessor_codetable_t::dump(grib_dumper* dumper) long value; if (!table_loaded_) { - table_ = load_table(this); /* may return NULL */ + table_ = load_table(); /* may return NULL */ table_loaded_ = 1; } table = table_; @@ -593,7 +593,7 @@ int grib_accessor_codetable_t::unpack_string(char* buffer, size_t* len) return err; if (!table_loaded_) { - table_ = load_table(this); /* may return NULL */ + table_ = load_table(); /* may return NULL */ table_loaded_ = 1; } table = table_; @@ -664,7 +664,7 @@ int grib_accessor_codetable_t::pack_string(const char* buffer, size_t* len) size_t size = 1; if (!table_loaded_) { - table_ = load_table(this); /* may return NULL */ + table_ = load_table(); /* may return NULL */ table_loaded_ = 1; } table = table_; @@ -812,7 +812,7 @@ int grib_accessor_codetable_t::unpack_long(long* val, size_t* len) rlen = 1; /* ECC-480 Performance: avoid func call overhead of grib_value_count */ if (!table_loaded_) { - table_ = load_table(this); /* may return NULL */ + table_ = load_table(); /* may return NULL */ table_loaded_ = 1; } diff --git a/src/accessor/grib_accessor_class_codetable.h b/src/accessor/grib_accessor_class_codetable.h index 644e0c2c7..e7224ec61 100644 --- a/src/accessor/grib_accessor_class_codetable.h +++ b/src/accessor/grib_accessor_class_codetable.h @@ -31,9 +31,14 @@ public: void init(const long, grib_arguments*) override; public: + // TODO(maee): make private grib_codetable* table_; + +private: const char* tablename_; const char* masterDir_; const char* localDir_; int table_loaded_; + + grib_codetable* load_table(); }; diff --git a/src/accessor/grib_accessor_class_constant.h b/src/accessor/grib_accessor_class_constant.h index b0e6bda1b..ea4a88c6a 100644 --- a/src/accessor/grib_accessor_class_constant.h +++ b/src/accessor/grib_accessor_class_constant.h @@ -17,4 +17,5 @@ public: grib_accessor_variable_t() { class_name_ = "constant"; } grib_accessor* create_empty_accessor() override { return new grib_accessor_constant_t{}; } void init(const long, grib_arguments*) override; + }; diff --git a/src/accessor/grib_accessor_class_data_apply_bitmap.cc b/src/accessor/grib_accessor_class_data_apply_bitmap.cc index 4913ec146..ec43d810f 100644 --- a/src/accessor/grib_accessor_class_data_apply_bitmap.cc +++ b/src/accessor/grib_accessor_class_data_apply_bitmap.cc @@ -232,10 +232,9 @@ int grib_accessor_data_apply_bitmap_t::pack_double(const double* val, size_t* le return err; } -template -static int unpack(grib_accessor* a, T* val, size_t* len) +template +int grib_accessor_data_apply_bitmap_t::unpack(T* val, size_t* len) { - grib_accessor_data_apply_bitmap_t* self = (grib_accessor_data_apply_bitmap_t*)a; static_assert(std::is_floating_point::value, "Requires floating point numbers"); size_t i = 0; @@ -246,18 +245,18 @@ static int unpack(grib_accessor* a, T* val, size_t* len) T* coded_vals = NULL; double missing_value = 0; - int err = a->value_count(&nn); + int err = value_count(&nn); n_vals = nn; if (err) return err; - if (!grib_find_accessor(grib_handle_of_accessor(a), self->bitmap_)) - return grib_get_array(grib_handle_of_accessor(a), self->coded_values_, val, len); + if (!grib_find_accessor(grib_handle_of_accessor(this), bitmap_)) + return grib_get_array(grib_handle_of_accessor(this), coded_values_, val, len); - if ((err = grib_get_size(grib_handle_of_accessor(a), self->coded_values_, &coded_n_vals)) != GRIB_SUCCESS) + if ((err = grib_get_size(grib_handle_of_accessor(this), coded_values_, &coded_n_vals)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(grib_handle_of_accessor(a), self->missing_value_, &missing_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(grib_handle_of_accessor(this), missing_value_, &missing_value)) != GRIB_SUCCESS) return err; if (*len < n_vals) { @@ -273,21 +272,21 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return GRIB_SUCCESS; } - if ((err = grib_get_array_internal(grib_handle_of_accessor(a), self->bitmap_, val, &n_vals)) != GRIB_SUCCESS) + if ((err = grib_get_array_internal(grib_handle_of_accessor(this), bitmap_, val, &n_vals)) != GRIB_SUCCESS) return err; - coded_vals = (T*)grib_context_malloc(a->context_, coded_n_vals * sizeof(T)); + coded_vals = (T*)grib_context_malloc(context_, coded_n_vals * sizeof(T)); if (coded_vals == NULL) return GRIB_OUT_OF_MEMORY; - if ((err = grib_get_array(grib_handle_of_accessor(a), self->coded_values_, coded_vals, &coded_n_vals)) != GRIB_SUCCESS) { - grib_context_free(a->context_, coded_vals); + if ((err = grib_get_array(grib_handle_of_accessor(this), coded_values_, coded_vals, &coded_n_vals)) != GRIB_SUCCESS) { + grib_context_free(context_, coded_vals); return err; } - grib_context_log(a->context_, GRIB_LOG_DEBUG, + grib_context_log(context_, GRIB_LOG_DEBUG, "grib_accessor_data_apply_bitmap: %s : creating %s, %d values", - __func__, a->name_, n_vals); + __func__, name_, n_vals); for (i = 0; i < n_vals; i++) { if (val[i] == 0) { @@ -296,11 +295,11 @@ static int unpack(grib_accessor* a, T* val, size_t* len) else { val[i] = coded_vals[j++]; if (j > coded_n_vals) { - grib_context_free(a->context_, coded_vals); - grib_context_log(a->context_, GRIB_LOG_ERROR, + grib_context_free(context_, coded_vals); + grib_context_log(context_, GRIB_LOG_ERROR, "grib_accessor_data_apply_bitmap [%s]:" " %s : number of coded values does not match bitmap %ld %ld", - a->name_, __func__, coded_n_vals, n_vals); + name_, __func__, coded_n_vals, n_vals); return GRIB_ARRAY_TOO_SMALL; } @@ -309,18 +308,18 @@ static int unpack(grib_accessor* a, T* val, size_t* len) *len = n_vals; - grib_context_free(a->context_, coded_vals); + grib_context_free(context_, coded_vals); return err; } int grib_accessor_data_apply_bitmap_t::unpack_double(double* val, size_t* len) { - return unpack(this, val, len); + return unpack(val, len); } int grib_accessor_data_apply_bitmap_t::unpack_float(float* val, size_t* len) { - return unpack(this, val, len); + return unpack(val, len); } long grib_accessor_data_apply_bitmap_t::get_native_type() diff --git a/src/accessor/grib_accessor_class_data_apply_bitmap.h b/src/accessor/grib_accessor_class_data_apply_bitmap.h index f91b24750..bfcc41e47 100644 --- a/src/accessor/grib_accessor_class_data_apply_bitmap.h +++ b/src/accessor/grib_accessor_class_data_apply_bitmap.h @@ -29,11 +29,13 @@ public: int unpack_double_element(size_t i, double* val) override; int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override; -public: +private: const char* coded_values_; const char* bitmap_; const char* missing_value_; const char* number_of_data_points_; const char* number_of_values_; const char* binary_scale_factor_; + + template int unpack(T* val, size_t* len); }; diff --git a/src/accessor/grib_accessor_class_data_apply_boustrophedonic.cc b/src/accessor/grib_accessor_class_data_apply_boustrophedonic.cc index 5f82ffeb2..b453bc7c9 100644 --- a/src/accessor/grib_accessor_class_data_apply_boustrophedonic.cc +++ b/src/accessor/grib_accessor_class_data_apply_boustrophedonic.cc @@ -39,9 +39,8 @@ int grib_accessor_data_apply_boustrophedonic_t::value_count(long* numberOfPoints } template -static int unpack(grib_accessor* a, T* val, size_t* len) +int grib_accessor_data_apply_boustrophedonic_t::unpack(T* val, size_t* len) { - grib_accessor_data_apply_boustrophedonic_t* self = (grib_accessor_data_apply_boustrophedonic_t*)a; size_t plSize = 0; long* pl = 0; double* values = 0; @@ -52,7 +51,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) int ret; long numberOfPoints, numberOfRows, numberOfColumns; - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfPoints_, &numberOfPoints); + ret = grib_get_long_internal(grib_handle_of_accessor(this), numberOfPoints_, &numberOfPoints); if (ret) return ret; @@ -61,7 +60,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return GRIB_ARRAY_TOO_SMALL; } - ret = grib_get_size(grib_handle_of_accessor(a), self->values_, &valuesSize); + ret = grib_get_size(grib_handle_of_accessor(this), values_, &valuesSize); if (ret) return ret; @@ -70,31 +69,31 @@ static int unpack(grib_accessor* a, T* val, size_t* len) return 0; if (valuesSize != numberOfPoints) { - grib_context_log(a->context_, GRIB_LOG_ERROR, "boustrophedonic ordering error: ( %s=%ld ) != (sizeOf(%s)=%ld)", - numberOfPoints, numberOfPoints, self->values_, (long)valuesSize); + grib_context_log(context_, GRIB_LOG_ERROR, "boustrophedonic ordering error: ( %s=%ld ) != (sizeOf(%s)=%ld)", + numberOfPoints, numberOfPoints, values_, (long)valuesSize); return GRIB_DECODING_ERROR; } - values = (double*)grib_context_malloc_clear(a->context_, sizeof(double) * numberOfPoints); - ret = grib_get_double_array_internal(grib_handle_of_accessor(a), self->values_, values, &valuesSize); + values = (double*)grib_context_malloc_clear(context_, sizeof(double) * numberOfPoints); + ret = grib_get_double_array_internal(grib_handle_of_accessor(this), values_, values, &valuesSize); if (ret) return ret; pvalues = values; pval = val; - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfRows_, &numberOfRows); + ret = grib_get_long_internal(grib_handle_of_accessor(this), numberOfRows_, &numberOfRows); if (ret) return ret; - ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfColumns_, &numberOfColumns); + ret = grib_get_long_internal(grib_handle_of_accessor(this), numberOfColumns_, &numberOfColumns); if (ret) return ret; - if (grib_get_size(grib_handle_of_accessor(a), self->pl_, &plSize) == GRIB_SUCCESS) { + if (grib_get_size(grib_handle_of_accessor(this), pl_, &plSize) == GRIB_SUCCESS) { Assert(plSize == numberOfRows); - pl = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * plSize); - ret = grib_get_long_array_internal(grib_handle_of_accessor(a), self->pl_, pl, &plSize); + pl = (long*)grib_context_malloc_clear(context_, sizeof(long) * plSize); + ret = grib_get_long_array_internal(grib_handle_of_accessor(this), pl_, pl, &plSize); if (ret) return ret; @@ -111,7 +110,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) } } - grib_context_free(a->context_, pl); + grib_context_free(context_, pl); } else { for (j = 0; j < numberOfRows; j++) { @@ -128,19 +127,19 @@ static int unpack(grib_accessor* a, T* val, size_t* len) } } - grib_context_free(a->context_, values); + grib_context_free(context_, values); return GRIB_SUCCESS; } int grib_accessor_data_apply_boustrophedonic_t::unpack_double(double* val, size_t* len) { - return unpack(this, val, len); + return unpack(val, len); } int grib_accessor_data_apply_boustrophedonic_t::unpack_float(float* val, size_t* len) { - return unpack(this, val, len); + return unpack(val, len); } int grib_accessor_data_apply_boustrophedonic_t::unpack_double_element(size_t idx, double* val) diff --git a/src/accessor/grib_accessor_class_data_apply_boustrophedonic.h b/src/accessor/grib_accessor_class_data_apply_boustrophedonic.h index da7898ddf..76aae84c6 100644 --- a/src/accessor/grib_accessor_class_data_apply_boustrophedonic.h +++ b/src/accessor/grib_accessor_class_data_apply_boustrophedonic.h @@ -28,10 +28,12 @@ public: int unpack_double_element(size_t i, double* val) override; int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override; -public: +private: const char* values_; const char* numberOfRows_; const char* numberOfColumns_; const char* numberOfPoints_; const char* pl_; + + template int unpack(T* val, size_t* len); }; diff --git a/src/accessor/grib_accessor_class_data_ccsds_packing.cc b/src/accessor/grib_accessor_class_data_ccsds_packing.cc index b26157f46..63b6cce35 100644 --- a/src/accessor/grib_accessor_class_data_ccsds_packing.cc +++ b/src/accessor/grib_accessor_class_data_ccsds_packing.cc @@ -377,12 +377,11 @@ cleanup: } template -static int unpack(grib_accessor* a, T* val, size_t* len) +int grib_accessor_data_ccsds_packing_t::unpack(T* val, size_t* len) { - grib_accessor_data_ccsds_packing_t* self = (grib_accessor_data_ccsds_packing_t*)a; static_assert(std::is_floating_point::value, "Requires floating point numbers"); - grib_handle* hand = grib_handle_of_accessor(a); - const char* cclass_name = a->class_name_; + grib_handle* hand = grib_handle_of_accessor(this); + const char* cclass_name = class_name_; int err = GRIB_SUCCESS, i = 0; size_t buflen = 0; @@ -406,28 +405,28 @@ static int unpack(grib_accessor* a, T* val, size_t* len) long ccsds_rsi; size_t nbytes; - a->dirty_ = 0; + dirty_ = 0; - if ((err = a->value_count(&nn)) != GRIB_SUCCESS) + if ((err = value_count(&nn)) != GRIB_SUCCESS) return err; n_vals = nn; - if ((err = grib_get_long_internal(hand, self->bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(hand, self->reference_value_, &reference_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(hand, reference_value_, &reference_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(hand, self->binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(hand, self->decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return err; // ECC-477: Don't call grib_get_long_internal to suppress error message being output - if ((err = grib_get_long(hand, self->ccsds_flags_, &ccsds_flags)) != GRIB_SUCCESS) + if ((err = grib_get_long(hand, ccsds_flags_, &ccsds_flags)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(hand, self->ccsds_block_size_, &ccsds_block_size)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, ccsds_block_size_, &ccsds_block_size)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(hand, self->ccsds_rsi_, &ccsds_rsi)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(hand, ccsds_rsi_, &ccsds_rsi)) != GRIB_SUCCESS) return err; modify_aec_flags(&ccsds_flags); @@ -447,9 +446,9 @@ static int unpack(grib_accessor* a, T* val, size_t* len) bscale = codes_power(binary_scale_factor, 2); dscale = codes_power(-decimal_scale_factor, 10); - buflen = self->byte_count(); + buflen = byte_count(); buf = (unsigned char*)hand->buffer->data; - buf += a->byte_offset(); + buf += byte_offset(); strm.flags = ccsds_flags; strm.bits_per_sample = bits_per_value; strm.block_size = ccsds_block_size; @@ -463,7 +462,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) nbytes = 4; size = n_vals * nbytes; - decoded = (unsigned char*)grib_context_buffer_malloc_clear(a->context_, size); + decoded = (unsigned char*)grib_context_buffer_malloc_clear(context_, size); if (!decoded) { err = GRIB_OUT_OF_MEMORY; goto cleanup; @@ -474,7 +473,7 @@ static int unpack(grib_accessor* a, T* val, size_t* len) if (hand->context->debug) print_aec_stream_info(&strm, "unpack_*"); if ((err = aec_buffer_decode(&strm)) != AEC_OK) { - grib_context_log(a->context_, GRIB_LOG_ERROR, "%s %s: aec_buffer_decode error %d (%s)", + grib_context_log(context_, GRIB_LOG_ERROR, "%s %s: aec_buffer_decode error %d (%s)", cclass_name, __func__, err, aec_get_error_message(err)); err = GRIB_DECODING_ERROR; goto cleanup; @@ -501,8 +500,8 @@ static int unpack(grib_accessor* a, T* val, size_t* len) } break; default: - grib_context_log(a->context_, GRIB_LOG_ERROR, "%s %s: unpacking %s, bits_per_value=%ld (max 32)", - cclass_name, __func__, a->name_, bits_per_value); + grib_context_log(context_, GRIB_LOG_ERROR, "%s %s: unpacking %s, bits_per_value=%ld (max 32)", + cclass_name, __func__, name_, bits_per_value); err = GRIB_INVALID_BPV; goto cleanup; } @@ -510,18 +509,18 @@ static int unpack(grib_accessor* a, T* val, size_t* len) *len = n_vals; cleanup: - grib_context_buffer_free(a->context_, decoded); + grib_context_buffer_free(context_, decoded); return err; } int grib_accessor_data_ccsds_packing_t::unpack_double(double* val, size_t* len) { - return unpack(this, val, len); + return unpack(val, len); } int grib_accessor_data_ccsds_packing_t::unpack_float(float* val, size_t* len) { - return unpack(this, val, len); + return unpack(val, len); } int grib_accessor_data_ccsds_packing_t::unpack_double_element(size_t idx, double* val) diff --git a/src/accessor/grib_accessor_class_data_ccsds_packing.h b/src/accessor/grib_accessor_class_data_ccsds_packing.h index 43ae75b6b..7ae72d514 100644 --- a/src/accessor/grib_accessor_class_data_ccsds_packing.h +++ b/src/accessor/grib_accessor_class_data_ccsds_packing.h @@ -27,7 +27,7 @@ public: int unpack_double_element(size_t i, double* val) override; int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override; -public: +private: const char* number_of_values_; const char* reference_value_; const char* binary_scale_factor_; @@ -38,4 +38,6 @@ public: const char* ccsds_flags_; const char* ccsds_block_size_; const char* ccsds_rsi_; + + template int unpack(T* val, size_t* len); }; diff --git a/src/accessor/grib_accessor_class_data_g1second_order_general_packing.cc b/src/accessor/grib_accessor_class_data_g1second_order_general_packing.cc index 400381670..ac9622b64 100644 --- a/src/accessor/grib_accessor_class_data_g1second_order_general_packing.cc +++ b/src/accessor/grib_accessor_class_data_g1second_order_general_packing.cc @@ -48,9 +48,8 @@ int grib_accessor_data_g1second_order_general_packing_t::value_count(long* numbe } template -static int unpack_real(grib_accessor* a, T* values, size_t* len) +int grib_accessor_data_g1second_order_general_packing_t::unpack_real(T* values, size_t* len) { - grib_accessor_data_g1second_order_general_packing_t* self = (grib_accessor_data_g1second_order_general_packing_t*)a; static_assert(std::is_floating_point::value, "Requires floating point numbers"); int ret = 0; long numberOfGroups, numberOfSecondOrderPackedValues; @@ -59,7 +58,7 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) long* X = 0; long pos = 0; long widthOfFirstOrderValues = 0; - unsigned char* buf = (unsigned char*)grib_handle_of_accessor(a)->buffer->data; + unsigned char* buf = (unsigned char*)grib_handle_of_accessor(this)->buffer->data; long i, n; double reference_value; long binary_scale_factor; @@ -69,44 +68,44 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) long groupLength, j; size_t groupWidthsSize; - buf += a->byte_offset(); - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfGroups_, &numberOfGroups)) != GRIB_SUCCESS) + buf += byte_offset(); + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), numberOfGroups_, &numberOfGroups)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->widthOfFirstOrderValues_, &widthOfFirstOrderValues)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), widthOfFirstOrderValues_, &widthOfFirstOrderValues)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_double_internal(grib_handle_of_accessor(a), self->reference_value_, &reference_value)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(grib_handle_of_accessor(this), reference_value_, &reference_value)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(grib_handle_of_accessor(a), self->numberOfSecondOrderPackedValues_, + if ((ret = grib_get_long_internal(grib_handle_of_accessor(this), numberOfSecondOrderPackedValues_, &numberOfSecondOrderPackedValues)) != GRIB_SUCCESS) return ret; if (*len < (size_t)numberOfSecondOrderPackedValues) return GRIB_ARRAY_TOO_SMALL; - groupWidths = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfGroups); + groupWidths = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfGroups); groupWidthsSize = numberOfGroups; - if ((ret = grib_get_long_array_internal(grib_handle_of_accessor(a), self->groupWidths_, groupWidths, &groupWidthsSize)) != GRIB_SUCCESS) + if ((ret = grib_get_long_array_internal(grib_handle_of_accessor(this), groupWidths_, groupWidths, &groupWidthsSize)) != GRIB_SUCCESS) return ret; - secondaryBitmap = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * (numberOfSecondOrderPackedValues + 1)); + secondaryBitmap = (long*)grib_context_malloc_clear(context_, sizeof(long) * (numberOfSecondOrderPackedValues + 1)); secondaryBitmap[numberOfSecondOrderPackedValues] = 1; grib_decode_long_array(buf, &pos, 1, numberOfSecondOrderPackedValues, secondaryBitmap); pos = 8 * ((pos + 7) / 8); - firstOrderValues = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfGroups); + firstOrderValues = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfGroups); grib_decode_long_array(buf, &pos, widthOfFirstOrderValues, numberOfGroups, firstOrderValues); pos = 8 * ((pos + 7) / 8); - X = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfSecondOrderPackedValues); + X = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfSecondOrderPackedValues); n = 0; i = -1; @@ -143,22 +142,22 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) } *len = numberOfSecondOrderPackedValues; - grib_context_free(a->context_, secondaryBitmap); - grib_context_free(a->context_, firstOrderValues); - grib_context_free(a->context_, X); - grib_context_free(a->context_, groupWidths); + grib_context_free(context_, secondaryBitmap); + grib_context_free(context_, firstOrderValues); + grib_context_free(context_, X); + grib_context_free(context_, groupWidths); return ret; } int grib_accessor_data_g1second_order_general_packing_t::unpack_float(float* values, size_t* len) { - return unpack_real(this, values, len); + return unpack_real(values, len); } int grib_accessor_data_g1second_order_general_packing_t::unpack_double(double* values, size_t* len) { - return unpack_real(this, values, len); + return unpack_real(values, len); } int grib_accessor_data_g1second_order_general_packing_t::pack_double(const double* cval, size_t* len) diff --git a/src/accessor/grib_accessor_class_data_g1second_order_general_packing.h b/src/accessor/grib_accessor_class_data_g1second_order_general_packing.h index c04deaa2a..159e1f98c 100644 --- a/src/accessor/grib_accessor_class_data_g1second_order_general_packing.h +++ b/src/accessor/grib_accessor_class_data_g1second_order_general_packing.h @@ -25,7 +25,7 @@ public: int value_count(long*) override; void init(const long, grib_arguments*) override; -public: +private: const char* half_byte_; const char* packingType_; const char* ieee_packing_; @@ -42,4 +42,6 @@ public: const char* jPointsAreConsecutive_; const char* bitmap_; const char* groupWidths_; + + template int unpack_real(T* values, size_t* len); }; diff --git a/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.cc b/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.cc index 652ad9e4b..49c8550c2 100644 --- a/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.cc +++ b/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.cc @@ -113,10 +113,9 @@ int grib_accessor_data_g1second_order_row_by_row_packing_t::value_count(long* co } template -static int unpack_real(grib_accessor* a, T* values, size_t* len) +int grib_accessor_data_g1second_order_row_by_row_packing_t::unpack_real(T* values, size_t* len) { - grib_accessor_data_g1second_order_row_by_row_packing_t* self = (grib_accessor_data_g1second_order_row_by_row_packing_t*)a; - grib_handle* gh = grib_handle_of_accessor(a); + grib_handle* gh = grib_handle_of_accessor(this); int ret = 0; long numberOfGroups, numberOfSecondOrderPackedValues; long* groupWidths = 0; @@ -138,25 +137,25 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) size_t plSize = 0; long* pl = 0; - buf += a->byte_offset(); - if ((ret = grib_get_long_internal(gh, self->numberOfGroups_, &numberOfGroups)) != GRIB_SUCCESS) + buf += byte_offset(); + if ((ret = grib_get_long_internal(gh, numberOfGroups_, &numberOfGroups)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->jPointsAreConsecutive_, &jPointsAreConsecutive)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, jPointsAreConsecutive_, &jPointsAreConsecutive)) != GRIB_SUCCESS) return ret; - if (self->bitmap_) + if (bitmap_) bitmapPresent = 1; - ret = grib_get_size(gh, self->pl_, &plSize); + ret = grib_get_size(gh, pl_, &plSize); if (ret == GRIB_SUCCESS) { - pl = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * plSize); - if ((ret = grib_get_long_array(gh, self->pl_, pl, &plSize)) != GRIB_SUCCESS) + pl = (long*)grib_context_malloc_clear(context_, sizeof(long) * plSize); + if ((ret = grib_get_long_array(gh, pl_, pl, &plSize)) != GRIB_SUCCESS) return ret; } - if ((ret = grib_get_long_internal(gh, self->Ni_, &Ni)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, Ni_, &Ni)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->Nj_, &Nj)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, Nj_, &Nj)) != GRIB_SUCCESS) return ret; if (jPointsAreConsecutive) { numberOfRows = Ni; @@ -167,7 +166,7 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) numberOfColumns = Ni; } - numbersPerRow = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfRows); + numbersPerRow = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfRows); if (!numbersPerRow) return GRIB_OUT_OF_MEMORY; if (bitmapPresent) { @@ -179,9 +178,9 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) for (i = 0; i < numberOfRows; i++) numberOfPoints += pl[i]; } - bitmap = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfPoints); + bitmap = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfPoints); pbitmap = bitmap; - grib_get_long_array(gh, self->bitmap_, bitmap, &numberOfPoints); + grib_get_long_array(gh, bitmap_, bitmap, &numberOfPoints); if (plSize && pl) { for (i = 0; i < numberOfRows; i++) { for (j = 0; j < pl[i]; j++) { @@ -198,7 +197,7 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) } } - grib_context_free(a->context_, pbitmap); + grib_context_free(context_, pbitmap); } else { if (plSize && pl) { @@ -211,28 +210,28 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) } } - if ((ret = grib_get_long_internal(gh, self->widthOfFirstOrderValues_, &widthOfFirstOrderValues)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, widthOfFirstOrderValues_, &widthOfFirstOrderValues)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_double_internal(gh, self->reference_value_, &reference_value)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(gh, reference_value_, &reference_value)) != GRIB_SUCCESS) return ret; - if ((ret = grib_get_long_internal(gh, self->numberOfSecondOrderPackedValues_, + if ((ret = grib_get_long_internal(gh, numberOfSecondOrderPackedValues_, &numberOfSecondOrderPackedValues)) != GRIB_SUCCESS) return ret; - groupWidths = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfGroups); + groupWidths = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfGroups); groupWidthsSize = numberOfGroups; - if ((ret = grib_get_long_array_internal(gh, self->groupWidths_, groupWidths, &groupWidthsSize)) != GRIB_SUCCESS) + if ((ret = grib_get_long_array_internal(gh, groupWidths_, groupWidths, &groupWidthsSize)) != GRIB_SUCCESS) return ret; - firstOrderValues = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * numberOfGroups); + firstOrderValues = (long*)grib_context_malloc_clear(context_, sizeof(long) * numberOfGroups); grib_decode_long_array(buf, &pos, widthOfFirstOrderValues, numberOfGroups, firstOrderValues); pos = 8 * ((pos + 7) / 8); @@ -243,7 +242,7 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) if (*len < (size_t)n) return GRIB_ARRAY_TOO_SMALL; - X = (long*)grib_context_malloc_clear(a->context_, sizeof(long) * n); + X = (long*)grib_context_malloc_clear(context_, sizeof(long) * n); n = 0; k = 0; for (i = 0; i < numberOfGroups; i++) { @@ -268,25 +267,25 @@ static int unpack_real(grib_accessor* a, T* values, size_t* len) for (i = 0; i < n; i++) { values[i] = (T)(((X[i] * s) + reference_value) * d); } - grib_context_free(a->context_, firstOrderValues); - grib_context_free(a->context_, X); - grib_context_free(a->context_, groupWidths); + grib_context_free(context_, firstOrderValues); + grib_context_free(context_, X); + grib_context_free(context_, groupWidths); if (plSize) - grib_context_free(a->context_, pl); + grib_context_free(context_, pl); if (numbersPerRow) - grib_context_free(a->context_, numbersPerRow); + grib_context_free(context_, numbersPerRow); return ret; } int grib_accessor_data_g1second_order_row_by_row_packing_t::unpack_float(float* values, size_t* len) { - return unpack_real(this, values, len); + return unpack_real(values, len); } int grib_accessor_data_g1second_order_row_by_row_packing_t::unpack_double(double* values, size_t* len) { - return unpack_real(this, values, len); + return unpack_real(values, len); } int grib_accessor_data_g1second_order_row_by_row_packing_t::pack_double(const double* cval, size_t* len) diff --git a/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.h b/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.h index af224ab56..263830ad8 100644 --- a/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.h +++ b/src/accessor/grib_accessor_class_data_g1second_order_row_by_row_packing.h @@ -25,7 +25,7 @@ public: int value_count(long*) override; void init(const long, grib_arguments*) override; -public: +private: const char* half_byte_; const char* packingType_; const char* ieee_packing_; @@ -42,4 +42,6 @@ public: const char* jPointsAreConsecutive_; const char* bitmap_; const char* groupWidths_; + + template int unpack_real(T* values, size_t* len); }; diff --git a/src/accessor/grib_accessor_class_data_g22order_packing.cc b/src/accessor/grib_accessor_class_data_g22order_packing.cc index 815e21eac..5e830a1c0 100644 --- a/src/accessor/grib_accessor_class_data_g22order_packing.cc +++ b/src/accessor/grib_accessor_class_data_g22order_packing.cc @@ -1461,12 +1461,11 @@ int grib_accessor_data_g22order_packing_t::pack_double(const double* val, size_t } template -static int unpack(grib_accessor* a, T* val, const size_t* len) +int grib_accessor_data_g22order_packing_t::unpack(T* val, const size_t* len) { - grib_accessor_data_g22order_packing_t* self = reinterpret_cast(a); static_assert(std::is_floating_point::value, "Requires floating points numbers"); - const char* cclass_name = a->class_name_; - grib_handle* gh = grib_handle_of_accessor(a); + const char* cclass_name = class_name_; + grib_handle* gh = grib_handle_of_accessor(this); size_t i = 0; size_t j = 0; @@ -1511,63 +1510,63 @@ static int unpack(grib_accessor* a, T* val, const size_t* len) long numberOfOctetsExtraDescriptors = 0; double missingValue = 0; - err = a->value_count(&n_vals); + err = value_count(&n_vals); if (err) return err; if (*len < static_cast(n_vals)) return GRIB_ARRAY_TOO_SMALL; - if ((err = grib_get_long_internal(gh, self->bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, bits_per_value_, &bits_per_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(gh, self->reference_value_, &reference_value)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(gh, reference_value_, &reference_value)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, binary_scale_factor_, &binary_scale_factor)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, decimal_scale_factor_, &decimal_scale_factor)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->typeOfOriginalFieldValues_, &typeOfOriginalFieldValues)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, typeOfOriginalFieldValues_, &typeOfOriginalFieldValues)) != GRIB_SUCCESS) return err; // Don't call grib_get_long_internal to suppress error message being output - if ((err = grib_get_long(gh, self->groupSplittingMethodUsed_, &groupSplittingMethodUsed)) != GRIB_SUCCESS) + if ((err = grib_get_long(gh, groupSplittingMethodUsed_, &groupSplittingMethodUsed)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->missingValueManagementUsed_, &missingValueManagementUsed)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, missingValueManagementUsed_, &missingValueManagementUsed)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->primaryMissingValueSubstitute_, &primaryMissingValueSubstitute)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, primaryMissingValueSubstitute_, &primaryMissingValueSubstitute)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->secondaryMissingValueSubstitute_, &secondaryMissingValueSubstitute)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, secondaryMissingValueSubstitute_, &secondaryMissingValueSubstitute)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->numberOfGroupsOfDataValues_, &numberOfGroupsOfDataValues)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, numberOfGroupsOfDataValues_, &numberOfGroupsOfDataValues)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->referenceForGroupWidths_, &referenceForGroupWidths)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, referenceForGroupWidths_, &referenceForGroupWidths)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->numberOfBitsUsedForTheGroupWidths_, &numberOfBitsUsedForTheGroupWidths)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, numberOfBitsUsedForTheGroupWidths_, &numberOfBitsUsedForTheGroupWidths)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->referenceForGroupLengths_, &referenceForGroupLengths)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, referenceForGroupLengths_, &referenceForGroupLengths)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->lengthIncrementForTheGroupLengths_, &lengthIncrementForTheGroupLengths)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, lengthIncrementForTheGroupLengths_, &lengthIncrementForTheGroupLengths)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->trueLengthOfLastGroup_, &trueLengthOfLastGroup)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, trueLengthOfLastGroup_, &trueLengthOfLastGroup)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->numberOfBitsUsedForTheScaledGroupLengths_, &numberOfBitsUsedForTheScaledGroupLengths)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, numberOfBitsUsedForTheScaledGroupLengths_, &numberOfBitsUsedForTheScaledGroupLengths)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->orderOfSpatialDifferencing_, &orderOfSpatialDifferencing)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, orderOfSpatialDifferencing_, &orderOfSpatialDifferencing)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(gh, self->numberOfOctetsExtraDescriptors_, &numberOfOctetsExtraDescriptors)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(gh, numberOfOctetsExtraDescriptors_, &numberOfOctetsExtraDescriptors)) != GRIB_SUCCESS) return err; if ((err = grib_get_double_internal(gh, "missingValue", &missingValue)) != GRIB_SUCCESS) return err; - a->dirty_ = 0; + dirty_ = 0; - sec_val = (long*)grib_context_malloc(a->context_, (n_vals) * sizeof(long)); + sec_val = (long*)grib_context_malloc(context_, (n_vals) * sizeof(long)); if (!sec_val) return GRIB_OUT_OF_MEMORY; memset(sec_val, 0, (n_vals) * sizeof(long)); // See SUP-718 - buf_ref = buf + a->offset_; + buf_ref = buf + offset_; ref_p = (numberOfGroupsOfDataValues * bits_per_value); @@ -1680,7 +1679,7 @@ static int unpack(grib_accessor* a, T* val, const size_t* len) // For Complex packing, order == 0 // For Complex packing and spatial differencing, order == 1 or 2 (code table 5.6) if (orderOfSpatialDifferencing != 1 && orderOfSpatialDifferencing != 2) { - grib_context_log(a->context_, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "%s unpacking: Unsupported order of spatial differencing %ld", cclass_name, orderOfSpatialDifferencing); return GRIB_INTERNAL_ERROR; } @@ -1691,7 +1690,7 @@ static int unpack(grib_accessor* a, T* val, const size_t* len) bias = grib_decode_signed_longb(buf_ref, &ref_p, numberOfOctetsExtraDescriptors * 8); - post_process(a->context_, sec_val, n_vals, orderOfSpatialDifferencing, bias, extras); + post_process(context_, sec_val, n_vals, orderOfSpatialDifferencing, bias, extras); // de_spatial_difference (context_ , sec_val, n_vals, orderOfSpatialDifferencing, bias); } @@ -1707,18 +1706,18 @@ static int unpack(grib_accessor* a, T* val, const size_t* len) } } - grib_context_free(a->context_, sec_val); + grib_context_free(context_, sec_val); return err; } int grib_accessor_data_g22order_packing_t::unpack_double(double* val, size_t* len) { - return unpack(this, val, len); + return unpack(val, len); } int grib_accessor_data_g22order_packing_t::unpack_float(float* val, size_t* len) { - return unpack(this, val, len); + return unpack(val, len); } int grib_accessor_data_g22order_packing_t::unpack_double_element(size_t idx, double* val) diff --git a/src/accessor/grib_accessor_class_data_g22order_packing.h b/src/accessor/grib_accessor_class_data_g22order_packing.h index cbb396f62..d202d8178 100644 --- a/src/accessor/grib_accessor_class_data_g22order_packing.h +++ b/src/accessor/grib_accessor_class_data_g22order_packing.h @@ -27,7 +27,7 @@ public: int unpack_double_element(size_t i, double* val) override; int unpack_double_element_set(const size_t* index_array, size_t len, double* val_array) override; -public: +private: const char* numberOfValues_; const char* bits_per_value_; const char* reference_value_; @@ -48,4 +48,6 @@ public: const char* numberOfBitsUsedForTheScaledGroupLengths_; const char* orderOfSpatialDifferencing_; const char* numberOfOctetsExtraDescriptors_; + + template int unpack(T* val, const size_t* len); }; diff --git a/src/accessor/grib_accessor_class_data_g2bifourier_packing.cc b/src/accessor/grib_accessor_class_data_g2bifourier_packing.cc index 066744538..d887635e0 100644 --- a/src/accessor/grib_accessor_class_data_g2bifourier_packing.cc +++ b/src/accessor/grib_accessor_class_data_g2bifourier_packing.cc @@ -15,9 +15,6 @@ grib_accessor_data_g2bifourier_packing_t _grib_accessor_data_g2bifourier_packing{}; grib_accessor* grib_accessor_data_g2bifourier_packing = &_grib_accessor_data_g2bifourier_packing; -typedef unsigned long (*encode_float_proc)(double); -typedef double (*decode_float_proc)(unsigned long); - void grib_accessor_data_g2bifourier_packing_t::init(const long v, grib_arguments* args) { grib_accessor_data_simple_packing_t::init(v, args); @@ -145,29 +142,6 @@ static void diamond(long ni, long nj, long itrunc[], long jtrunc[]) insub = insub || (i == 0) || (j == 0); \ } while (0) -typedef struct bif_trunc_t -{ - long bits_per_value; - long decimal_scale_factor; - long binary_scale_factor; - long ieee_floats; - long laplacianOperatorIsSet; - double laplacianOperator; - double reference_value; - long sub_i, sub_j, bif_i, bif_j; - long biFourierTruncationType; - long biFourierSubTruncationType; - long keepaxes; - long maketemplate; - decode_float_proc decode_float; - encode_float_proc encode_float; - int bytes; - long* itruncation_bif; - long* jtruncation_bif; - long* itruncation_sub; - long* jtruncation_sub; - size_t n_vals_bif, n_vals_sub; -} bif_trunc_t; /* * Total number of coefficients @@ -354,45 +328,44 @@ static void free_bif_trunc(bif_trunc_t* bt, grib_accessor* a) grib_context_free(gh->context, bt); } -static bif_trunc_t* new_bif_trunc(grib_accessor* a) +bif_trunc_t* grib_accessor_data_g2bifourier_packing_t::new_bif_trunc() { int ret; - grib_accessor_data_g2bifourier_packing_t* self = (grib_accessor_data_g2bifourier_packing_t*)a; - grib_handle* gh = grib_handle_of_accessor(a); + grib_handle* gh = grib_handle_of_accessor(this); bif_trunc_t* bt = (bif_trunc_t*)grib_context_malloc(gh->context, sizeof(bif_trunc_t)); memset(bt, 0, sizeof(bif_trunc_t)); - if ((ret = grib_get_double_internal(gh, self->reference_value_, &bt->reference_value)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(gh, reference_value_, &bt->reference_value)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->bits_per_value_, &bt->bits_per_value)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, bits_per_value_, &bt->bits_per_value)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->binary_scale_factor_, &bt->binary_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, binary_scale_factor_, &bt->binary_scale_factor)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->decimal_scale_factor_, &bt->decimal_scale_factor)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, decimal_scale_factor_, &bt->decimal_scale_factor)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->ieee_floats_, &bt->ieee_floats)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, ieee_floats_, &bt->ieee_floats)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->laplacianOperatorIsSet_, &bt->laplacianOperatorIsSet)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, laplacianOperatorIsSet_, &bt->laplacianOperatorIsSet)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_double_internal(gh, self->laplacianOperator_, &bt->laplacianOperator)) != GRIB_SUCCESS) + if ((ret = grib_get_double_internal(gh, laplacianOperator_, &bt->laplacianOperator)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->sub_i_, &bt->sub_i)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, sub_i_, &bt->sub_i)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->sub_j_, &bt->sub_j)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, sub_j_, &bt->sub_j)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->bif_i_, &bt->bif_i)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, bif_i_, &bt->bif_i)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->bif_j_, &bt->bif_j)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, bif_j_, &bt->bif_j)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->biFourierTruncationType_, &bt->biFourierTruncationType)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, biFourierTruncationType_, &bt->biFourierTruncationType)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->biFourierSubTruncationType_, &bt->biFourierSubTruncationType)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, biFourierSubTruncationType_, &bt->biFourierSubTruncationType)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->biFourierDoNotPackAxes_, &bt->keepaxes)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, biFourierDoNotPackAxes_, &bt->keepaxes)) != GRIB_SUCCESS) goto cleanup; - if ((ret = grib_get_long_internal(gh, self->biFourierMakeTemplate_, &bt->maketemplate)) != GRIB_SUCCESS) + if ((ret = grib_get_long_internal(gh, biFourierMakeTemplate_, &bt->maketemplate)) != GRIB_SUCCESS) goto cleanup; switch (bt->ieee_floats) { @@ -461,7 +434,7 @@ static bif_trunc_t* new_bif_trunc(grib_accessor* a) cleanup: - free_bif_trunc(bt, a); + free_bif_trunc(bt, this); if (ret) fprintf(stderr, "ERROR: new_bif_trunc: %s\n", grib_get_error_message(ret)); return NULL; @@ -495,7 +468,7 @@ int grib_accessor_data_g2bifourier_packing_t::unpack_double(double* val, size_t* if ((ret = value_count(&count)) != GRIB_SUCCESS) goto cleanup; - bt = new_bif_trunc(this); + bt = new_bif_trunc(); if (bt == NULL) { ret = GRIB_INTERNAL_ERROR; @@ -594,7 +567,7 @@ int grib_accessor_data_g2bifourier_packing_t::pack_double(const double* val, siz goto cleanup; } - bt = new_bif_trunc(this); + bt = new_bif_trunc(); if (bt == NULL) { long makeTemplate = 0; diff --git a/src/accessor/grib_accessor_class_data_g2bifourier_packing.h b/src/accessor/grib_accessor_class_data_g2bifourier_packing.h index 22449fb93..f5bce94fb 100644 --- a/src/accessor/grib_accessor_class_data_g2bifourier_packing.h +++ b/src/accessor/grib_accessor_class_data_g2bifourier_packing.h @@ -12,6 +12,35 @@ #include "grib_accessor_class_data_simple_packing.h" +typedef unsigned long (*encode_float_proc)(double); +typedef double (*decode_float_proc)(unsigned long); + + +typedef struct bif_trunc_t +{ + long bits_per_value; + long decimal_scale_factor; + long binary_scale_factor; + long ieee_floats; + long laplacianOperatorIsSet; + double laplacianOperator; + double reference_value; + long sub_i, sub_j, bif_i, bif_j; + long biFourierTruncationType; + long biFourierSubTruncationType; + long keepaxes; + long maketemplate; + decode_float_proc decode_float; + encode_float_proc encode_float; + int bytes; + long* itruncation_bif; + long* jtruncation_bif; + long* itruncation_sub; + long* jtruncation_sub; + size_t n_vals_bif, n_vals_sub; +} bif_trunc_t; + + class grib_accessor_data_g2bifourier_packing_t : public grib_accessor_data_simple_packing_t { public: @@ -23,7 +52,7 @@ public: int value_count(long*) override; void init(const long, grib_arguments*) override; -public: +private: const char* ieee_floats_; const char* laplacianOperatorIsSet_; const char* laplacianOperator_; @@ -37,4 +66,6 @@ public: const char* biFourierMakeTemplate_; const char* totalNumberOfValuesInUnpackedSubset_; const char* numberOfValues_; + + bif_trunc_t* new_bif_trunc(); }; diff --git a/src/accessor/grib_accessor_class_data_run_length_packing.h b/src/accessor/grib_accessor_class_data_run_length_packing.h index b489c7d9b..8606a6ae0 100644 --- a/src/accessor/grib_accessor_class_data_run_length_packing.h +++ b/src/accessor/grib_accessor_class_data_run_length_packing.h @@ -23,7 +23,7 @@ public: int value_count(long*) override; void init(const long, grib_arguments*) override; -public: +private: const char* number_of_values_; const char* bits_per_value_; const char* max_level_value_; diff --git a/src/accessor/grib_accessor_class_dictionary.cc b/src/accessor/grib_accessor_class_dictionary.cc index 6bca21294..933a89ec4 100644 --- a/src/accessor/grib_accessor_class_dictionary.cc +++ b/src/accessor/grib_accessor_class_dictionary.cc @@ -29,10 +29,8 @@ void grib_accessor_dictionary_t::init(const long len, grib_arguments* params) flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; } -static grib_trie* load_dictionary(grib_accessor* a, int* err) +grib_trie* grib_accessor_dictionary_t::load_dictionary(int* err) { - grib_accessor_dictionary_t* self = (grib_accessor_dictionary_t*)a; - char* filename = NULL; char line[1024] = { 0, @@ -55,17 +53,17 @@ static grib_trie* load_dictionary(grib_accessor* a, int* err) grib_trie* dictionary = NULL; FILE* f = NULL; int i = 0; - grib_handle* h = grib_handle_of_accessor(a); - grib_context* c = a->context_; + grib_handle* h = grib_handle_of_accessor(this); + grib_context* c = context_; *err = GRIB_SUCCESS; len = 1024; - if (self->masterDir_ != NULL) - grib_get_string(h, self->masterDir_, masterDir, &len); + if (masterDir_ != NULL) + grib_get_string(h, masterDir_, masterDir, &len); len = 1024; - if (self->localDir_ != NULL) - grib_get_string(h, self->localDir_, localDir, &len); + if (localDir_ != NULL) + grib_get_string(h, localDir_, localDir, &len); if (*masterDir != 0) { char name[2048] = { @@ -74,12 +72,12 @@ static grib_trie* load_dictionary(grib_accessor* a, int* err) char recomposed[2048] = { 0, }; - snprintf(name, sizeof(name), "%s/%s", masterDir, self->dictionary_); + snprintf(name, sizeof(name), "%s/%s", masterDir, dictionary_); grib_recompose_name(h, NULL, name, recomposed, 0); filename = grib_context_full_defs_path(c, recomposed); } else { - filename = grib_context_full_defs_path(c, self->dictionary_); + filename = grib_context_full_defs_path(c, dictionary_); } if (*localDir != 0) { @@ -89,7 +87,7 @@ static grib_trie* load_dictionary(grib_accessor* a, int* err) char localRecomposed[1024] = { 0, }; - snprintf(localName, sizeof(localName), "%s/%s", localDir, self->dictionary_); + snprintf(localName, sizeof(localName), "%s/%s", localDir, dictionary_); grib_recompose_name(h, NULL, localName, localRecomposed, 0); localFilename = grib_context_full_defs_path(c, localRecomposed); snprintf(dictName, sizeof(dictName), "%s:%s", localFilename, filename); @@ -99,7 +97,7 @@ static grib_trie* load_dictionary(grib_accessor* a, int* err) } if (!filename) { - grib_context_log(c, GRIB_LOG_ERROR, "Unable to find def file %s", self->dictionary_); + grib_context_log(c, GRIB_LOG_ERROR, "Unable to find def file %s", dictionary_); *err = GRIB_FILE_NOT_FOUND; return NULL; } @@ -108,11 +106,11 @@ static grib_trie* load_dictionary(grib_accessor* a, int* err) } dictionary = (grib_trie*)grib_trie_get(c->lists, dictName); if (dictionary) { - grib_context_log(c, GRIB_LOG_DEBUG, "using dictionary %s from cache", self->dictionary_); + grib_context_log(c, GRIB_LOG_DEBUG, "using dictionary %s from cache", dictionary_); return dictionary; } else { - grib_context_log(c, GRIB_LOG_DEBUG, "using dictionary %s from file %s", self->dictionary_, filename); + grib_context_log(c, GRIB_LOG_DEBUG, "using dictionary %s from file %s", dictionary_, filename); } f = codes_fopen(filename, "r"); @@ -192,7 +190,7 @@ int grib_accessor_dictionary_t::unpack_string(char* buffer, size_t* len) size_t rsize = 0; int i = 0; - grib_trie* dictionary = load_dictionary(this, &err); + grib_trie* dictionary = load_dictionary(&err); if (err) return err; diff --git a/src/accessor/grib_accessor_class_dictionary.h b/src/accessor/grib_accessor_class_dictionary.h index dd1fba934..7c6b8ed76 100644 --- a/src/accessor/grib_accessor_class_dictionary.h +++ b/src/accessor/grib_accessor_class_dictionary.h @@ -26,10 +26,12 @@ public: void dump(grib_dumper*) override; void init(const long, grib_arguments*) override; -public: +private: const char* dictionary_; const char* key_; long column_; const char* masterDir_; const char* localDir_; + + grib_trie* load_dictionary(int* err); }; diff --git a/src/accessor/grib_accessor_class_expanded_descriptors.h b/src/accessor/grib_accessor_class_expanded_descriptors.h index 682f62105..578b5fdd2 100644 --- a/src/accessor/grib_accessor_class_expanded_descriptors.h +++ b/src/accessor/grib_accessor_class_expanded_descriptors.h @@ -28,6 +28,7 @@ public: void init(const long, grib_arguments*) override; public: + // TODO(maee): make private const char* unexpandedDescriptors_; const char* sequence_; const char* expandedName_; diff --git a/src/accessor/grib_accessor_class_g1forecastmonth.cc b/src/accessor/grib_accessor_class_g1forecastmonth.cc index 3315831bd..6f9e00a64 100644 --- a/src/accessor/grib_accessor_class_g1forecastmonth.cc +++ b/src/accessor/grib_accessor_class_g1forecastmonth.cc @@ -103,9 +103,8 @@ static int unpack_long_edition2(grib_accessor* a, long* val, size_t* len) return GRIB_SUCCESS; } -static int unpack_long_edition1(grib_accessor* a, long* val, size_t* len) +int grib_accessor_g1forecastmonth_t::unpack_long_edition1(long* val, size_t* len) { - grib_accessor_g1forecastmonth_t* self = (grib_accessor_g1forecastmonth_t*)a; int err = 0; long verification_yearmonth = 0; @@ -116,29 +115,29 @@ static int unpack_long_edition1(grib_accessor* a, long* val, size_t* len) long check = 0; long fcmonth = 0; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), - self->verification_yearmonth_, &verification_yearmonth)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), + verification_yearmonth_, &verification_yearmonth)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->base_date_, &base_date)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), base_date_, &base_date)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->day_, &day)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), day_, &day)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->hour_, &hour)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), hour_, &hour)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->fcmonth_, &gribForecastMonth)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), fcmonth_, &gribForecastMonth)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(grib_handle_of_accessor(a), self->check_, &check)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(grib_handle_of_accessor(this), check_, &check)) != GRIB_SUCCESS) return err; - if ((err = calculate_fcmonth(a, verification_yearmonth, base_date, day, hour, val)) != GRIB_SUCCESS) + if ((err = calculate_fcmonth(this, verification_yearmonth, base_date, day, hour, val)) != GRIB_SUCCESS) return err; /* Verification - compare gribForecastMonth with fcmonth */ fcmonth = *val; if (gribForecastMonth != 0 && gribForecastMonth != fcmonth) { if (check) { - grib_context_log(a->context_, GRIB_LOG_ERROR, "%s=%ld (%s-%s)=%ld", self->fcmonth_, - gribForecastMonth, base_date, self->verification_yearmonth_, fcmonth); + grib_context_log(context_, GRIB_LOG_ERROR, "%s=%ld (%s-%s)=%ld", fcmonth_, + gribForecastMonth, base_date, verification_yearmonth_, fcmonth); Assert(gribForecastMonth == fcmonth); } else { @@ -160,7 +159,7 @@ int grib_accessor_g1forecastmonth_t::unpack_long(long* val, size_t* len) return err; if (edition == 1) - return unpack_long_edition1(this, val, len); + return unpack_long_edition1(val, len); if (edition == 2) return unpack_long_edition2(this, val, len); diff --git a/src/accessor/grib_accessor_class_g1forecastmonth.h b/src/accessor/grib_accessor_class_g1forecastmonth.h index c19be2f31..9737eb16a 100644 --- a/src/accessor/grib_accessor_class_g1forecastmonth.h +++ b/src/accessor/grib_accessor_class_g1forecastmonth.h @@ -24,11 +24,13 @@ public: void dump(grib_dumper*) override; void init(const long, grib_arguments*) override; -public: +private: const char* verification_yearmonth_; const char* base_date_; const char* day_; const char* hour_; const char* fcmonth_; const char* check_; + + int unpack_long_edition1(long* val, size_t* len); }; diff --git a/src/accessor/grib_accessor_class_g2_mars_labeling.cc b/src/accessor/grib_accessor_class_g2_mars_labeling.cc index 8e8ffa131..509ebf8b8 100644 --- a/src/accessor/grib_accessor_class_g2_mars_labeling.cc +++ b/src/accessor/grib_accessor_class_g2_mars_labeling.cc @@ -77,11 +77,10 @@ int grib_accessor_g2_mars_labeling_t::unpack_string(char* val, size_t* len) return grib_get_string(grib_handle_of_accessor(this), key, val, len); } -static int extra_set(grib_accessor* a, long val) +int grib_accessor_g2_mars_labeling_t::extra_set(long val) { - grib_accessor_g2_mars_labeling_t* self = (grib_accessor_g2_mars_labeling_t*)a; int ret = 0; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); char stepType[30] = { 0, }; @@ -108,7 +107,7 @@ static int extra_set(grib_accessor* a, long val) const int is_wave = grib_is_defined(hand, "waveDirectionNumber"); const int is_wave_prange = grib_is_defined(hand, "typeOfWavePeriodInterval"); - switch (self->index_) { + switch (index_) { case 0: /* class */ return ret; @@ -162,7 +161,7 @@ static int extra_set(grib_accessor* a, long val) break; case 17: /* Ensemble mean (em) */ derivedForecast = 0; - grib_get_string(hand, self->stepType_, stepType, &stepTypelen); + grib_get_string(hand, stepType_, stepType, &stepTypelen); if (!strcmp(stepType, "instant")) { productDefinitionTemplateNumberNew = 2; } @@ -174,7 +173,7 @@ static int extra_set(grib_accessor* a, long val) break; case 18: /* Ensemble standard deviation (es) */ derivedForecast = 4; - grib_get_string(hand, self->stepType_, stepType, &stepTypelen); + grib_get_string(hand, stepType_, stepType, &stepTypelen); if (!strcmp(stepType, "instant")) { productDefinitionTemplateNumberNew = 2; } @@ -258,7 +257,7 @@ static int extra_set(grib_accessor* a, long val) typeOfGeneratingProcess = 255; break; default: - grib_context_log(a->context_, GRIB_LOG_WARNING, "g2_mars_labeling: unknown mars.type %d", (int)val); + grib_context_log(context_, GRIB_LOG_WARNING, "g2_mars_labeling: unknown mars.type %d", (int)val); /*return GRIB_ENCODING_ERROR;*/ } break; @@ -269,7 +268,7 @@ static int extra_set(grib_accessor* a, long val) case 1249: /* elda */ case 1250: /* ewla */ is_eps = 1; /* These streams are all for ensembles */ - grib_get_string(hand, self->stepType_, stepType, &stepTypelen); + grib_get_string(hand, stepType_, stepType, &stepTypelen); is_instant = (strcmp(stepType, "instant") == 0); productDefinitionTemplateNumberNew = grib2_select_PDTN( is_eps, is_instant, @@ -282,8 +281,8 @@ static int extra_set(grib_accessor* a, long val) } break; default: - grib_context_log(a->context_, GRIB_LOG_ERROR, - "invalid first argument of g2_mars_labeling in %s", a->name_); + grib_context_log(context_, GRIB_LOG_ERROR, + "invalid first argument of g2_mars_labeling in %s", name_); return GRIB_INTERNAL_ERROR; } @@ -293,19 +292,19 @@ static int extra_set(grib_accessor* a, long val) } if (productDefinitionTemplateNumberNew >= 0) { - grib_get_long(hand, self->productDefinitionTemplateNumber_, &productDefinitionTemplateNumber); + grib_get_long(hand, productDefinitionTemplateNumber_, &productDefinitionTemplateNumber); if (productDefinitionTemplateNumber != productDefinitionTemplateNumberNew) - grib_set_long(hand, self->productDefinitionTemplateNumber_, productDefinitionTemplateNumberNew); + grib_set_long(hand, productDefinitionTemplateNumber_, productDefinitionTemplateNumberNew); } if (derivedForecast >= 0) { - grib_set_long(hand, self->derivedForecast_, derivedForecast); + grib_set_long(hand, derivedForecast_, derivedForecast); } if (typeOfProcessedData > 0) - grib_set_long(hand, self->typeOfProcessedData_, typeOfProcessedData); + grib_set_long(hand, typeOfProcessedData_, typeOfProcessedData); if (typeOfGeneratingProcess > 0) - grib_set_long(hand, self->typeOfGeneratingProcess_, typeOfGeneratingProcess); + grib_set_long(hand, typeOfGeneratingProcess_, typeOfGeneratingProcess); return ret; } @@ -340,7 +339,7 @@ int grib_accessor_g2_mars_labeling_t::pack_string(const char* val, size_t* len) if (ret) return ret; /* failed */ - return extra_set(this, lval); + return extra_set(lval); } int grib_accessor_g2_mars_labeling_t::pack_long(const long* val, size_t* len) @@ -368,7 +367,7 @@ int grib_accessor_g2_mars_labeling_t::pack_long(const long* val, size_t* len) if (ret) return ret; /* failed */ - return extra_set(this, *val); + return extra_set(*val); } int grib_accessor_g2_mars_labeling_t::value_count(long* count) diff --git a/src/accessor/grib_accessor_class_g2_mars_labeling.h b/src/accessor/grib_accessor_class_g2_mars_labeling.h index fa9e816e5..7655fd60d 100644 --- a/src/accessor/grib_accessor_class_g2_mars_labeling.h +++ b/src/accessor/grib_accessor_class_g2_mars_labeling.h @@ -27,7 +27,7 @@ public: int value_count(long*) override; void init(const long, grib_arguments*) override; -public: +private: int index_; const char* the_class_; const char* stream_; @@ -38,4 +38,6 @@ public: const char* stepType_; const char* derivedForecast_; const char* typeOfGeneratingProcess_; + + int extra_set(long val); }; diff --git a/src/accessor/grib_accessor_class_g2end_step.cc b/src/accessor/grib_accessor_class_g2end_step.cc index 36cd03f5b..a601250d8 100644 --- a/src/accessor/grib_accessor_class_g2end_step.cc +++ b/src/accessor/grib_accessor_class_g2end_step.cc @@ -96,10 +96,8 @@ static int convert_time_range_long_( return GRIB_SUCCESS; } -static int unpack_one_time_range_long_(grib_accessor* a, long* val, size_t* len) +int grib_accessor_g2end_step_t::unpack_one_time_range_long_(long* val, size_t* len) { - grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; - int err = 0; long start_step_value; long step_units; @@ -107,17 +105,17 @@ static int unpack_one_time_range_long_(grib_accessor* a, long* val, size_t* len) long time_range_value, typeOfTimeIncrement; int add_time_range = 1; /* whether we add lengthOfTimeRange */ - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); - if ((err = grib_get_long_internal(h, self->start_step_value_, &start_step_value))) + if ((err = grib_get_long_internal(h, start_step_value_, &start_step_value))) return err; - if ((err = grib_get_long_internal(h, self->step_units_, &step_units))) + if ((err = grib_get_long_internal(h, step_units_, &step_units))) return err; - if ((err = grib_get_long_internal(h, self->time_range_unit_, &time_range_unit))) + if ((err = grib_get_long_internal(h, time_range_unit_, &time_range_unit))) return err; - if ((err = grib_get_long_internal(h, self->time_range_value_, &time_range_value))) + if ((err = grib_get_long_internal(h, time_range_value_, &time_range_value))) return err; - if ((err = grib_get_long_internal(h, self->typeOfTimeIncrement_, &typeOfTimeIncrement))) + if ((err = grib_get_long_internal(h, typeOfTimeIncrement_, &typeOfTimeIncrement))) return err; err = convert_time_range_long_(h, step_units, time_range_unit, &time_range_value); @@ -146,9 +144,8 @@ static int unpack_one_time_range_long_(grib_accessor* a, long* val, size_t* len) return GRIB_SUCCESS; } -static int unpack_one_time_range_double_(grib_accessor* a, double* val, size_t* len) +int grib_accessor_g2end_step_t::unpack_one_time_range_double_(double* val, size_t* len) { - grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; int err = 0; double start_step_value; long start_step_unit; @@ -158,19 +155,19 @@ static int unpack_one_time_range_double_(grib_accessor* a, double* val, size_t* long typeOfTimeIncrement; int add_time_range = 1; /* whether we add lengthOfTimeRange */ - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); - if ((err = grib_get_double_internal(h, self->start_step_value_, &start_step_value))) + if ((err = grib_get_double_internal(h, start_step_value_, &start_step_value))) return err; if ((err = grib_get_long_internal(h, "startStepUnit", &start_step_unit))) return err; - if ((err = grib_get_long_internal(h, self->step_units_, &step_units))) + if ((err = grib_get_long_internal(h, step_units_, &step_units))) return err; - if ((err = grib_get_long_internal(h, self->time_range_unit_, &time_range_unit))) + if ((err = grib_get_long_internal(h, time_range_unit_, &time_range_unit))) return err; - if ((err = grib_get_double_internal(h, self->time_range_value_, &time_range_value))) + if ((err = grib_get_double_internal(h, time_range_value_, &time_range_value))) return err; - if ((err = grib_get_long_internal(h, self->typeOfTimeIncrement_, &typeOfTimeIncrement))) + if ((err = grib_get_long_internal(h, typeOfTimeIncrement_, &typeOfTimeIncrement))) return err; eccodes::Step start_step{ start_step_value, start_step_unit }; @@ -199,11 +196,10 @@ static int unpack_one_time_range_double_(grib_accessor* a, double* val, size_t* } #define MAX_NUM_TIME_RANGES 16 /* maximum number of time range specifications */ -static int unpack_multiple_time_ranges_long_(grib_accessor* a, long* val, size_t* len) +int grib_accessor_g2end_step_t::unpack_multiple_time_ranges_long_(long* val, size_t* len) { - grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; int i = 0, err = 0; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); long numberOfTimeRanges = 0, step_units = 0, start_step_value = 0; size_t count = 0; @@ -217,11 +213,11 @@ static int unpack_multiple_time_ranges_long_(grib_accessor* a, long* val, size_t 0, }; - if ((err = grib_get_long_internal(h, self->start_step_value_, &start_step_value))) + if ((err = grib_get_long_internal(h, start_step_value_, &start_step_value))) return err; - if ((err = grib_get_long_internal(h, self->step_units_, &step_units))) + if ((err = grib_get_long_internal(h, step_units_, &step_units))) return err; - if ((err = grib_get_long_internal(h, self->numberOfTimeRanges_, &numberOfTimeRanges))) + if ((err = grib_get_long_internal(h, numberOfTimeRanges_, &numberOfTimeRanges))) return err; if (numberOfTimeRanges > MAX_NUM_TIME_RANGES) { grib_context_log(h->context, GRIB_LOG_ERROR, "Too many time range specifications!"); @@ -230,11 +226,11 @@ static int unpack_multiple_time_ranges_long_(grib_accessor* a, long* val, size_t count = numberOfTimeRanges; /* Get the arrays for the N time ranges */ - if ((err = grib_get_long_array(h, self->typeOfTimeIncrement_, arr_typeOfTimeIncrement, &count))) + if ((err = grib_get_long_array(h, typeOfTimeIncrement_, arr_typeOfTimeIncrement, &count))) return err; - if ((err = grib_get_long_array(h, self->time_range_unit_, arr_coded_unit, &count))) + if ((err = grib_get_long_array(h, time_range_unit_, arr_coded_unit, &count))) return err; - if ((err = grib_get_long_array(h, self->time_range_value_, arr_coded_time_range, &count))) + if ((err = grib_get_long_array(h, time_range_value_, arr_coded_time_range, &count))) return err; /* Look in the array of typeOfTimeIncrements for first entry whose typeOfTimeIncrement == 2 */ @@ -258,11 +254,10 @@ static int unpack_multiple_time_ranges_long_(grib_accessor* a, long* val, size_t return GRIB_DECODING_ERROR; } -static int unpack_multiple_time_ranges_double_(grib_accessor* a, double* val, size_t* len) +int grib_accessor_g2end_step_t::unpack_multiple_time_ranges_double_(double* val, size_t* len) { - grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; int i = 0, err = 0; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); long numberOfTimeRanges = 0; long step_units = 0; long start_step_value = 0; @@ -279,17 +274,17 @@ static int unpack_multiple_time_ranges_double_(grib_accessor* a, double* val, si 0, }; - if ((err = grib_get_long_internal(h, self->start_step_value_, &start_step_value))) + if ((err = grib_get_long_internal(h, start_step_value_, &start_step_value))) return err; if ((err = grib_get_long_internal(h, "startStepUnit", &start_step_unit))) return err; eccodes::Step start_step{ start_step_value, start_step_unit }; - if ((err = grib_get_long_internal(h, self->step_units_, &step_units))) + if ((err = grib_get_long_internal(h, step_units_, &step_units))) return err; - if ((err = grib_get_long_internal(h, self->numberOfTimeRanges_, &numberOfTimeRanges))) + if ((err = grib_get_long_internal(h, numberOfTimeRanges_, &numberOfTimeRanges))) return err; if (numberOfTimeRanges > MAX_NUM_TIME_RANGES) { grib_context_log(h->context, GRIB_LOG_ERROR, "Too many time range specifications!"); @@ -298,11 +293,11 @@ static int unpack_multiple_time_ranges_double_(grib_accessor* a, double* val, si count = numberOfTimeRanges; /* Get the arrays for the N time ranges */ - if ((err = grib_get_long_array(h, self->typeOfTimeIncrement_, arr_typeOfTimeIncrement, &count))) + if ((err = grib_get_long_array(h, typeOfTimeIncrement_, arr_typeOfTimeIncrement, &count))) return err; - if ((err = grib_get_long_array(h, self->time_range_unit_, arr_coded_unit, &count))) + if ((err = grib_get_long_array(h, time_range_unit_, arr_coded_unit, &count))) return err; - if ((err = grib_get_long_array(h, self->time_range_value_, arr_coded_time_range, &count))) + if ((err = grib_get_long_array(h, time_range_value_, arr_coded_time_range, &count))) return err; /* Look in the array of typeOfTimeIncrements for first entry whose typeOfTimeIncrement == 2 */ @@ -355,10 +350,10 @@ int grib_accessor_g2end_step_t::unpack_long(long* val, size_t* len) try { if (numberOfTimeRanges == 1) { - ret = unpack_one_time_range_long_(this, val, len); + ret = unpack_one_time_range_long_(val, len); } else { - ret = unpack_multiple_time_ranges_long_(this, val, len); + ret = unpack_multiple_time_ranges_long_(val, len); } } catch (std::exception& e) { @@ -397,10 +392,10 @@ int grib_accessor_g2end_step_t::unpack_double(double* val, size_t* len) try { if (numberOfTimeRanges == 1) { - ret = unpack_one_time_range_double_(this, val, len); + ret = unpack_one_time_range_double_(val, len); } else { - ret = unpack_multiple_time_ranges_double_(this, val, len); + ret = unpack_multiple_time_ranges_double_(val, len); } } catch (std::exception& e) { @@ -411,10 +406,9 @@ int grib_accessor_g2end_step_t::unpack_double(double* val, size_t* len) return ret; } -static int pack_long_(grib_accessor* a, const long end_step_value, const long end_step_unit) +int grib_accessor_g2end_step_t::pack_long_(const long end_step_value, const long end_step_unit) { - grib_accessor_g2end_step_t* self = (grib_accessor_g2end_step_t*)a; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); int err = 0; long year; @@ -436,34 +430,34 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en long typeOfTimeIncrement; double dend, dstep; - const int show_units_for_hours = a->context_->grib_hourly_steps_with_units; + const int show_units_for_hours = context_->grib_hourly_steps_with_units; eccodes::Step end_step{ end_step_value, end_step_unit }; /*point in time */ - if (self->year_ == NULL) { + if (year_ == NULL) { if ((err = grib_set_long_internal(h, "startStepUnit", end_step.unit().value())) != GRIB_SUCCESS) return err; - err = grib_set_long_internal(h, self->start_step_value_, end_step.value()); + err = grib_set_long_internal(h, start_step_value_, end_step.value()); return err; } - if ((err = grib_get_long_internal(h, self->time_range_unit_, &time_range_unit))) + if ((err = grib_get_long_internal(h, time_range_unit_, &time_range_unit))) return err; - if ((err = grib_get_long_internal(h, self->year_, &year))) + if ((err = grib_get_long_internal(h, year_, &year))) return err; - if ((err = grib_get_long_internal(h, self->month_, &month))) + if ((err = grib_get_long_internal(h, month_, &month))) return err; - if ((err = grib_get_long_internal(h, self->day_, &day))) + if ((err = grib_get_long_internal(h, day_, &day))) return err; - if ((err = grib_get_long_internal(h, self->hour_, &hour))) + if ((err = grib_get_long_internal(h, hour_, &hour))) return err; - if ((err = grib_get_long_internal(h, self->minute_, &minute))) + if ((err = grib_get_long_internal(h, minute_, &minute))) return err; - if ((err = grib_get_long_internal(h, self->second_, &second))) + if ((err = grib_get_long_internal(h, second_, &second))) return err; - if ((err = grib_get_long_internal(h, self->start_step_value_, &start_step_value))) + if ((err = grib_get_long_internal(h, start_step_value_, &start_step_value))) return err; if ((err = grib_get_long_internal(h, "startStepUnit", &start_step_unit))) return err; @@ -478,7 +472,7 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en return GRIB_WRONG_STEP_UNIT; } - if ((err = grib_get_long_internal(h, self->typeOfTimeIncrement_, &typeOfTimeIncrement))) + if ((err = grib_get_long_internal(h, typeOfTimeIncrement_, &typeOfTimeIncrement))) return err; eccodes::Step start_step{ start_step_value, start_step_unit }; @@ -496,7 +490,7 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en grib_context_log(h->context, GRIB_LOG_ERROR, "%s:%s: Date/Time is not valid! " "year=%ld month=%ld day=%ld hour=%ld minute=%ld second=%ld", - a->class_name_, __func__, year, month, day, hour, minute, second); + class_name_, __func__, year, month, day, hour, minute, second); return GRIB_DECODING_ERROR; } @@ -513,17 +507,17 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en if (err != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(h, self->year_of_end_of_interval_, year_of_end_of_interval))) + if ((err = grib_set_long_internal(h, year_of_end_of_interval_, year_of_end_of_interval))) return err; - if ((err = grib_set_long_internal(h, self->month_of_end_of_interval_, month_of_end_of_interval))) + if ((err = grib_set_long_internal(h, month_of_end_of_interval_, month_of_end_of_interval))) return err; - if ((err = grib_set_long_internal(h, self->day_of_end_of_interval_, day_of_end_of_interval))) + if ((err = grib_set_long_internal(h, day_of_end_of_interval_, day_of_end_of_interval))) return err; - if ((err = grib_set_long_internal(h, self->hour_of_end_of_interval_, hour_of_end_of_interval))) + if ((err = grib_set_long_internal(h, hour_of_end_of_interval_, hour_of_end_of_interval))) return err; - if ((err = grib_set_long_internal(h, self->minute_of_end_of_interval_, minute_of_end_of_interval))) + if ((err = grib_set_long_internal(h, minute_of_end_of_interval_, minute_of_end_of_interval))) return err; - if ((err = grib_set_long_internal(h, self->second_of_end_of_interval_, second_of_end_of_interval))) + if ((err = grib_set_long_internal(h, second_of_end_of_interval_, second_of_end_of_interval))) return err; const char* forecast_time_value_key = "forecastTime"; @@ -538,13 +532,13 @@ static int pack_long_(grib_accessor* a, const long end_step_value, const long en time_range_opt = eccodes::Step{ time_range.value(eccodes::Unit{ force_step_units }), eccodes::Unit{ force_step_units } }; } - if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->time_range_value_, time_range_opt.value())) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(grib_handle_of_accessor(this), time_range_value_, time_range_opt.value())) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(grib_handle_of_accessor(a), self->time_range_unit_, time_range_opt.unit().value())) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(grib_handle_of_accessor(this), time_range_unit_, time_range_opt.unit().value())) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(grib_handle_of_accessor(a), forecast_time_value_key, forecast_time_opt.value())) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(grib_handle_of_accessor(this), forecast_time_value_key, forecast_time_opt.value())) != GRIB_SUCCESS) return err; - if ((err = grib_set_long_internal(grib_handle_of_accessor(a), forecast_time_unit_key, forecast_time_opt.unit().value())) != GRIB_SUCCESS) + if ((err = grib_set_long_internal(grib_handle_of_accessor(this), forecast_time_unit_key, forecast_time_opt.unit().value())) != GRIB_SUCCESS) return err; return GRIB_SUCCESS; @@ -614,7 +608,7 @@ int grib_accessor_g2end_step_t::pack_long(const long* val, size_t* len) else { end_step_unit = force_step_units; } - ret = pack_long_(this, *val, end_step_unit); + ret = pack_long_(*val, end_step_unit); } catch (std::exception& e) { grib_context_log(h->context, GRIB_LOG_ERROR, "grib_accessor_g2end_step_t::pack_long: %s", e.what()); @@ -638,7 +632,7 @@ int grib_accessor_g2end_step_t::pack_string(const char* val, size_t* len) if ((ret = grib_set_long_internal(h, "endStepUnit", end_step.unit().value())) != GRIB_SUCCESS) return ret; - if ((ret = pack_long_(this, end_step.value(), end_step.unit().value())) != GRIB_SUCCESS) + if ((ret = pack_long_(end_step.value(), end_step.unit().value())) != GRIB_SUCCESS) return ret; } catch (std::exception& e) { diff --git a/src/accessor/grib_accessor_class_g2end_step.h b/src/accessor/grib_accessor_class_g2end_step.h index 9bd3461d4..d66a01d5e 100644 --- a/src/accessor/grib_accessor_class_g2end_step.h +++ b/src/accessor/grib_accessor_class_g2end_step.h @@ -28,7 +28,7 @@ public: void dump(grib_dumper*) override; void init(const long, grib_arguments*) override; -public: +private: const char* start_step_value_; const char* step_units_; const char* year_; @@ -47,4 +47,10 @@ public: const char* time_range_value_; const char* typeOfTimeIncrement_; const char* numberOfTimeRanges_; + + int unpack_one_time_range_long_(long* val, size_t* len); + int unpack_one_time_range_double_(double* val, size_t* len); + int unpack_multiple_time_ranges_long_(long* val, size_t* len); + int unpack_multiple_time_ranges_double_(double* val, size_t* len); + int pack_long_(const long end_step_value, const long end_step_unit); }; diff --git a/src/accessor/grib_accessor_class_gen.h b/src/accessor/grib_accessor_class_gen.h index 407841dd2..bd3a1a8f5 100644 --- a/src/accessor/grib_accessor_class_gen.h +++ b/src/accessor/grib_accessor_class_gen.h @@ -73,7 +73,7 @@ public: template int unpack_helper(grib_accessor* a, T* v, size_t* len); -private: +public: enum { PACK_DOUBLE, diff --git a/src/accessor/grib_accessor_class_hash_array.cc b/src/accessor/grib_accessor_class_hash_array.cc index 789102ad9..b82d0cf79 100644 --- a/src/accessor/grib_accessor_class_hash_array.cc +++ b/src/accessor/grib_accessor_class_hash_array.cc @@ -64,16 +64,15 @@ int grib_accessor_hash_array_t::unpack_double(double* val, size_t* len) return GRIB_NOT_IMPLEMENTED; } -static grib_hash_array_value* find_hash_value(grib_accessor* a, int* err) +grib_hash_array_value* grib_accessor_hash_array_t::find_hash_value(int* err) { - grib_accessor_hash_array_t* self = (grib_accessor_hash_array_t*)a; grib_hash_array_value* ha_ret = 0; grib_hash_array_value* ha = NULL; - ha = get_hash_array(grib_handle_of_accessor(a), self->creator_); + ha = get_hash_array(grib_handle_of_accessor(this), creator_); if (!ha) { - grib_context_log(a->context_, GRIB_LOG_ERROR, - "unable to get hash value for %s", self->creator_->name); + grib_context_log(context_, GRIB_LOG_ERROR, + "unable to get hash value for %s", creator_->name); *err = GRIB_HASH_ARRAY_NO_MATCH; return NULL; } @@ -81,27 +80,27 @@ static grib_hash_array_value* find_hash_value(grib_accessor* a, int* err) *err = GRIB_SUCCESS; Assert(ha != NULL); - if (!self->key_) { - grib_context_log(a->context_, GRIB_LOG_ERROR, - "unable to get hash value for %s, set before getting", self->creator_->name); + if (!key_) { + grib_context_log(context_, GRIB_LOG_ERROR, + "unable to get hash value for %s, set before getting", creator_->name); *err = GRIB_HASH_ARRAY_NO_MATCH; return NULL; } - ha_ret = (grib_hash_array_value*)grib_trie_get(ha->index, self->key_); + ha_ret = (grib_hash_array_value*)grib_trie_get(ha->index, key_); if (!ha_ret) ha_ret = (grib_hash_array_value*)grib_trie_get(ha->index, "default"); if (!ha_ret) { *err = GRIB_HASH_ARRAY_NO_MATCH; - grib_context_log(a->context_, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, "hash_array: no match for %s=%s", - self->creator_->name, self->key_); - const char* full_path = get_hash_array_full_path(self->creator_); + creator_->name, key_); + const char* full_path = get_hash_array_full_path(creator_); if (full_path) { - grib_context_log(a->context_, GRIB_LOG_ERROR, "hash_array: file path = %s", full_path); + grib_context_log(context_, GRIB_LOG_ERROR, "hash_array: file path = %s", full_path); } - grib_context_log(a->context_, GRIB_LOG_ERROR, "Hint: Check the key 'masterTablesVersionNumber'"); + grib_context_log(context_, GRIB_LOG_ERROR, "Hint: Check the key 'masterTablesVersionNumber'"); return NULL; } return ha_ret; @@ -114,7 +113,7 @@ int grib_accessor_hash_array_t::unpack_long(long* val, size_t* len) size_t i = 0; if (!ha_) { - ha = find_hash_value(this, &err); + ha = find_hash_value(&err); if (err) return err; ha_ = ha; @@ -169,7 +168,7 @@ int grib_accessor_hash_array_t::value_count(long* count) grib_hash_array_value* ha = 0; if (!ha_) { - ha = find_hash_value(this, &err); + ha = find_hash_value(&err); if (err) return err; ha_ = ha; diff --git a/src/accessor/grib_accessor_class_hash_array.h b/src/accessor/grib_accessor_class_hash_array.h index 7819dbc8b..9dabd2db8 100644 --- a/src/accessor/grib_accessor_class_hash_array.h +++ b/src/accessor/grib_accessor_class_hash_array.h @@ -33,7 +33,9 @@ public: void init(const long, grib_arguments*) override; int compare(grib_accessor*) override; -public: +private: char* key_; grib_hash_array_value* ha_; + + grib_hash_array_value* find_hash_value(int* err); }; diff --git a/src/accessor/grib_accessor_class_iterator.h b/src/accessor/grib_accessor_class_iterator.h index dba32e6e5..13aadfcd9 100644 --- a/src/accessor/grib_accessor_class_iterator.h +++ b/src/accessor/grib_accessor_class_iterator.h @@ -21,8 +21,10 @@ public: void init(const long l, grib_arguments* args) override; void dump(grib_dumper* dumper) override; -public: +private: grib_arguments* args_; + + friend grib_iterator* grib_iterator_new(const grib_handle* ch, unsigned long flags, int* error); }; // grib_iterator* grib_iterator_new(const grib_handle* ch, unsigned long flags, int* error) diff --git a/src/accessor/grib_accessor_class_nearest.h b/src/accessor/grib_accessor_class_nearest.h index 3d6280743..0781f9132 100644 --- a/src/accessor/grib_accessor_class_nearest.h +++ b/src/accessor/grib_accessor_class_nearest.h @@ -21,8 +21,10 @@ public: void init(const long l, grib_arguments* args) override; void dump(grib_dumper* dumper) override; -public: +private: grib_arguments* args_; + + friend grib_nearest* grib_nearest_new(const grib_handle* ch, int* error); }; // grib_nearest* grib_nearest_new(const grib_handle* ch, int* error); diff --git a/src/accessor/grib_accessor_class_number_of_points_gaussian.cc b/src/accessor/grib_accessor_class_number_of_points_gaussian.cc index a62d8bf30..2876eda3d 100644 --- a/src/accessor/grib_accessor_class_number_of_points_gaussian.cc +++ b/src/accessor/grib_accessor_class_number_of_points_gaussian.cc @@ -122,15 +122,14 @@ int grib_accessor_number_of_points_gaussian_t::unpack_long(long* val, size_t* le return err; if (support_legacy == 1) - return unpack_long_with_legacy_support(this, val, len); + return unpack_long_with_legacy_support(val, len); else - return unpack_long_new(this, val, len); + return unpack_long_new(val, len); } /* New algorithm */ -static int unpack_long_new(grib_accessor* a, long* val, size_t* len) +int grib_accessor_number_of_points_gaussian_t::unpack_long_new(long* val, size_t* len) { - grib_accessor_number_of_points_gaussian_t* self = (grib_accessor_number_of_points_gaussian_t*)a; int err = GRIB_SUCCESS; int is_global = 0; long ni = 0, nj = 0, plpresent = 0, order = 0; @@ -142,17 +141,17 @@ static int unpack_long_new(grib_accessor* a, long* val, size_t* len) long ilon_first = 0, ilon_last = 0; double angular_precision = 1.0 / 1000000.0; long angleSubdivisions = 0; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); - grib_context* c = a->context_; + grib_context* c = context_; - if ((err = grib_get_long_internal(h, self->ni_, &ni)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, ni_, &ni)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(h, self->nj_, &nj)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, nj_, &nj)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(h, self->plpresent_, &plpresent)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, plpresent_, &plpresent)) != GRIB_SUCCESS) return err; if (nj == 0) @@ -169,23 +168,23 @@ static int unpack_long_new(grib_accessor* a, long* val, size_t* len) // double lon_first_row = 0, lon_last_row = 0; /*reduced*/ - if ((err = grib_get_long_internal(h, self->order_, &order)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, order_, &order)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->lat_first_, &lat_first)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, lat_first_, &lat_first)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->lon_first_, &lon_first)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, lon_first_, &lon_first)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->lat_last_, &lat_last)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, lat_last_, &lat_last)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->lon_last_, &lon_last)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, lon_last_, &lon_last)) != GRIB_SUCCESS) return err; - if ((err = grib_get_size(h, self->pl_, &plsize)) != GRIB_SUCCESS) + if ((err = grib_get_size(h, pl_, &plsize)) != GRIB_SUCCESS) return err; pl = (long*)grib_context_malloc_clear(c, sizeof(long) * plsize); plsave = pl; - grib_get_long_array_internal(h, self->pl_, pl, &plsize); + grib_get_long_array_internal(h, pl_, pl, &plsize); if (lon_last < 0) lon_last += 360; @@ -237,9 +236,8 @@ static int unpack_long_new(grib_accessor* a, long* val, size_t* len) } /* With Legacy support */ -static int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t* len) +int grib_accessor_number_of_points_gaussian_t::unpack_long_with_legacy_support(long* val, size_t* len) { - grib_accessor_number_of_points_gaussian_t* self = (grib_accessor_number_of_points_gaussian_t*)a; int err = GRIB_SUCCESS; int is_global = 0; long ni = 0, nj = 0, plpresent = 0, order = 0; @@ -251,18 +249,18 @@ static int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t* long ilon_first = 0, ilon_last = 0; double angular_precision = 1.0 / 1000000.0; long angleSubdivisions = 0; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); size_t numDataValues = 0; - grib_context* c = a->context_; + grib_context* c = context_; - if ((err = grib_get_long_internal(h, self->ni_, &ni)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, ni_, &ni)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(h, self->nj_, &nj)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, nj_, &nj)) != GRIB_SUCCESS) return err; - if ((err = grib_get_long_internal(h, self->plpresent_, &plpresent)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, plpresent_, &plpresent)) != GRIB_SUCCESS) return err; if (nj == 0) @@ -279,23 +277,23 @@ static int unpack_long_with_legacy_support(grib_accessor* a, long* val, size_t* // double lon_first_row = 0, lon_last_row = 0; /*reduced*/ - if ((err = grib_get_long_internal(h, self->order_, &order)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, order_, &order)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->lat_first_, &lat_first)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, lat_first_, &lat_first)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->lon_first_, &lon_first)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, lon_first_, &lon_first)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->lat_last_, &lat_last)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, lat_last_, &lat_last)) != GRIB_SUCCESS) return err; - if ((err = grib_get_double_internal(h, self->lon_last_, &lon_last)) != GRIB_SUCCESS) + if ((err = grib_get_double_internal(h, lon_last_, &lon_last)) != GRIB_SUCCESS) return err; - if ((err = grib_get_size(h, self->pl_, &plsize)) != GRIB_SUCCESS) + if ((err = grib_get_size(h, pl_, &plsize)) != GRIB_SUCCESS) return err; pl = (long*)grib_context_malloc_clear(c, sizeof(long) * plsize); plsave = pl; - grib_get_long_array_internal(h, self->pl_, pl, &plsize); + grib_get_long_array_internal(h, pl_, pl, &plsize); if (lon_last < 0) lon_last += 360; diff --git a/src/accessor/grib_accessor_class_number_of_points_gaussian.h b/src/accessor/grib_accessor_class_number_of_points_gaussian.h index 6b47f7a0e..530f1ad27 100644 --- a/src/accessor/grib_accessor_class_number_of_points_gaussian.h +++ b/src/accessor/grib_accessor_class_number_of_points_gaussian.h @@ -22,7 +22,7 @@ public: int unpack_long(long* val, size_t* len) override; void init(const long, grib_arguments*) override; -public: +private: const char* ni_; const char* nj_; const char* plpresent_; @@ -33,4 +33,7 @@ public: const char* lat_last_; const char* lon_last_; const char* support_legacy_; + + int unpack_long_new(long* val, size_t* len); + int unpack_long_with_legacy_support(long* val, size_t* len); }; diff --git a/src/accessor/grib_accessor_class_signed_bits.cc b/src/accessor/grib_accessor_class_signed_bits.cc index 2c2587338..af75c55cf 100644 --- a/src/accessor/grib_accessor_class_signed_bits.cc +++ b/src/accessor/grib_accessor_class_signed_bits.cc @@ -18,24 +18,23 @@ long grib_accessor_signed_bits_t::byte_count() return length_; } -static long compute_byte_count(grib_accessor* a) +long grib_accessor_signed_bits_t::compute_byte_count() { - grib_accessor_signed_bits_t* self = (grib_accessor_signed_bits_t*)a; long numberOfBits; long numberOfElements; int ret = 0; - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits_, &numberOfBits); + ret = grib_get_long(grib_handle_of_accessor(this), numberOfBits_, &numberOfBits); if (ret) { - grib_context_log(a->context_, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name_, self->numberOfBits_); + grib_context_log(context_, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", name_, numberOfBits_); return 0; } - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements_, &numberOfElements); + ret = grib_get_long(grib_handle_of_accessor(this), numberOfElements_, &numberOfElements); if (ret) { - grib_context_log(a->context_, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name_, self->numberOfElements_); + grib_context_log(context_, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", name_, numberOfElements_); return 0; } @@ -48,7 +47,7 @@ void grib_accessor_signed_bits_t::init(const long len, grib_arguments* args) int n = 0; numberOfBits_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); numberOfElements_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); - length_ = compute_byte_count(this); + length_ = compute_byte_count(); } int grib_accessor_signed_bits_t::unpack_long(long* val, size_t* len) diff --git a/src/accessor/grib_accessor_class_signed_bits.h b/src/accessor/grib_accessor_class_signed_bits.h index 9d37550f4..e257343e7 100644 --- a/src/accessor/grib_accessor_class_signed_bits.h +++ b/src/accessor/grib_accessor_class_signed_bits.h @@ -28,7 +28,9 @@ public: void init(const long, grib_arguments*) override; void update_size(size_t) override; -public: +private: const char* numberOfBits_; const char* numberOfElements_; + + long compute_byte_count(); }; diff --git a/src/accessor/grib_accessor_class_smart_table.cc b/src/accessor/grib_accessor_class_smart_table.cc index f628fba79..d0e629b19 100644 --- a/src/accessor/grib_accessor_class_smart_table.cc +++ b/src/accessor/grib_accessor_class_smart_table.cc @@ -65,11 +65,10 @@ void grib_accessor_smart_table_t::init(const long len, grib_arguments* params) table_ = NULL; } -grib_smart_table* load_table(grib_accessor* a) +grib_smart_table* grib_accessor_smart_table_t::load_table() { - grib_accessor_smart_table_t* self = (grib_accessor_smart_table_t*)a; size_t size = 0; - grib_handle* h = ((grib_accessor*)self)->parent_->h; + grib_handle* h = this->parent_->h; grib_context* c = h->context; grib_smart_table* t = NULL; grib_smart_table* next = NULL; @@ -96,30 +95,30 @@ grib_smart_table* load_table(grib_accessor* a) }; size_t len = 1024; - if (self->masterDir_ != NULL) { - grib_get_string(h, self->masterDir_, masterDir, &len); + if (masterDir_ != NULL) { + grib_get_string(h, masterDir_, masterDir, &len); } len = 1024; - if (self->localDir_ != NULL) { - grib_get_string(h, self->localDir_, localDir, &len); + if (localDir_ != NULL) { + grib_get_string(h, localDir_, localDir, &len); } len = 1024; - if (self->extraDir_ != NULL && self->extraTable_ != NULL) { - grib_get_string(h, self->extraDir_, extraDir, &len); + if (extraDir_ != NULL && extraTable_ != NULL) { + grib_get_string(h, extraDir_, extraDir, &len); } if (*masterDir != 0) { char name[2048] = { 0, }; - snprintf(name, sizeof(name), "%s/%s", masterDir, self->tablename_); + snprintf(name, sizeof(name), "%s/%s", masterDir, tablename_); grib_recompose_name(h, NULL, name, recomposed, 0); filename = grib_context_full_defs_path(c, recomposed); } else { - grib_recompose_name(h, NULL, self->tablename_, recomposed, 0); + grib_recompose_name(h, NULL, tablename_, recomposed, 0); filename = grib_context_full_defs_path(c, recomposed); } @@ -127,7 +126,7 @@ grib_smart_table* load_table(grib_accessor* a) char localName[2048] = { 0, }; - snprintf(localName, sizeof(localName), "%s/%s", localDir, self->tablename_); + snprintf(localName, sizeof(localName), "%s/%s", localDir, tablename_); grib_recompose_name(h, NULL, localName, localRecomposed, 0); localFilename = grib_context_full_defs_path(c, localRecomposed); } @@ -136,7 +135,7 @@ grib_smart_table* load_table(grib_accessor* a) char extraTable[2048] = { 0, }; - snprintf(extraTable, sizeof(extraTable), "%s/%s", extraDir, self->extraTable_); + snprintf(extraTable, sizeof(extraTable), "%s/%s", extraDir, extraTable_); grib_recompose_name(h, NULL, extraTable, extraRecomposed, 0); extraFilename = grib_context_full_defs_path(c, extraRecomposed); } @@ -155,7 +154,7 @@ grib_smart_table* load_table(grib_accessor* a) // Note: widthOfCode_ is chosen so that 2^width is bigger than the maximum descriptor code, // which for BUFR4 is the Table C operator 243255 // - size = (1ULL << self->widthOfCode_); // = 2^widthOfCode_ (as a 64 bit number) + size = (1ULL << widthOfCode_); // = 2^widthOfCode_ (as a 64 bit number) t = (grib_smart_table*)grib_context_malloc_clear_persistent(c, sizeof(grib_smart_table)); t->entries = (grib_smart_table_entry*)grib_context_malloc_clear_persistent(c, size * sizeof(grib_smart_table_entry)); @@ -317,7 +316,7 @@ int grib_accessor_smart_table_t::unpack_string(char* buffer, size_t* len) return err; if (!table_) - table_ = load_table(this); + table_ = load_table(); table = table_; if (table && (value >= 0) && (value < table->numberOfEntries) && table->entries[value].abbreviation) { @@ -341,9 +340,8 @@ int grib_accessor_smart_table_t::unpack_string(char* buffer, size_t* len) return GRIB_SUCCESS; } -static int get_table_codes(grib_accessor* a) +int grib_accessor_smart_table_t::get_table_codes() { - grib_accessor_smart_table_t* self = (grib_accessor_smart_table_t*)a; size_t size = 0; long* v = 0; int err = 0; @@ -352,43 +350,43 @@ static int get_table_codes(grib_accessor* a) int table_size; - if (!a->dirty_) + if (!dirty_) return 0; - table_size = (1 << self->widthOfCode_); // 2 ^ widthOfCode_ + table_size = (1 << widthOfCode_); // 2 ^ widthOfCode_ - if (!self->table_) - self->table_ = load_table(a); + if (!table_) + table_ = load_table(); - err = grib_get_size(grib_handle_of_accessor(a), self->values_, &size); + err = grib_get_size(grib_handle_of_accessor(this), values_, &size); if (err) { - grib_context_log(a->context_, GRIB_LOG_ERROR, - "unable to get size of %s", a->name_); + grib_context_log(context_, GRIB_LOG_ERROR, + "unable to get size of %s", name_); return err; } - v = (long*)grib_context_malloc_clear(a->context_, size * sizeof(long)); + v = (long*)grib_context_malloc_clear(context_, size * sizeof(long)); - grib_get_long_array(grib_handle_of_accessor(a), self->values_, v, &size); + grib_get_long_array(grib_handle_of_accessor(this), values_, v, &size); count = 0; for (i = 0; i < size; i++) { if (v[i] < table_size) count++; } - if (self->tableCodes_) - grib_context_free(a->context_, self->tableCodes_); - self->tableCodes_ = (long*)grib_context_malloc_clear(a->context_, count * sizeof(long)); + if (tableCodes_) + grib_context_free(context_, tableCodes_); + tableCodes_ = (long*)grib_context_malloc_clear(context_, count * sizeof(long)); j = 0; for (i = 0; i < size; i++) { if (v[i] < table_size) - self->tableCodes_[j++] = v[i]; + tableCodes_[j++] = v[i]; } - grib_context_free(a->context_, v); + grib_context_free(context_, v); - self->tableCodesSize_ = count; - a->dirty_ = 0; + tableCodesSize_ = count; + dirty_ = 0; return 0; } @@ -400,7 +398,7 @@ int grib_accessor_smart_table_t::value_count(long* count) if (!values_) return 0; - err = get_table_codes(this); + err = get_table_codes(); if (err) return err; @@ -438,7 +436,7 @@ int grib_accessor_smart_table_t::unpack_long(long* val, size_t* len) if (!values_) return 0; - err = get_table_codes(this); + err = get_table_codes(); if (err) return 0; diff --git a/src/accessor/grib_accessor_class_smart_table.h b/src/accessor/grib_accessor_class_smart_table.h index ff601c062..d6baae111 100644 --- a/src/accessor/grib_accessor_class_smart_table.h +++ b/src/accessor/grib_accessor_class_smart_table.h @@ -28,6 +28,10 @@ public: void init(const long, grib_arguments*) override; public: + // TODO(maee): make private + grib_smart_table* table_; + +private: const char* values_; const char* tablename_; const char* masterDir_; @@ -37,5 +41,7 @@ public: int widthOfCode_; long* tableCodes_; size_t tableCodesSize_; - grib_smart_table* table_; + + grib_smart_table* load_table(); + int get_table_codes(); }; diff --git a/src/accessor/grib_accessor_class_spd.cc b/src/accessor/grib_accessor_class_spd.cc index ae746cc7f..8d0df9bad 100644 --- a/src/accessor/grib_accessor_class_spd.cc +++ b/src/accessor/grib_accessor_class_spd.cc @@ -18,23 +18,22 @@ long grib_accessor_spd_t::byte_count() return length_; } -static long compute_byte_count(grib_accessor* a) +long grib_accessor_spd_t::compute_byte_count() { - grib_accessor_spd_t* self = (grib_accessor_spd_t*)a; long numberOfBits = 0; long numberOfElements = 0; - int ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits_, &numberOfBits); + int ret = grib_get_long(grib_handle_of_accessor(this), numberOfBits_, &numberOfBits); if (ret) { - grib_context_log(a->context_, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name_, self->numberOfBits_); + grib_context_log(context_, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", name_, numberOfBits_); return 0; } - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements_, &numberOfElements); + ret = grib_get_long(grib_handle_of_accessor(this), numberOfElements_, &numberOfElements); if (ret) { - grib_context_log(a->context_, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name_, self->numberOfElements_); + grib_context_log(context_, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", name_, numberOfElements_); return 0; } numberOfElements++; @@ -48,7 +47,7 @@ void grib_accessor_spd_t::init(const long len, grib_arguments* args) int n = 0; numberOfBits_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); numberOfElements_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); - length_ = compute_byte_count(this); + length_ = compute_byte_count(); } int grib_accessor_spd_t::unpack_long(long* val, size_t* len) @@ -109,7 +108,7 @@ int grib_accessor_spd_t::pack_long(const long* val, size_t* len) if (ret) return ret; - buflen = compute_byte_count(this); + buflen = compute_byte_count(); buf = (unsigned char*)grib_context_malloc_clear(context_, buflen); for (i = 0; i < rlen - 1; i++) { diff --git a/src/accessor/grib_accessor_class_spd.h b/src/accessor/grib_accessor_class_spd.h index 06114dc09..9c9ecd070 100644 --- a/src/accessor/grib_accessor_class_spd.h +++ b/src/accessor/grib_accessor_class_spd.h @@ -28,7 +28,9 @@ public: void init(const long, grib_arguments*) override; void update_size(size_t) override; -public: +private: const char* numberOfBits_; const char* numberOfElements_; + + long compute_byte_count(); }; diff --git a/src/accessor/grib_accessor_class_step_in_units.cc b/src/accessor/grib_accessor_class_step_in_units.cc index 651e4dfa1..d63a13c76 100644 --- a/src/accessor/grib_accessor_class_step_in_units.cc +++ b/src/accessor/grib_accessor_class_step_in_units.cc @@ -92,19 +92,18 @@ int grib_accessor_step_in_units_t::unpack_double(double* val, size_t* len) return GRIB_SUCCESS; } -static int pack_long_new_(grib_accessor* a, const long start_step_value, const long start_step_unit, const long force_step_units) +int grib_accessor_step_in_units_t::pack_long_new_(const long start_step_value, const long start_step_unit, const long force_step_units) { - const grib_accessor_step_in_units_t* self = (grib_accessor_step_in_units_t*)a; - grib_handle* h = grib_handle_of_accessor(a); + grib_handle* h = grib_handle_of_accessor(this); int err = 0; long forecast_time_unit; long start_step_value_old; long start_step_unit_old; size_t len = 0; - if ((err = grib_get_long_internal(h, self->forecast_time_unit_, &forecast_time_unit)) != GRIB_SUCCESS) + if ((err = grib_get_long_internal(h, forecast_time_unit_, &forecast_time_unit)) != GRIB_SUCCESS) return err; - if ((err = a->unpack_long(&start_step_value_old, &len)) != GRIB_SUCCESS) + if ((err = unpack_long(&start_step_value_old, &len)) != GRIB_SUCCESS) return err; if ((err = grib_get_long_internal(h, "startStepUnit", &start_step_unit_old)) != GRIB_SUCCESS) return err; @@ -113,7 +112,7 @@ static int pack_long_new_(grib_accessor* a, const long start_step_value, const l eccodes::Step forecast_time(start_step_value, start_step_unit); eccodes::Step time_range_new{}; - auto time_range_opt = get_step(h, self->time_range_value_, self->time_range_unit_); + auto time_range_opt = get_step(h, time_range_value_, time_range_unit_); if (time_range_opt) { auto time_range = time_range_opt.value(); @@ -121,11 +120,11 @@ static int pack_long_new_(grib_accessor* a, const long start_step_value, const l if (time_range.value() < 0) time_range = eccodes::Step{ 0l, time_range.unit() }; auto [sa, sb] = find_common_units(forecast_time.optimize_unit(), time_range.optimize_unit()); - if ((err = set_step(h, self->forecast_time_value_, self->forecast_time_unit_, sa)) != GRIB_SUCCESS) + if ((err = set_step(h, forecast_time_value_, forecast_time_unit_, sa)) != GRIB_SUCCESS) return err; if ((err = grib_set_long_internal(h, "startStepUnit", forecast_time.unit().value())) != GRIB_SUCCESS) return err; - if ((err = set_step(h, self->time_range_value_, self->time_range_unit_, sb)) != GRIB_SUCCESS) + if ((err = set_step(h, time_range_value_, time_range_unit_, sb)) != GRIB_SUCCESS) return err; return GRIB_SUCCESS; } @@ -136,7 +135,7 @@ static int pack_long_new_(grib_accessor* a, const long start_step_value, const l if ((err = grib_set_long_internal(h, "startStepUnit", forecast_time.unit().value())) != GRIB_SUCCESS) return err; - if ((err = set_step(h, self->forecast_time_value_, self->forecast_time_unit_, forecast_time)) != GRIB_SUCCESS) + if ((err = set_step(h, forecast_time_value_, forecast_time_unit_, forecast_time)) != GRIB_SUCCESS) return err; return GRIB_SUCCESS; @@ -169,7 +168,7 @@ int grib_accessor_step_in_units_t::pack_long(const long* val, size_t* len) return GRIB_DECODING_ERROR; } - ret = pack_long_new_(this, *val, start_step_unit, force_step_units); + ret = pack_long_new_(*val, start_step_unit, force_step_units); return ret; } @@ -185,7 +184,7 @@ int grib_accessor_step_in_units_t::pack_string(const char* val, size_t* len) try { eccodes::Step step = step_from_string(val, eccodes::Unit{ force_step_units }); - if ((ret = pack_long_new_(this, step.value(), step.unit().value(), force_step_units)) != GRIB_SUCCESS) + if ((ret = pack_long_new_(step.value(), step.unit().value(), force_step_units)) != GRIB_SUCCESS) return ret; } catch (std::exception& e) { diff --git a/src/accessor/grib_accessor_class_step_in_units.h b/src/accessor/grib_accessor_class_step_in_units.h index 74c71a0af..49c3403e0 100644 --- a/src/accessor/grib_accessor_class_step_in_units.h +++ b/src/accessor/grib_accessor_class_step_in_units.h @@ -28,10 +28,12 @@ public: void dump(grib_dumper*) override; void init(const long, grib_arguments*) override; -public: +private: const char* forecast_time_value_; const char* forecast_time_unit_; const char* step_units_; const char* time_range_unit_; const char* time_range_value_; + + int pack_long_new_(const long start_step_value, const long start_step_unit, const long force_step_units); }; diff --git a/src/accessor/grib_accessor_class_suppressed.cc b/src/accessor/grib_accessor_class_suppressed.cc index 29a78cc1b..f0de3960f 100644 --- a/src/accessor/grib_accessor_class_suppressed.cc +++ b/src/accessor/grib_accessor_class_suppressed.cc @@ -22,38 +22,37 @@ void grib_accessor_suppressed_t::init(const long l, grib_arguments* c) length_ = 0; } -static void log_message(grib_accessor* a) +void grib_accessor_suppressed_t::log_message() { - grib_accessor_suppressed_t* self = (grib_accessor_suppressed_t*)a; int i = 0; - grib_handle* hand = grib_handle_of_accessor(a); + grib_handle* hand = grib_handle_of_accessor(this); - grib_context_log(a->context_, GRIB_LOG_ERROR, - "key '%s' is unavailable in this version.", a->name_); - grib_context_log(a->context_, GRIB_LOG_ERROR, + grib_context_log(context_, GRIB_LOG_ERROR, + "key '%s' is unavailable in this version.", name_); + grib_context_log(context_, GRIB_LOG_ERROR, "Please use the following key(s):"); - while (grib_arguments_get_name(hand, self->args_, i)) { - grib_context_log(a->context_, GRIB_LOG_ERROR, "\t- %s", - grib_arguments_get_name(hand, self->args_, i)); + while (grib_arguments_get_name(hand, args_, i)) { + grib_context_log(context_, GRIB_LOG_ERROR, "\t- %s", + grib_arguments_get_name(hand, args_, i)); i++; } } int grib_accessor_suppressed_t::unpack_string(char* val, size_t* len) { - log_message(this); + log_message(); return GRIB_NOT_FOUND; } int grib_accessor_suppressed_t::unpack_long(long* val, size_t* len) { - log_message(this); + log_message(); return GRIB_NOT_FOUND; } int grib_accessor_suppressed_t::unpack_double(double* val, size_t* len) { - log_message(this); + log_message(); return GRIB_NOT_FOUND; } diff --git a/src/accessor/grib_accessor_class_suppressed.h b/src/accessor/grib_accessor_class_suppressed.h index 9c4f0a243..2fce6dc51 100644 --- a/src/accessor/grib_accessor_class_suppressed.h +++ b/src/accessor/grib_accessor_class_suppressed.h @@ -26,6 +26,8 @@ public: int value_count(long*) override; void init(const long, grib_arguments*) override; -public: +private: grib_arguments* args_; + + void log_message(); }; diff --git a/src/accessor/grib_accessor_class_unsigned_bits.cc b/src/accessor/grib_accessor_class_unsigned_bits.cc index edaa9bbe1..eeb34614d 100644 --- a/src/accessor/grib_accessor_class_unsigned_bits.cc +++ b/src/accessor/grib_accessor_class_unsigned_bits.cc @@ -13,24 +13,23 @@ grib_accessor_unsigned_bits_t _grib_accessor_unsigned_bits{}; grib_accessor* grib_accessor_unsigned_bits = &_grib_accessor_unsigned_bits; -static long compute_byte_count(grib_accessor* a) +long grib_accessor_unsigned_bits_t::compute_byte_count() { - grib_accessor_unsigned_bits_t* self = (grib_accessor_unsigned_bits_t*)a; long numberOfBits; long numberOfElements; int ret = 0; - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfBits_, &numberOfBits); + ret = grib_get_long(grib_handle_of_accessor(this), numberOfBits_, &numberOfBits); if (ret) { - grib_context_log(a->context_, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name_, self->numberOfBits_); + grib_context_log(context_, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", name_, numberOfBits_); return 0; } - ret = grib_get_long(grib_handle_of_accessor(a), self->numberOfElements_, &numberOfElements); + ret = grib_get_long(grib_handle_of_accessor(this), numberOfElements_, &numberOfElements); if (ret) { - grib_context_log(a->context_, GRIB_LOG_ERROR, - "%s unable to get %s to compute size", a->name_, self->numberOfElements_); + grib_context_log(context_, GRIB_LOG_ERROR, + "%s unable to get %s to compute size", name_, numberOfElements_); return 0; } @@ -43,7 +42,7 @@ void grib_accessor_unsigned_bits_t::init(const long len, grib_arguments* args) int n = 0; numberOfBits_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); numberOfElements_ = grib_arguments_get_name(grib_handle_of_accessor(this), args, n++); - length_ = compute_byte_count(this); + length_ = compute_byte_count(); } int grib_accessor_unsigned_bits_t::unpack_long(long* val, size_t* len) @@ -112,7 +111,7 @@ int grib_accessor_unsigned_bits_t::pack_long(const long* val, size_t* len) return GRIB_SUCCESS; } - buflen = compute_byte_count(this); + buflen = compute_byte_count(); buf = (unsigned char*)grib_context_malloc_clear(context_, buflen + sizeof(long)); for (i = 0; i < *len; i++) diff --git a/src/accessor/grib_accessor_class_unsigned_bits.h b/src/accessor/grib_accessor_class_unsigned_bits.h index 66512187f..a93256da1 100644 --- a/src/accessor/grib_accessor_class_unsigned_bits.h +++ b/src/accessor/grib_accessor_class_unsigned_bits.h @@ -28,7 +28,9 @@ public: void init(const long, grib_arguments*) override; void update_size(size_t) override; -public: +private: const char* numberOfBits_; const char* numberOfElements_; + + long compute_byte_count(); }; diff --git a/src/accessor/grib_accessor_class_variable.h b/src/accessor/grib_accessor_class_variable.h index 3051ab58f..c95343986 100644 --- a/src/accessor/grib_accessor_class_variable.h +++ b/src/accessor/grib_accessor_class_variable.h @@ -37,10 +37,12 @@ public: int compare(grib_accessor*) override; grib_accessor* make_clone(grib_section*, int*) override; -public: +private: double dval_; float fval_; char* cval_; char* cname_; int type_; + + friend void accessor_variable_set_type(grib_accessor* a, int type); };