📄 record.c
字号:
if (map == NULL) { map = record_gen_base_fields(record, ftid); } if (fid < fids_map_get_min_fid(map) || fid > fids_map_get_max_fid(map)) { return FALSE; } key = g_new0(guint32, 1); *key = fid; field = field_new(fdesc); g_hash_table_replace(record->fields, key, (gpointer)field); } field_set_label(field, label); record->extended = TRUE; return TRUE;}/** * @brief Set label of field in #Record object. * * @param record the #Record object * @param fid the identifier of the field * @param label the label to be set * * @return TRUE if set successfully */gboolean record_set_label (Record *record, guint32 fid, const gchar *label){ Field * field = NULL; g_return_val_if_fail(record, FALSE); field = g_hash_table_lookup(record->fields, &fid); if (field == NULL) { FidsMap * map = NULL; guint32 * key = NULL; guint32 ftid = FIELD_TEMPLATE_ID_INVALID; FieldDescriptor * fdesc = NULL; ftid = FID_GET_FTID(fid); g_return_val_if_fail(ftid != FIELD_TEMPLATE_ID_INVALID, FALSE); fdesc = field_template_get(record->template, ftid); map = (FidsMap *)g_hash_table_lookup(record->fids_map, &ftid); if (map == NULL) { map = record_gen_base_fields(record, ftid); } if (fid < fids_map_get_min_fid(map) || fid > fids_map_get_max_fid(map)) { return FALSE; } key = g_new0(guint32, 1); *key = fid; field = field_new(fdesc); g_hash_table_replace(record->fields, key, (gpointer)field); } field_set_label(field, label); record->extended = TRUE; return TRUE;}/** * @brief Set description of default field of specific * field template in #Record object. * * @param record the #Record object * @param ftid the identifier of specific field template * @param description the description to be set * * @return TRUE if set successfully */gboolean record_set_desc_default (Record *record, guint32 ftid, const gchar *description){ Field * field = NULL; FidsMap * map = NULL; guint32 fid = FIELD_ID_INVALID; g_return_val_if_fail(record, FALSE); g_return_val_if_fail(ftid != FIELD_TEMPLATE_ID_INVALID, FALSE); map = (FidsMap *)g_hash_table_lookup(record->fids_map, &ftid); if (map == NULL) { map = record_gen_base_fields(record, ftid); } fid = fids_map_get_default_fid(map); field = g_hash_table_lookup(record->fields, &fid); if (field == NULL) { FidsMap * map = NULL; guint32 * key = NULL; guint32 ftid = FIELD_TEMPLATE_ID_INVALID; FieldDescriptor * fdesc = NULL; ftid = FID_GET_FTID(fid); g_return_val_if_fail(ftid != FIELD_TEMPLATE_ID_INVALID, FALSE); fdesc = field_template_get(record->template, ftid); map = (FidsMap *)g_hash_table_lookup(record->fids_map, &ftid); if (map == NULL) { map = record_gen_base_fields(record, ftid); } if (fid < fids_map_get_min_fid(map) || fid > fids_map_get_max_fid(map)) { return FALSE; } key = g_new0(guint32, 1); *key = fid; field = field_new(fdesc); g_hash_table_replace(record->fields, key, (gpointer)field); } field_set_desc(field, description); record->extended = TRUE; return TRUE;}/** * @brief Set description of field in #Record object. * * @param record the #Record object * @param fid the identifier of the field * @param description the label to be set * * @return TRUE if set successfully */gbooleanrecord_set_desc (Record *record, guint32 fid, const gchar *description){ Field * field = NULL; g_return_val_if_fail(record, FALSE); field = g_hash_table_lookup(record->fields, &fid); if (field == NULL) { FidsMap * map = NULL; guint32 * key = NULL; guint32 ftid = FIELD_TEMPLATE_ID_INVALID; FieldDescriptor * fdesc = NULL; ftid = FID_GET_FTID(fid); g_return_val_if_fail(ftid != FIELD_TEMPLATE_ID_INVALID, FALSE); fdesc = field_template_get(record->template, ftid); map = (FidsMap *)g_hash_table_lookup(record->fids_map, &ftid); if (map == NULL) { map = record_gen_base_fields(record, ftid); } if (fid < fids_map_get_min_fid(map) || fid > fids_map_get_max_fid(map)) { return FALSE; } key = g_new0(guint32, 1); *key = fid; field = field_new(fdesc); g_hash_table_replace(record->fields, key, (gpointer)field); } field_set_desc(field, description); record->extended = TRUE; return TRUE;}/** * @brief Retrieve value of default field of specific field template * in #Record object. * * A direct pointer to the memory block of value of * the field is returned and users SHOULD NOT modify * or free this pointer. * * @param record the #Record object * @param ftid the identifier of specific field template * @param size the size of returned value * * @return A pointer points to value of the field */gconstpointerrecord_get_field_default (const Record *record, guint32 ftid, FieldSize *size){ Field * field = NULL; FidsMap * map = NULL; guint32 fid = FIELD_ID_INVALID; g_return_val_if_fail(record, NULL); g_return_val_if_fail(ftid != FIELD_TEMPLATE_ID_INVALID, FALSE); map = (FidsMap *)g_hash_table_lookup(record->fids_map, &ftid); if (map == NULL) { return FALSE; } fid = fids_map_get_default_fid(map); field = g_hash_table_lookup(record->fields, &fid); if (field == NULL) { if (size) { *size = 0; } return NULL; } if (size) { *size = field_get_size(field); } return field_get_value(field);}/** * @brief Retrieve value of the field in #Record object. * * A direct pointer to the memory block of value of * the field is returned and users SHOULD NOT modify * or free this pointer. * * @param record the #Record object * @param fid the identifier of the field * @param size the size of returned value * * @return A pointer points to value of the field */gconstpointerrecord_get_field (const Record *record, guint32 fid, FieldSize *size){ Field * field = NULL; g_return_val_if_fail(record, NULL); field = g_hash_table_lookup(record->fields, &fid); if (field == NULL) { if (size) { *size = 0; } return NULL; } if (size) { *size = field_get_size(field); } return field_get_value(field);}/** * @brief Retrieve label of default field of specific field template * in #Record object. * * A direct pointer to the memory block of label of * the field is returned and users SHOULD NOT modify * or free this pointer. * * @param record the #Record object * @param ftid the identifier of specific field template * @param size the size of returned value * * @return A pointer points to label of the field */const gchar *record_get_label_default (Record *record, guint32 ftid){ Field * field = NULL; FidsMap * map = NULL; guint32 fid = FIELD_ID_INVALID; g_return_val_if_fail(record, NULL); g_return_val_if_fail(ftid != FIELD_TEMPLATE_ID_INVALID, FALSE); map = (FidsMap *)g_hash_table_lookup(record->fids_map, &ftid); if (map == NULL) { return FALSE; } fid = fids_map_get_default_fid(map); field = g_hash_table_lookup(record->fields, &fid); if (field == NULL) { return NULL; } return field_get_label(field);}/** * @brief Retrieve label of the field in #Record object. * * A direct pointer to the memory block of label of * the field is returned and users SHOULD NOT modify * or free this pointer. * * @param record the #Record object * @param fid the identifier of the field * @param size the size of returned value * * @return A pointer points to label of the field */const gchar *record_get_label (Record *record, guint32 fid){ Field * field = NULL; g_return_val_if_fail(record, NULL); field = g_hash_table_lookup(record->fields, &fid); if (field == NULL) { return NULL; } return field_get_label(field);}/** * @brief Retrieve description of default field of * specific field template in #Record object. * * A direct pointer to the memory block of description of * the field is returned and users SHOULD NOT modify * or free this pointer. * * @param record the #Record object * @param ftid the identifier of specific field template * @param size the size of returned value * * @return A pointer points to description of the field */const gchar *record_get_desc_default (Record *record, guint32 ftid){ Field * field = NULL; FidsMap * map = NULL; guint32 fid = FIELD_ID_INVALID; g_return_val_if_fail(record, NULL); g_return_val_if_fail(ftid != FIELD_TEMPLATE_ID_INVALID, FALSE); map = (FidsMap *)g_hash_table_lookup(record->fids_map, &ftid); if (map == NULL) { return FALSE; } fid = fids_map_get_default_fid(map); field = g_hash_table_lookup(record->fields, &fid); if (field == NULL) { return NULL; } return field_get_desc(field);}/** * @brief Retrieve description of the field * in #Record object. * * A direct pointer to the memory block of description of * the field is returned and users SHOULD NOT modify * or free this pointer. * * @param record the #Record object * @param fid the identifier of the field * @param size the size of returned value * * @return A pointer points to description of the field */const gchar *record_get_desc (Record *record, guint32 fid){ Field * field = NULL; g_return_val_if_fail(record, NULL); field = g_hash_table_lookup(record->fields, &fid); if (field == NULL) { return NULL; } return field_get_desc(field);}/** * @brief Calls the given function for each field of * #Record object. * * The function is passed the identifier of the field * and #Field object, and the given user_data parameter. * The #Record object SHOLD not be modified while iterating over it * (you can't add/remove any fields). * * @param record the #Record object * @param func the function to call for each fid/field pair * @param user_data user data to pass to the function */voidrecord_foreach_field (const Record *record, RecordFieldFunc func, gpointer user_data){ g_return_if_fail(record); g_hash_table_foreach(record->fields, (GHFunc)func, user_data); return;}/** * @brief Returns whether #Record object is empty. * * @param record the #Record object * * @return TRUE if #Record object is empty. */gbooleanrecord_is_empty (const Record *record){ g_return_val_if_fail(record, FALSE); if (g_hash_table_size(record->fields) > 0) { return FALSE; } return TRUE;}/** * @brief Returns whether #Record object is extended. * * @param record the #Record object * * @return TRUE if #Record object is extended. */gbooleanrecord_is_extended (const Record *record){ return record->extended;}/** * @brief Returns whether the default fid of * specific field template is changed * in #Record object. * * @param record the #Record object * @param ftid the identifier of specific field template * * @return TRUE if default fid is changed. */gboolean
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -