// 生成读取属性的语句 func gen_load_attr_statement(field *generator.Field_t) string { var g_load_attr_stmt = [generator.Fieldtype_max + 1]string{} g_load_attr_stmt[0] = "" g_load_attr_stmt[1] = "cfg.%field% = %cast%(%val%);" g_load_attr_stmt[2] = "cfg.%field% = (%val%[0] != '0');" g_load_attr_stmt[3] = "cfg.%field% = %cast%(%val%);" g_load_attr_stmt[4] = "cfg.%field% = %cast%(%val%);" g_load_attr_stmt[5] = "cfg.%field% = %cast%(%val%);" g_load_attr_stmt[6] = "cfg.%field% = %cast%(%val%);" g_load_attr_stmt[7] = "cfg.%field% = %cast%(%val%);" g_load_attr_stmt[8] = "cfg.%field% = %cast%(%val%);" g_load_attr_stmt[9] = "cfg.%field% = %cast%(%val%);" g_load_attr_stmt[10] = "cfg.%field% = %cast%(%val%);" g_load_attr_stmt[11] = "cfg.%field% = (float)%cast%(%val%);" g_load_attr_stmt[12] = "cfg.%field% = %cast%(%val%);" var g_cast_func_name = [generator.Fieldtype_max + 1]string{} g_cast_func_name[0] = "" g_cast_func_name[1] = "strtool::un_escape_xml" g_cast_func_name[2] = "strtool::str_to_bool" g_cast_func_name[3] = "strtool::str_to_int32" g_cast_func_name[4] = "strtool::str_to_int32" g_cast_func_name[5] = "strtool::str_to_int32" g_cast_func_name[6] = "strtool::str_to_int64" g_cast_func_name[7] = "strtool::str_to_uint32" g_cast_func_name[8] = "strtool::str_to_uint32" g_cast_func_name[9] = "strtool::str_to_uint32" g_cast_func_name[10] = "strtool::str_to_uint64" g_cast_func_name[11] = "atof" g_cast_func_name[12] = "atof" var static_load_vec_stmt string = "cfg.%field% = strtool::split_str_to_vec<%T%>(%val%, %cast%);" var static_load_set_stmt string = "cfg.%field% = strtool::split_str_to_set<%T%>(%val%, %cast%);" var static_load_str_vec_stmt string = "cfg.%field% = strtool::split(%val%);" var static_load_str_set_stmt string = "cfg.%field% = strtool::split_str_set(%val%);" var stmt string = g_load_attr_stmt[field.Fieldtype] if field.Is_array() { if field.Fieldtype == generator.Fieldtype_string { stmt = static_load_str_vec_stmt } else { stmt = static_load_vec_stmt } } else if field.Is_set() { if field.Fieldtype == generator.Fieldtype_string { stmt = static_load_str_set_stmt } else { stmt = static_load_set_stmt } } var val string = "node->first_attribute(\"%field%\")->value()" var cast_func *string = &g_cast_func_name[field.Fieldtype] stmt = strings.Replace(stmt, "%val%", val, -1) stmt = strings.Replace(stmt, "%field%", field.En_name, -1) stmt = strings.Replace(stmt, "%T%", g_cpp_types[field.Fieldtype], -1) stmt = strings.Replace(stmt, "%cast%", *cast_func, -1) return stmt }
func get_field_c_typedef_type(cfg *generator.Cfg_t, field *generator.Field_t, c_type enum_get_c_field_option) string { var ret string if field.Fieldattr != generator.Fieldattr_none { var typedef_type string switch { case field.Is_array(): typedef_type = field.En_name + "vec_t" case field.Is_set(): typedef_type = field.En_name + "set_t" default: typedef_type = field.En_name + "_t" } // 检测是否需要指定作用域 if gcfo_without_namespace == c_type { ret = typedef_type } else { ret = get_cfg_type_name(cfg) + "::" + typedef_type } } else { ret = g_cpp_types[field.Fieldtype] } return ret }
func get_field_c_type(field *generator.Field_t) string { var text string var c_type *string = &g_cpp_types[field.Fieldtype] switch { case field.Is_array(): text = "std::vector<%type%>" text = strings.Replace(text, "%type%", *c_type, -1) case field.Is_set(): text = "std::set<%type%>" text = strings.Replace(text, "%type%", *c_type, -1) default: text = *c_type } return text }