navit  0.5.6
About: NavIt is a car navigation system with GPS tracking and a routing engine.
  Fossies Dox: navit-0.5.6.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

attr.c File Reference

Attribute handling code. More...

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <glib.h>
#include "debug.h"
#include "item.h"
#include "coord.h"
#include "transform.h"
#include "color.h"
#include "navigation.h"
Include dependency graph for attr.c:

Go to the source code of this file.

Data Structures

struct  attr_name
 

Functions

void attr_create_hash (void)
 
void attr_destroy_hash (void)
 
enum attr_type attr_from_name (const char *name)
 Converts a string to an attr_type. More...
 
static int attr_match (enum attr_type search, enum attr_type found)
 
char * attr_to_name (enum attr_type attr)
 Converts an attr_type to a string. More...
 
struct attrattr_new_from_text (const char *name, const char *value)
 Creates an attribute from text information. More...
 
static char * flags_to_text (int flags)
 Converts access flags to a human-readable string. More...
 
char * attr_to_text_ext (struct attr *attr, char *sep, enum attr_format fmt, enum attr_format def_fmt, struct map *map)
 Converts attribute data to human-readable text. More...
 
char * attr_to_text (struct attr *attr, struct map *map, int pretty)
 Converts an attribute to a string that can be displayed. More...
 
struct attrattr_search (struct attr **attrs, enum attr_type attr)
 Searches for an attribute of a given type. More...
 
int attr_generic_get_attr (struct attr **attrs, struct attr **def_attrs, enum attr_type type, struct attr *attr, struct attr_iter *iter)
 Generic get function. More...
 
struct attr ** attr_generic_set_attr (struct attr **attrs, struct attr *attr)
 Generic set function. More...
 
struct attr ** attr_generic_add_attr (struct attr **attrs, struct attr *attr)
 Generic add function. More...
 
struct attr ** attr_generic_add_attr_list (struct attr **attrs, struct attr **add)
 
struct attr ** attr_generic_prepend_attr (struct attr **attrs, struct attr *attr)
 
struct attr ** attr_generic_remove_attr (struct attr **attrs, struct attr *attr)
 Removes an attribute from an attribute list. More...
 
enum attr_type attr_type_begin (enum attr_type type)
 
int attr_data_size (struct attr *attr)
 
void * attr_data_get (struct attr *attr)
 
void attr_data_set (struct attr *attr, void *data)
 
void attr_data_set_le (struct attr *attr, void *data)
 
static void attr_free_content_do (struct attr *attr)
 
void attr_free_content (struct attr *attr)
 
void attr_free (struct attr *attr)
 
void attr_free_g (struct attr *attr, void *unused)
 
void attr_dup_content (struct attr *src, struct attr *dst)
 
struct attrattr_dup (struct attr *attr)
 
void attr_list_free (struct attr **attrs)
 Frees a list of attributes. More...
 
struct attr ** attr_list_dup (struct attr **attrs)
 Duplicates a list of attributes. More...
 
int attr_from_line (const char *line, const char *name, int *pos, char *val_ret, char *name_ret)
 Retrieves an attribute from a line in textfile format. More...
 
int attr_types_contains (enum attr_type *types, enum attr_type type)
 Checks if an enumeration of attribute types contains a specific attribute. More...
 
int attr_types_contains_default (enum attr_type *types, enum attr_type type, int deflt)
 Check if an enumeration of attribute types contains a specific attribute. More...
 
int attr_rel2real (int attrval, int whole, int treat_neg_as_rel)
 Derive absolute value from relative attribute, given value of the whole range. More...
 

Variables

static struct attr_name attr_names []
 
static GHashTableattr_hash
 

Detailed Description

Attribute handling code.

Structures and functions for working with attributes.

Author
Navit Team
Date
2005-2014

Definition in file attr.c.

Function Documentation

◆ attr_create_hash()

void attr_create_hash ( void  )

◆ attr_data_get()

void* attr_data_get ( struct attr attr)

Definition at line 787 of file attr.c.

References attr::data, attr::num, attr::range, attr::type, and attr::u.

Referenced by attr_bin_write_attr(), and binfile_attr_set().

◆ attr_data_set()

void attr_data_set ( struct attr attr,
void *  data 
)

