38 type_filter(type_filter_),
39 field_filter(field_filter_),
60 if (shall_display_type(key_type)) {
66 fprintf(stderr,
"WARNING: can't read key name (Reason: %s)",
GB_await_error());
67 name =
"<unnamedKey?>";
71 const char *display =
NULp;
77 static long not_hidden = 0;
78 hiddenPtr = ¬_hidden;
110 return new Itemfield_Selection(from_sellist, gb_key_data, type_filter, field_filter, *selector);
122 {
GB_INT,
"Rounded numerical",
"i",
"INT" },
123 {
GB_FLOAT,
"Floating-point n.",
"F",
"FLOAT" },
124 {
GB_STRING,
"Ascii text",
"s",
"STRING" }
143 def(
"dummy",
NULp, NULL_selector, 0),
161 void popdown() {
if (aw_popup) aw_popup->hide(); }
177 if (elem_type) definedType =
GB_TYPES(*elem_type);
192 if (allowed & typeFlag) {
193 if (allowed == typeFlag)
return creatable[i].type;
206 FieldSelectionRegistry::iterator found = registry.
find(awar_name);
207 return found == registry.end() ?
NULp : &found->second;
252 const char *value =
NULp;
255 error =
GBS_global_string(
"Awar '%s' is not registered as field selection", awar_name);
281 error =
GBS_global_string(
"Please select the datatype for the new %s '%s'", kindOfField, field);
289 error =
GBS_global_string(
"Selected %s '%s' is not defined (logical error)", kindOfField, field);
298 error =
GBS_global_string(
"Selected field '%s' has unwanted type (%i)\nPlease select the %s again.", field,
int(type), kindOfField);
301 if (!error) value = field;
314 (awar_name == other.awar_name) &&
315 (&selector == &other.selector) &&
316 (gb_main == other.gb_main) &&
317 (type_filter == other.type_filter) &&
318 (field_filter == other.field_filter);
388 if (selected != defined) {
391 aw_message(
"You cannot change the type of an existing field");
416 for (FieldSelectionRegistry::const_iterator reg = registry.begin(); reg != registry.end(); ++reg) {
441 found =
find(field_awarname);
458 aw_popup =
new AW_window_simple;
463 const char *
format = allowNewFields ?
"Select or create a new %s" :
"Select the %s";
465 aw_popup->init(awr,
"SELECT_FIELD", title);
467 if (allowNewFields) aw_popup->load_xfig(
"awt/field_sel_new.fig");
468 else aw_popup->load_xfig(
"awt/field_sel.fig");
478 aw_popup->at(
"close");
480 aw_popup->create_button(
"CLOSE",
"CLOSE",
"C");
483 if (allowNewFields) {
484 aw_popup->at(
"help");
486 aw_popup->create_button(
"HELP",
"HELP",
"H");
489 int possibleTypes = 0;
494 if (firstType == -1) firstType =
creatable[i].type;
499 aw_popup->at(
"name");
503 aw_popup->at(
"type");
511 aw_popup->insert_toggle(
"<undefined>",
"",
GB_NONE);
513 aw_popup->update_toggle_field();
527 aw_popup->activate();
594 void TEST_lossless_conversion() {
601 const long tested_filter[] = {
607 for (
unsigned f = 0; f<
ARRAY_ELEMS(tested_filter); ++f) {
608 const long filter = tested_filter[f];
617 if (filter & (1<<
type)) {
620 const int I_min(-2147483648);
621 const int I_max(2147483647);
623 int tested_int_value[] = { I_min, -1, 0, 1, I_max-1, I_max };
624 for (
unsigned i = 0; i<
ARRAY_ELEMS(tested_int_value); ++i) {
625 int written = tested_int_value[i];
639 uint8_t tested_byte_value[] = { 0, 1, 127, 128, 255 };
640 for (
unsigned i = 0; i<
ARRAY_ELEMS(tested_byte_value); ++i) {
641 uint8_t written = tested_byte_value[i];
655 float tested_double_value[] = {
679 .0000000000123456789,
680 .00000000000000000000123456789,
681 .000000000000000000000000000000123456789,
682 .0000000000000000000000000000000000000000123456789,
683 .00000000000000000000000000000000000000000000000000123456789,
684 .000000000000000000000000000000000000000000000000000000000000123456789,
691 for (
unsigned i = 0; i<
ARRAY_ELEMS(tested_double_value); ++i) {
692 float written = tested_double_value[i];
697 double EPSILON = written*0.000001;
699 EPSILON = 0.000000001;
GB_ERROR GBT_add_new_changekey_to_keypath(GBDATA *gb_main, const char *name, GB_TYPES type, const char *keypath)
void insert_default(const char *displayed, const char *value)
const std::string & get_described_field() const
GB_TYPES get_keytype(const char *fieldName) const
Itemfield_Selection * build_sel(AW_selection_list *from_sellist) const
#define PSEUDO_FIELD_ALL_FIELDS_REC
GBDATA * GB_open(const char *path, const char *opent)
GB_TYPES get_unmated_type()
static void fieldtype_changed_cb(AW_root *awr, RegFieldSelection *fsel)
void button_length(int length)
CONSTEXPR long FIELD_FILTER_FLOAT_WRITEABLE
AliDataPtr format(AliDataPtr data, const size_t wanted_len, GB_ERROR &error)
#define TEST_EXPECT_SIMILAR(expr, want, epsilon)
long GB_read_int(GBDATA *gbd)
return string(buffer, length)
static RegFieldSelection & registrate(AW_root *awr, const FieldSelDef &def)
bool new_fields_allowed() const
void popup_window(AW_root *awr)
#define PSEUDO_FIELD_ALL_FIELDS
GBDATA * get_gb_main() const
GBDATA * GB_nextEntry(GBDATA *entry)
const char * GBS_global_string(const char *templat,...)
char * GBS_string_eval(const char *insource, const char *icommand)
void AW_POPDOWN(AW_window *window)
RegFieldSelection(const FieldSelDef &def_)
const std::string & get_awarname() const
const int FIELDNAME_VISIBLE_CHARS
ItemSelector & get_itemtype() const
void init_awars(AW_root *awr)
#define ARRAY_ELEMS(array)
#define NO_FIELD_SELECTED
static Shaders registered
void insert(const char *displayed, const char *value)
AW_awar * add_callback(const RootCallback &cb)
void create_itemfield_selection_button(AW_window *aws, const FieldSelDef &selDef, const char *at)
static void popup_field_selection(AW_window *aw_parent, RegFieldSelection *fsel)
static bool fieldtype_change_warning
GB_ERROR GB_check_hkey(const char *key) __ATTR__USERESULT
void update_button_text(AW_root *awr) const
const char * read_char_pntr() const
GB_ERROR GB_export_error(const char *error)
GB_ERROR GB_write_lossless_byte(GBDATA *gbd, uint8_t byte)
GB_ERROR GB_await_error()
static AW_root * SINGLETON
NOT4PERL long * GBT_read_int(GBDATA *gb_container, const char *fieldpath)
WindowCallback makeHelpCallback(const char *helpfile)
void awt_auto_popdown_cb(AW_root *, AW_window_simple *aw_popup)
void GB_warningf(const char *templat,...)
GBDATA * GB_create(GBDATA *father, const char *key, GB_TYPES type)
#define PSEUDO_FIELD_ANY_FIELD
NOT4PERL int32_t GB_read_lossless_int(GBDATA *gbd, GB_ERROR &error)
const char * change_key_path
const char * get_type_awarname() const
Itemfield_Selection(AW_selection_list *sellist_, GBDATA *gb_key_data, long type_filter_, SelectableFields field_filter_, ItemSelector &selector_)
NOT4PERL float GB_read_lossless_float(GBDATA *gbd, GB_ERROR &error)
bool new_fields_allowed() const
NOT4PERL uint8_t GB_read_lossless_byte(GBDATA *gbd, GB_ERROR &error)
#define TEST_REJECT_NULL(n)
static void update_buttons()
static void error(const char *msg)
GB_ERROR GB_write_lossless_int(GBDATA *gbd, int32_t i)
const char * get_field_awarname() const
const char * prepare_and_get_selected_itemfield(AW_root *awr, const char *awar_name, GBDATA *gb_main, const ItemSelector &itemtype, FailIfField failIf)
AW_awar * awar(const char *awar)
int get_button_length() const
const char * get_button_awarname() const
const FieldSelDef & get_def() const
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
bool matches4reuse(const FieldSelDef &other) const
GBDATA * GBT_get_changekey(GBDATA *gb_main, const char *key, const char *change_key_path)
Itemfield_Selection * create_itemfield_selection_list(AW_window *aws, const FieldSelDef &selDef, const char *at)
AW_selection_list * create_selection_list(const char *awar_name, int columns, int rows)
const int NEWFIELD_EXTRA_SPACE
#define TEST_EXPECT_NO_ERROR(call)
void aw_message(const char *msg)
map< string, RegFieldSelection > FieldSelectionRegistry
#define TEST_EXPECT_ERROR_CONTAINS(call, part)
GB_ERROR GB_write_lossless_float(GBDATA *gbd, float f)
GB_ERROR write_string(const char *aw_string)
void insert_plain(const char *displayed_value)
GB_ERROR GB_ensure_callback(GBDATA *gbd, GB_CB_TYPE type, const DatabaseCallback &dbcb)
long get_type_filter() const
CONSTEXPR long FIELD_FILTER_INT_WRITEABLE
GB_transaction ta(gb_var)
GB_ERROR GBT_write_int(GBDATA *gb_container, const char *fieldpath, long content)
void callback(const WindowCallback &cb)
static struct @42 creatable[]
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
GB_TYPES get_selected_type(AW_root *awr)
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
GBDATA * GB_search(GBDATA *gbd, const char *fieldpath, GB_TYPES create)
void create_window(AW_root *awr)
char GB_type_2_char(GB_TYPES type)
#define TEST_EXPECT_EQUAL(expr, want)
CONSTEXPR long FIELD_FILTER_BYTE_WRITEABLE
GB_ERROR write_int(long aw_int)
GBDATA * GB_entry(GBDATA *father, const char *key)
AW_selection_list * get_sellist()
#define PSEUDO_FIELD_ANY_FIELD_REC
void aw_message_if(GB_ERROR error)
void GB_close(GBDATA *gbd)
static RegFieldSelection * find(const string &awar_name)
void create_button(const char *macro_name, AW_label label, const char *mnemonic=NULp, const char *color=NULp)
static void fieldname_changed_cb(AW_root *awr, RegFieldSelection *fsel)
const char * get_itemfield_type_awarname(const char *itemfield_awarname)