Modernisation: Private member variables in bufr_data_array

This commit is contained in:
Eugen Betke 2024-09-19 17:34:41 +02:00
parent faf8197aad
commit 3a52f55e46
7 changed files with 606 additions and 563 deletions

File diff suppressed because it is too large Load Diff

View File

@ -12,6 +12,21 @@
#include "grib_accessor_class_gen.h" #include "grib_accessor_class_gen.h"
typedef struct bitmap_s
{
grib_accessors_list* cursor;
grib_accessors_list* referredElement;
grib_accessors_list* referredElementStart;
} bitmap_s;
class grib_accessor_bufr_data_array_t;
typedef int (*codec_element_proc)(grib_context*, grib_accessor_bufr_data_array_t*, int, grib_buffer*, unsigned char*, long*, int, bufr_descriptor*, long, grib_darray*, grib_sarray*);
typedef int (*codec_replication_proc)(grib_context*, grib_accessor_bufr_data_array_t*, int, grib_buffer*, unsigned char*, long*, int, long, grib_darray*, long*);
class grib_accessor_bufr_data_array_t : public grib_accessor_gen_t class grib_accessor_bufr_data_array_t : public grib_accessor_gen_t
{ {
public: public:
@ -30,7 +45,12 @@ public:
void dump(grib_dumper*) override; void dump(grib_dumper*) override;
void init(const long, grib_arguments*) override; void init(const long, grib_arguments*) override;
public: void accessor_bufr_data_array_set_unpackMode(int);
grib_accessors_list* accessor_bufr_data_array_get_dataAccessors();
grib_trie_with_rank* accessor_bufr_data_array_get_dataAccessorsTrie();
grib_vsarray* accessor_bufr_data_array_get_stringValues();
private:
const char* bufrDataEncodedName_; const char* bufrDataEncodedName_;
const char* numberOfSubsetsName_; const char* numberOfSubsetsName_;
const char* expandedDescriptorsName_; const char* expandedDescriptorsName_;
@ -78,9 +98,47 @@ public:
long refValIndex_; long refValIndex_;
bufr_tableb_override* tableb_override_; bufr_tableb_override* tableb_override_;
int set_to_missing_if_out_of_range_; int set_to_missing_if_out_of_range_;
};
grib_vsarray* accessor_bufr_data_array_get_stringValues(grib_accessor*); void restart_bitmap();
grib_accessors_list* accessor_bufr_data_array_get_dataAccessors(grib_accessor*); void cancel_bitmap();
grib_trie_with_rank* accessor_bufr_data_array_get_dataAccessorsTrie(grib_accessor*); int is_bitmap_start_defined();
void accessor_bufr_data_array_set_unpackMode(grib_accessor*, int unpackMode); size_t get_length();
void tableB_override_store_ref_val(grib_context*, int, long);
int tableB_override_get_ref_val(int, long*);
void tableB_override_clear(grib_context*);
int tableB_override_set_key(grib_handle*);
int get_descriptors();
int decode_string_array(grib_context*, unsigned char*, long*, bufr_descriptor*);
int encode_string_array(grib_context*, grib_buffer*, long*, bufr_descriptor*, grib_sarray*);
int encode_double_array(grib_context*, grib_buffer*, long*, bufr_descriptor*, grib_darray*);
int encode_double_value(grib_context*, grib_buffer*, long*, bufr_descriptor*, double);
char* decode_string_value(grib_context*, unsigned char*, long*, bufr_descriptor*, int*);
double decode_double_value(grib_context*, unsigned char*, long*, bufr_descriptor*, int, int*);
int encode_new_bitmap(grib_context*, grib_buffer*, long*, int);
grib_darray* doubleValues = NULL;
int encode_overridden_reference_value(grib_context*, grib_buffer*, long*, bufr_descriptor*);
int build_bitmap(unsigned char*, long*, int, grib_iarray*, int);
int consume_bitmap(int);
int build_bitmap_new_data(unsigned char*, long*, int, grib_iarray*, int);
int get_next_bitmap_descriptor_index_new_bitmap(grib_iarray*, int);
int get_next_bitmap_descriptor_index(grib_iarray*, grib_darray*);
void push_zero_element(grib_darray*);
grib_accessor* create_attribute_variable(const char*, grib_section*, int, char*, double, long, unsigned long);
grib_accessor* create_accessor_from_descriptor(grib_accessor*, grib_section*, long, long, int, int, int, int);
grib_iarray* set_subset_list( grib_context*, long, long, long, const long*, size_t);
void print_bitmap_debug_info(grib_context*, bitmap_s*, grib_accessors_list*, int);
int create_keys(long, long, long);
void set_input_replications(grib_handle*);
void set_input_bitmap(grib_handle*);
int process_elements(int, long, long, long);
void self_clear();
grib_darray* decode_double_array(grib_context* c, unsigned char* data, long* pos, bufr_descriptor* bd, int canBeMissing, int*);
friend int check_end_data(grib_context*, bufr_descriptor*, grib_accessor_bufr_data_array_t*, int);
friend int decode_element(grib_context*, grib_accessor_bufr_data_array_t*, int, grib_buffer*, unsigned char*, long*, int, bufr_descriptor*, long, grib_darray*, grib_sarray*);
friend int decode_replication(grib_context*, grib_accessor_bufr_data_array_t*, int, grib_buffer*, unsigned char*, long*, int, long, grib_darray*, long*);
friend int encode_new_element(grib_context*, grib_accessor_bufr_data_array_t*, int, grib_buffer*, unsigned char*, long*, int, bufr_descriptor*, long, grib_darray*, grib_sarray*);
friend int encode_new_replication(grib_context*, grib_accessor_bufr_data_array_t*, int, grib_buffer*, unsigned char*, long*, int, long, grib_darray*, long*);
friend int encode_element(grib_context*, grib_accessor_bufr_data_array_t*, int, grib_buffer*, unsigned char*, long*, int, bufr_descriptor*, long, grib_darray*, grib_sarray*);
friend int encode_replication(grib_context*, grib_accessor_bufr_data_array_t*, int, grib_buffer*, unsigned char*, long*, int, long, grib_darray*, long*);
};