Definition at line 796 of file attr.c.

References attr::data, data, attr::num, attr::type, and attr::u.

Referenced by item_bin_dump().

◆ attr_data_set_le()

void attr_data_set_le ( struct attr attr,
void *  data 
)

Definition at line 804 of file attr.c.

References attr::data, data, le16_to_cpu, le32_to_cpu, range::max, range::min, attr::num, attr::range, attr::type, and attr::u.

Referenced by binfile_attr_get().

◆ attr_data_size()

◆ attr_destroy_hash()

void attr_destroy_hash ( void  )

Definition at line 79 of file attr.c.

References attr_hash, g_hash_table_destroy(), and NULL.

Referenced by config_load().

◆ attr_dup()

◆ attr_dup_content()

◆ attr_free()

◆ attr_free_content()

void attr_free_content ( struct attr attr)

Definition at line 832 of file attr.c.

References attr_free_content_do().

Referenced by navit_destroy(), and result_free().

◆ attr_free_content_do()

static void attr_free_content_do ( struct attr attr)
static

◆ attr_free_g()

void attr_free_g ( struct attr attr,
void *  unused 
)

Definition at line 842 of file attr.c.

References attr_free().

Referenced by navit_destroy().

◆ attr_from_line()

int attr_from_line ( const char *  line,
const char *  name,
int pos,
char *  val_ret,
char *  name_ret 
)

Retrieves an attribute from a line in textfile format.

If name is NULL, this function returns the first attribute found; otherwise it looks for an attribute named name.

If pos is specified, it acts as an offset pointer: Any data in line before *pos will be skipped. When the function returns, the value pointed to by pos will be incremented by the number of characters parsed. This can be used to iteratively retrieve all attributes: declare a local variable, set it to zero, then iteratively call this function with a pointer to the same variable until it returns false.

val_ret must be allocated (and later freed) by the caller, and have sufficient capacity to hold the parsed value including the terminating NULL character. The minimum safe size is strlen(line) - strlen(name) - *pos (assuming zero for NULL pointers).

Parameters
[in]lineThe line to parse, must be non-NULL and pointing to a NUL terminated string
[in]nameThe name of the attribute to retrieve; can be NULL (see description)
[in,out]posAs input, if pointer is non-NULL, this argument contains the character index inside line from which to start the search (see description)
[out]val_retPoints to a buffer which will receive the value as text
[out]name_retPoints to a buffer which will receive the actual name of the attribute found in the line, if NULL this argument won't be used. Note that the buffer provided here should be long enough to contain the attribute name + a terminating NUL character
Returns
true if successful, false in case of failure

Definition at line 945 of file attr.c.

References dbg, lvl_debug, lvl_warning, NULL, startup::pos, and strncpy_unescape().

Referenced by attr_resolve(), map_rect_get_item_shapefile(), map_rect_get_item_textfile(), parse_option(), and traffic_message_restore_segments().

◆ attr_from_name()

enum attr_type attr_from_name ( const char *  name)

Converts a string to an attr_type.

This function reads a string and returns the corresponding attr_type.

Parameters
nameThe attribute name
Returns
The corresponding
attr_type
Definition: attr.h:34
, or
attr_none
if the string specifies a nonexistent or invalid attribute type.

Definition at line 79 of file attr.c.

Referenced by attr_new_from_text(), command_call_function(), NGQProxy::getAttr(), NGQProxyNavit::getAttrList(), navit_cmd_map_item_set_attr(), navit_get_attr_py(), osd_text_prepare(), parse_filter(), NGQProxy::setAttr(), and start_element().

◆ attr_generic_add_attr()

struct attr** attr_generic_add_attr ( struct attr **  attrs,
struct attr attr 
)

Generic add function.

This function will insert a new attribute into the list.

Parameters
attrsPoints to the array of attribute pointers to be updated
attrThe new attribute.
Returns
Pointer to the updated attribute list

Definition at line 632 of file attr.c.

References attr_dup(), attr_to_name(), attr::attrs, dbg, g_free(), g_new0, i, lvl_debug, NULL, and attr::type.

