struct maps * maps_new(struct attr *parent, struct attr **attrs) { struct attr *data,**attrs_dup; if (!parent) { dbg(lvl_error,"No parent\n"); return NULL; } if (parent->type != attr_mapset) { dbg(lvl_error,"Parent must be mapset\n"); return NULL; } dbg(lvl_debug,"enter\n"); attrs_dup=attr_list_dup(attrs); data=attr_search(attrs_dup, NULL, attr_data); if (data) { struct file_wordexp *wexp=file_wordexp_new(data->u.str); int i,count=file_wordexp_get_count(wexp); char **array=file_wordexp_get_array(wexp); struct attr *name; struct attr *name_provided = attr_search(attrs_dup, NULL, attr_name); // if no name was provided, fill the name with the location if (!name_provided) { struct attr name_tmp; name_tmp.type = attr_name; name_tmp.u.str="NULL"; attrs_dup=attr_generic_add_attr(attrs_dup, &name_tmp); name = attr_search(attrs_dup, NULL, attr_name); } for (i = 0 ; i < count ; i++) { struct attr map; g_free(data->u.str); data->u.str=g_strdup(array[i]); if (!name_provided) { g_free(name->u.str); name->u.str=g_strdup(array[i]); } map.type=attr_map; map.u.map=map_new(parent, attrs_dup); if (map.u.map) { mapset_add_attr(parent->u.mapset, &map); navit_object_unref(map.u.navit_object); } } file_wordexp_destroy(wexp); } else { dbg(lvl_error,"no data attribute\n"); } attr_list_free(attrs_dup); return NULL; }
static struct profile_option * profile_option_new(struct attr *parent, struct attr **attrs) { struct profile_option *po=g_new0(struct profile_option, 1); po->func=&profile_option_func; navit_object_ref((struct navit_object *)po); po->attrs=attr_list_dup(attrs); dbg(lvl_debug,"return %p\n",po); return po; }
struct log * log_new(struct attr * parent,struct attr **attrs) { struct log *ret=g_new0(struct log, 1); struct attr *data,*overwrite,*lazy,*mkdir,*flush_size,*flush_time; struct file_wordexp *wexp; char *filename, **wexp_data; dbg(1,"enter\n"); ret->func=&log_func; navit_object_ref((struct navit_object *)ret); data=attr_search(attrs, NULL, attr_data); if (! data) return NULL; filename=data->u.str; wexp=file_wordexp_new(filename); if (wexp && file_wordexp_get_count(wexp) > 0) { wexp_data=file_wordexp_get_array(wexp); filename=wexp_data[0]; } if (filename) ret->filename=g_strdup(filename); if (wexp) file_wordexp_destroy(wexp); overwrite=attr_search(attrs, NULL, attr_overwrite); if (overwrite) ret->overwrite=overwrite->u.num; lazy=attr_search(attrs, NULL, attr_lazy); if (lazy) ret->lazy=lazy->u.num; mkdir=attr_search(attrs, NULL, attr_mkdir); if (mkdir) ret->mkdir=mkdir->u.num; flush_size=attr_search(attrs, NULL, attr_flush_size); if (flush_size) ret->flush_size=flush_size->u.num; flush_time=attr_search(attrs, NULL, attr_flush_time); if (flush_time) ret->flush_time=flush_time->u.num; if (ret->flush_time) { dbg(1,"interval %d\n", ret->flush_time*1000); ret->timer_callback=callback_new_1(callback_cast(log_timer), ret); ret->timer=event_add_timeout(ret->flush_time*1000, 1, ret->timer_callback); } expand_filenames(ret); if (ret->lazy) log_set_last_flush(ret); else log_open(ret); ret->attrs=attr_list_dup(attrs); return ret; }
struct vehicleprofile * vehicleprofile_new(struct attr *parent, struct attr **attrs) { struct vehicleprofile *this_; struct attr **attr, *type_attr; if (! (type_attr=attr_search(attrs, NULL, attr_name))) { return NULL; } this_=g_new0(struct vehicleprofile, 1); this_->attrs=attr_list_dup(attrs); this_->roadprofile_hash=g_hash_table_new(NULL, NULL); for (attr=attrs;*attr; attr++) vehicleprofile_set_attr_do(this_, *attr); return this_; }
static struct script * script_new(struct attr *parent, struct attr **attrs) { struct script *scr=g_new0(struct script, 1); scr->func=&script_func; navit_object_ref((struct navit_object *)scr); scr->attrs=attr_list_dup(attrs); attrs=scr->attrs; scr->cb=callback_new_1(callback_cast(script_run), scr); scr->parent=*parent; while (attrs && *attrs) script_set_attr_int(scr, *attrs++); dbg(lvl_debug,"return %p\n",scr); return scr; }
/** * Creates a new graphics object * attr type required * @param <> * @returns <> * @author Martin Schaller (04/2008) */ struct graphics * graphics_new(struct attr *parent, struct attr **attrs) { struct graphics *this_; struct attr *type_attr; struct graphics_priv * (*graphicstype_new)(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl); if (! (type_attr=attr_search(attrs, NULL, attr_type))) { return NULL; } graphicstype_new=plugin_get_graphics_type(type_attr->u.str); if (! graphicstype_new) return NULL; this_=g_new0(struct graphics, 1); this_->cbl=callback_list_new(); this_->priv=(*graphicstype_new)(parent->u.navit, &this_->meth, attrs, this_->cbl); this_->attrs=attr_list_dup(attrs); return this_; }
struct vehicleprofile * vehicleprofile_new(struct attr *parent, struct attr **attrs) { struct vehicleprofile *this_; struct attr **attr, *type_attr; if (! (type_attr=attr_search(attrs, NULL, attr_name))) { return NULL; } this_=g_new0(struct vehicleprofile, 1); this_->attrs=attr_list_dup(attrs); this_->roadprofile_hash=g_hash_table_new(NULL, NULL); this_->length=-1; this_->width=-1; this_->height=-1; this_->weight=-1; this_->axle_weight=-1; this_->through_traffic_penalty=9000; for (attr=attrs; *attr; attr++) vehicleprofile_set_attr_do(this_, *attr); return this_; }