View File

@ -40,18 +40,18 @@ grib_accessor* grib_accessor_bufr_string_values_t::get_accessor()
int grib_accessor_bufr_string_values_t::unpack_string_array(char** buffer, size_t* len) int grib_accessor_bufr_string_values_t::unpack_string_array(char** buffer, size_t* len)
{ {
grib_accessor* data = 0; grib_accessor_bufr_data_array_t* data = 0;
grib_context* c = context_; grib_context* c = context_;
grib_vsarray* stringValues = NULL; grib_vsarray* stringValues = NULL;
size_t l = 0, tl; size_t l = 0, tl;
size_t i, j, n = 0; size_t i, j, n = 0;
char** b = buffer; char** b = buffer;
data = get_accessor(); data = dynamic_cast<grib_accessor_bufr_data_array_t*>(get_accessor());
if (!data) if (!data)
return GRIB_NOT_FOUND; return GRIB_NOT_FOUND;
stringValues = accessor_bufr_data_array_get_stringValues(data); stringValues = data->accessor_bufr_data_array_get_stringValues();
n = grib_vsarray_used_size(stringValues); n = grib_vsarray_used_size(stringValues);

View File

@ -9,7 +9,6 @@
*/ */
#include "grib_accessor_class_unpack_bufr_values.h" #include "grib_accessor_class_unpack_bufr_values.h"
#include "grib_accessor_class_bufr_data_array.h"
grib_accessor_unpack_bufr_values_t _grib_accessor_unpack_bufr_values{}; grib_accessor_unpack_bufr_values_t _grib_accessor_unpack_bufr_values{};
grib_accessor* grib_accessor_unpack_bufr_values = &_grib_accessor_unpack_bufr_values; grib_accessor* grib_accessor_unpack_bufr_values = &_grib_accessor_unpack_bufr_values;
@ -19,7 +18,7 @@ void grib_accessor_unpack_bufr_values_t::init(const long len, grib_arguments* pa
grib_accessor_gen_t::init(len, params); grib_accessor_gen_t::init(len, params);
char* key; char* key;
key = (char*)grib_arguments_get_name(grib_handle_of_accessor(this), params, 0); key = (char*)grib_arguments_get_name(grib_handle_of_accessor(this), params, 0);
data_accessor_ = grib_find_accessor(grib_handle_of_accessor(this), key); data_accessor_ = dynamic_cast<grib_accessor_bufr_data_array_t*>(grib_find_accessor(grib_handle_of_accessor(this), key));
length_ = 0; length_ = 0;
} }
@ -89,7 +88,7 @@ int grib_accessor_unpack_bufr_values_t::pack_long(const long* val, size_t* len)
if (*val == 3) if (*val == 3)
unpackMode = CODES_BUFR_NEW_DATA; unpackMode = CODES_BUFR_NEW_DATA;
accessor_bufr_data_array_set_unpackMode(data_accessor_, unpackMode); data_accessor_->accessor_bufr_data_array_set_unpackMode(unpackMode);
return data_accessor_->unpack_double(0, 0); return data_accessor_->unpack_double(0, 0);
} }

View File

@ -12,6 +12,7 @@
#pragma once #pragma once
#include "grib_accessor_class_gen.h" #include "grib_accessor_class_gen.h"
#include "grib_accessor_class_bufr_data_array.h"
class grib_accessor_unpack_bufr_values_t : public grib_accessor_gen_t class grib_accessor_unpack_bufr_values_t : public grib_accessor_gen_t
{ {
@ -32,5 +33,5 @@ public:
void init(const long, grib_arguments*) override; void init(const long, grib_arguments*) override;
private: private:
grib_accessor* data_accessor_; grib_accessor_bufr_data_array_t* data_accessor_;
}; };

View File

@ -212,7 +212,8 @@ static char* get_condition(const char* name, codes_condition* condition)
static grib_accessor* _search_by_rank(grib_accessor* a, const char* name, int rank) static grib_accessor* _search_by_rank(grib_accessor* a, const char* name, int rank)
{ {
grib_trie_with_rank* t = accessor_bufr_data_array_get_dataAccessorsTrie(a); grib_accessor_bufr_data_array_t* data_accessor = dynamic_cast<grib_accessor_bufr_data_array_t*>(a);
grib_trie_with_rank* t = data_accessor->accessor_bufr_data_array_get_dataAccessorsTrie();
grib_accessor* ret = (grib_accessor*)grib_trie_with_rank_get(t, name, rank); grib_accessor* ret = (grib_accessor*)grib_trie_with_rank_get(t, name, rank);
return ret; return ret;
} }
@ -431,9 +432,10 @@ static grib_accessors_list* search_by_condition(grib_handle* h, const char* name
{ {
grib_accessors_list* al; grib_accessors_list* al;
grib_accessors_list* result = NULL; grib_accessors_list* result = NULL;
grib_accessor* data = search_and_cache(h, "dataAccessors", 0); grib_accessor* a = search_and_cache(h, "dataAccessors", 0);
if (data && condition->left) { grib_accessor_bufr_data_array_t* data_accessor = dynamic_cast<grib_accessor_bufr_data_array_t*>(a);
al = accessor_bufr_data_array_get_dataAccessors(data); if (data_accessor && condition->left) {
al = data_accessor->accessor_bufr_data_array_get_dataAccessors();
if (!al) if (!al)
return NULL; return NULL;
result = (grib_accessors_list*)grib_context_malloc_clear(al->accessor->context_, sizeof(grib_accessors_list)); result = (grib_accessors_list*)grib_context_malloc_clear(al->accessor->context_, sizeof(grib_accessors_list));

View File

@ -398,7 +398,7 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
long length = 0; long length = 0;
int i, err = 0; int i, err = 0;
grib_handle* hclone = NULL; grib_handle* hclone = NULL;
grib_accessor* a = NULL; grib_accessor_bufr_data_array_t* data = NULL;
grib_accessors_list* al = NULL; grib_accessors_list* al = NULL;
if (grib_get_long(h, "totalLength", &length) != GRIB_SUCCESS) if (grib_get_long(h, "totalLength", &length) != GRIB_SUCCESS)
length = -9999; length = -9999;
@ -475,8 +475,8 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h)
/*return err; See ECC-723*/ /*return err; See ECC-723*/
} }
} }
a = grib_find_accessor(h, "numericValues"); data = dynamic_cast<grib_accessor_bufr_data_array_t*>(grib_find_accessor(h, "numericValues"));
al = accessor_bufr_data_array_get_dataAccessors(a); al = data->accessor_bufr_data_array_get_dataAccessors();
options->dump_flags = GRIB_DUMP_FLAG_ALL_ATTRIBUTES; options->dump_flags = GRIB_DUMP_FLAG_ALL_ATTRIBUTES;
codes_dump_bufr_flat(al, h, stdout, options->dump_mode, options->dump_flags, 0); codes_dump_bufr_flat(al, h, stdout, options->dump_mode, options->dump_flags, 0);
break; break;