Referenced by announcement_add_attr(), attr_generic_add_attr_list(), cursor_add_attr(), eval_list(), graphics_new(), gui_internal_cmd_escape(), gui_internal_dbus_signal(), gui_internal_get_data(), gui_new(), layout_add_attr(), mapset_add_attr(), navit_add_attr(), navit_cmd_fmt_coordinates(), navit_cmd_strjoin(), navit_object_add_attr(), roadprofile_add_attr(), tm_item_update_attrs(), vehicle_add_attr(), and vehicleprofile_add_attr().

◆ attr_generic_add_attr_list()

struct attr** attr_generic_add_attr_list ( struct attr **  attrs,
struct attr **  add 
)

Definition at line 650 of file attr.c.

References attr_generic_add_attr(), and attr::attrs.

◆ attr_generic_get_attr()

int attr_generic_get_attr ( struct attr **  attrs,
struct attr **  def_attrs,
enum attr_type  type,
struct attr attr,
struct attr_iter iter 
)

Generic get function.

This function searches an attribute list for an attribute of a given type and stores it in the attr parameter. If no match is found in attrs and the def_attrs argument is supplied, def_attrs is searched for the attribute type and the first match (if any) is returned.

Searching for attr_any or attr_any_xml is supported, but def_attrs will not be searched in that case.

An iterator can be specified to get multiple attributes of the same type: The first call will return the first match from attr; each subsequent call with the same iterator will return the next match. After obtaining the last match from attr, def_attrs is searched in the same manner. If no more matching attributes are found in either of them, false is returned.

Parameters
attrsPoints to the array of attribute pointers to be searched
def_attrsPoints to a list of pointers to default attributes. If an attribute is not found in attrs, the function will return the first match from def_attrs. This parameter may be NULL.
typeThe attribute type to search for
attrPoints to a
struct attr
Definition: attr.h:157
which will receive the attribute
iterAn iterator. This parameter may be NULL.
Returns
True if a matching attribute was found, false if not.

Definition at line 560 of file attr.c.

References attr_match(), attr::attrs, and geojson-to-bbox::type.

Referenced by announcement_get_attr(), config_get_attr(), get_string_from_attr_list(), graphics_get_attr(), gui_get_attr(), log_get_attr(), map_get_attr(), messagelist_new(), navit_get_attr(), navit_object_get_attr(), roadprofile_get_attr(), route_new(), speech_get_attr(), tm_find_item(), tracking_new(), vehicle_get_attr(), and vehicleprofile_get_attr().

◆ attr_generic_prepend_attr()

struct attr** attr_generic_prepend_attr ( struct attr **  attrs,
struct attr attr 
)

Definition at line 659 of file attr.c.

References attr_dup(), attr::attrs, g_free(), g_new0, i, and NULL.

Referenced by navit_object_add_attr(), osd_new(), and search_list_common_addattr().

◆ attr_generic_remove_attr()

struct attr** attr_generic_remove_attr ( struct attr **  attrs,
struct attr attr 
)

Removes an attribute from an attribute list.

If attrs contains attr, a new attribute list is created (which contains all attributes, except for attr) and both attrs (the original attribute list) and attr are freed.

If attrs does not contain attr, this function is a no-op.

Attributes are matched based on their type and u.data members, thus attr can be a shallow copy of the attribute, and can match multiple attributes in the list. The attr argument itself is not changed.

Parameters
attrsThe attribute list
attrThe attribute to remove from the list
Returns
The new attribute list

Definition at line 693 of file attr.c.

References attr_free(), attr::attrs, attr::data, g_free(), g_new0, i, NULL, geojson-to-bbox::type, attr::type, and attr::u.

Referenced by announcement_remove_attr(), mapset_remove_attr(), navit_object_remove_attr(), navit_remove_attr(), roadprofile_remove_attr(), tm_item_update_attrs(), vehicle_remove_attr(), and vehicleprofile_remove_attr().

◆ attr_generic_set_attr()

struct attr** attr_generic_set_attr ( struct attr **  attrs,
struct attr attr 
)

Generic set function.

This function will search the list for the first attribute of the same type as the supplied new one and replace it with that. If the list does not contain an attribute whose type matches that of the new one, the new attribute is inserted into the list.

Parameters
attrsPoints to the array of attribute pointers to be updated (if NULL, this function will create a new list containing only the new attribute)
attrThe new attribute.
Returns
Pointer to the updated attribute list

Definition at line 600 of file attr.c.

References attr_dup(), attr_free(), attr_to_name(), attr::attrs, dbg, g_free(), g_new0, i, lvl_debug, NULL, and attr::type.

Referenced by announcement_set_attr(), gui_set_attr(), map_set_attr(), navit_object_set_attr(), roadprofile_set_attr(), tm_add_item(), vehicle_set_attr(), vehicle_set_default_name(), and vehicleprofile_set_attr().

◆ attr_list_dup()

struct attr** attr_list_dup ( struct attr **  attrs)

Duplicates a list of attributes.

This creates a deep copy, i.e. the attributes in the list are copied as well.

It is safe to call this function with a NULL argument; in this case, NULL will be returned.

Parameters
attrsThe attribute list to copy
Returns
The copy of the attribute list

Definition at line 907 of file attr.c.

References attr_dup(), attr::attrs, g_new0, i, and NULL.

Referenced by announcement_new(), graphics_new(), gui_new(), log_new(), map_new(), mapset_new(), navit_new(), navit_object_new(), osd_new(), profile_option_new(), roadprofile_dup(), roadprofile_new(), script_new(), tm_add_item(), traffic_message_restore_segments(), vehicle_new(), and vehicleprofile_new().

◆ attr_list_free()

void attr_list_free ( struct attr **  attrs)

Frees a list of attributes.

This frees the pointer array as well as the attributes referenced by the pointers.

It is safe to call this function with a NULL argument; doing so is a no-op.

Parameters
attrsThe attribute list to free

Definition at line 887 of file attr.c.

References attr_free(), attr::attrs, and g_free().

Referenced by command_call_function(), config_destroy(), eval_list(), graphics_free(), gui_internal_dbus_signal(), layer_destroy(), log_destroy(), map_destroy(), mapset_destroy(), navit_destroy(), navit_object_destroy(), osd_destroy(), osd_new(), parsed_item_destroy(), profile_option_destroy(), roadprofile_destroy(), script_destroy(), search_list_common_destroy(), tm_add_item(), tm_item_destroy(), traffic_destroy(), and vehicle_destroy().

◆ attr_match()

static int attr_match ( enum attr_type  search,
enum attr_type  found 
)
static

Definition at line 518 of file attr.c.

Referenced by attr_generic_get_attr().

◆ attr_new_from_text()

struct attr* attr_new_from_text ( const char *  name,
const char *  value 
)

◆ attr_rel2real()

int attr_rel2real ( int  attrval,
int  whole,
int  treat_neg_as_rel 
)

Derive absolute value from relative attribute, given value of the whole range.

Parameters
attrvalValue of u.num member of attribute capable of holding relative values.
wholeRange counted as 100%.
treat_neg_as_relReplace negative absolute values with whole+attr.u.num.
Returns
Absolute value corresponding to given relative value.

Definition at line 1057 of file attr.c.

Referenced by osd_std_calculate_sizes().

◆ attr_search()

struct attr* attr_search ( struct attr **  attrs,
enum attr_type  attr 
)

Searches for an attribute of a given type.

This function searches an array of pointers to attributes for a given attribute type and returns the first match.

Parameters
attrsPoints to the array of attribute pointers to be searched
attr_typeThe attribute type to search for. Generic types (such as attr_any or attr_any_xml) are NOT supported.
Returns
Pointer to the first matching attribute, or NULL if no match was found.

Definition at line 506 of file attr.c.

References attr::attrs, dbg, lvl_debug, lvl_info, and NULL.

Referenced by announcement_new(), coord_new_from_attrs(), cursor_new(), debug_new(), element_set_arrows_width(), element_set_background_color(), element_set_circle_radius(), element_set_circle_width(), element_set_color(), element_set_oneway(), element_set_polyline_dash(), element_set_polyline_directed(), element_set_polyline_offset(), element_set_polyline_width(), element_set_text_size(), espeak_new(), file_create(), gmap_new(), graphics_android_new(), graphics_gtk_drawing_area_new(), graphics_new(), graphics_null_new(), graphics_opengl_new(), graphics_qt5_new(), graphics_qt_qpainter_new(), graphics_sdl_new(), graphics_svg_debug_new(), graphics_win32_new(), gui_gtk_new(), gui_internal_add_vehicle_profile(), gui_internal_command_init(), gui_internal_new(), gui_new(), gui_qml_new(), gui_qt5_qml_new(), icon_new(), itemgra_new(), layout_new(), log_new(), map_filter_new(), map_new(), map_new_binfile(), map_new_csv(), map_new_garmin_img(), map_new_mg(), map_new_shapefile(), map_new_textfile(), map_route_occluded_new(), navigation_map_new(), navigation_new(), osd_button_new(), osd_cmd_interface_new(), osd_compass_new(), osd_gps_status_new(), osd_image_new(), osd_j1850_new(), osd_nav_next_turn_new(), osd_nav_toggle_announcer_new(), osd_navigation_status_new(), osd_new(), osd_odometer_new(), osd_route_guard_new(), osd_set_std_attr(), osd_speed_cam_new(), osd_speed_warner_new(), osd_stopwatch_new(), osd_text_new(), osd_volume_new(), plugin_new(), polygon_new(), qt5_espeak_init_espeak(), qt5_espeak_init_language(), route_map_new_helper(), script_run(), seg_data_equals(), speech_android_new(), speech_new(), speechd_new(), tm_item_update_attrs(), tracking_map_new(), traffic_map_new(), traffic_new(), vehicle_file_new_file(), vehicle_gpsd_new_gpsd(), vehicle_gypsy_new_gypsy(), vehicle_iphone_new(), vehicle_log_gpx(), vehicle_maemo_new_maemo(), vehicle_new(), vehicle_qt5_position_attr_get(), vehicle_set_default_name(), vehicle_wince_new(), and vehicleprofile_new().

◆ attr_to_name()

char* attr_to_name ( enum attr_type  attr)

Converts an attr_type to a string.

Parameters
attrThe attribute type to be converted.
Returns
The attribute name, or NULL if an invalid value was passed as . The calling function should create a copy of the string if it needs to alter it or relies on the string being available permanently.

Definition at line 117 of file attr.c.

References attr_names, i, attr_name::name, and NULL.

Referenced by android_search_idle(), attr_data_size(), attr_generic_add_attr(), attr_generic_set_attr(), attr_resolve(), attr_to_text_ext(), binfile_attr_get(), command_attr_type(), command_call_function(), command_get_attr(), command_object_get_attr(), encode_attr(), get_int_bool(), NGQPoint::getInformation(), getProperty(), gui_internal_append_attr(), gui_internal_cmd_debug(), gui_internal_cmd_view_attributes(), gui_internal_set_attr(), housenumber_attr_get(), invoke(), item_bin_dump(), item_dump_attr(), itemgra_add_attr(), map_search_new_mg(), map_search_setup(), navigation_get_attr(), navit_get_attr(), navit_object_add_attr(), navit_object_ref(), navit_object_set_attr(), navit_object_unref(), navit_set_attr_do(), osd_text_draw(), pedestrian_navit_init(), popup_show_attr_val(), route_set_attr(), rp_attr_get(), save_map_csv(), save_vehicle_xml(), search_attr_get(), search_by_address_attr(), search_list_level(), search_list_search(), street_name_attr_get(), tm_item_dump_to_file(), town_attr_get(), tracking_get_attr(), traffic_new(), vehicle_null_position_attr_get(), vehicle_qt5_position_attr_get(), vehicleprofile_apply_attrs(), and vehicleprofile_set_attr_do().

◆ attr_to_text()

char* attr_to_text ( struct attr attr,
struct map map,
int  pretty 
)

Converts an attribute to a string that can be displayed.

This function is just a wrapper around

char * attr_to_text_ext(struct attr *attr, char *sep, enum attr_format fmt, enum attr_format def_fmt, struct map *map)
Converts attribute data to human-readable text.
Definition: attr.c:363

.

Parameters
attrThe attribute to convert
mapThe translation map, see
prettyNot used

Definition at line 490 of file attr.c.

References attr_format_default, attr_to_text_ext(), and NULL.

Referenced by encode_attr(), get_string(), NGQPoint::getInformation(), gui_internal_cmd_debug(), gui_internal_cmd_match_expand(), gui_internal_cmd_view_attributes(), item_bin_dump(), item_dump_attr(), navit_cmd_strjoin(), osd_text_format_attr(), popup_show_attr_val(), route_get_destination_description(), save_vehicle_xml(), and tm_item_dump_to_file().

◆ attr_to_text_ext()

char* attr_to_text_ext ( struct attr attr,
char *  sep,
enum attr_format  fmt,
enum attr_format  def_fmt,
struct map map 
)

Converts attribute data to human-readable text.

Parameters
attrThe attribute to be formatted
sepThe separator to insert between a numeric value and its unit. If NULL, nothing will be inserted.
fmtSet to
@ attr_format_with_units
Definition: attr.h:56
if is of type
attr_destination_length
or
attr_destination_time
or a group type which might contain attributes of those types. Ignored for all other attribute types.
def_fmtNot used
mapThe translation map. This is only needed for string type attributes or group type attributes which might contain strings. It can be NULL for other attribute types. If a string type attribute is encountered and
Definition: map.c:55
is NULL, the string will be returned unchanged.
Returns
The attribute data in human-readable form. The caller is responsible for calling
void g_free(gpointer mem)
Definition: gmem.c:191
on the result when it is no longer needed.

Definition at line 363 of file attr.c.

References color::a, attr_format_with_units, attr_to_name(), attr::attrs, color::b, attr::color, poly_hole::coord_count, attr::coord_geo, attr::data, data, flags_to_text(), color::g, g_free(), g_strconcat_printf(), g_strdup(), g_strdup_printf(), i, item::id_hi, item::id_lo, attr::item, item_to_name(), attr::item_types, coord_geo::lat, coord_geo::lng, LONGLONG_FMT, item::map, map_convert_free(), map_convert_string(), map_get_attr(), nav_status_to_text(), NULL, attr::num, attr::num64, attr::numd, attr::poly_hole, color::r, attr::str, geojson-to-bbox::type, attr::type, item::type, and attr::u.

Referenced by attr_to_text(), and gui_internal_populate_route_table().

◆ attr_type_begin()

enum attr_type attr_type_begin ( enum attr_type  type)

Definition at line 693 of file attr.c.

◆ attr_types_contains()

int attr_types_contains ( enum attr_type types,
enum attr_type  type 
)

Checks if an enumeration of attribute types contains a specific attribute.

Parameters
typesPoints to a NULL-terminated array of pointers to
enum attr_type
, which will be searched
typeThe attr_type to be searched for
Returns
True if the attribute type was found, false if it was not found or if
unsigned char types
Definition: garmin_img.c:1
is empty

Definition at line 1020 of file attr.c.

References geojson-to-bbox::type, and types.

Referenced by attr_types_contains_default().

◆ attr_types_contains_default()

int attr_types_contains_default ( enum attr_type types,
enum attr_type  type,
int  deflt 
)

Check if an enumeration of attribute types contains a specific attribute.

This function is mostly identical to

int attr_types_contains(enum attr_type *types, enum attr_type type)
Checks if an enumeration of attribute types contains a specific attribute.
Definition: attr.c:1020

but returns the supplied default value if

is empty.

Parameters
typesPoints to a NULL-terminated array of pointers to
enum attr_type
, which will be searched
typeThe attr_type to be searched for
defltThe default value to return if is empty.
Returns
True if the attribute type was found, false if it was not found,
deflt
if types is empty.

Definition at line 1041 of file attr.c.

References attr_types_contains(), geojson-to-bbox::type, and types.

Referenced by vehicle_log_gpx().

◆ flags_to_text()

Variable Documentation

◆ attr_hash

GHashTable* attr_hash
static

Definition at line 69 of file attr.c.

Referenced by attr_create_hash(), and attr_destroy_hash().

◆ attr_names

struct attr_name attr_names[]
static
Initial value:
= {
#define ATTR2(x,y) ATTR(y)
#define ATTR(x) { attr_##x, #x },
#define ATTR_UNUSED
#include "attr_def.h"
#undef ATTR_UNUSED
#undef ATTR2
#undef ATTR
}
Attribute definitions.

List of attr_types with their names as strings.

Definition at line 1 of file attr.c.

Referenced by attr_create_hash(), and attr_to_name().