Exemplo n.º 1
0
// 生成读取属性的语句
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
}
Exemplo n.º 2
0
func splice_n_key(cfg *generator.Cfg_t, prefix string) string {
	var n_key int = len(cfg.Keys)
	if n_key <= 1 {
		return ""
	}

	var is_key_has_str bool = false

	for _, keyidx := range cfg.Keys {
		if cfg.Fields[keyidx].Fieldtype == generator.Fieldtype_string {
			is_key_has_str = true
			break
		}
	}

	var keys generator.Fieldvec_t
	for _, keyidx := range cfg.Keys {
		var key generator.Field_t = cfg.Fields[keyidx]

		key.En_name = prefix + key.En_name
		keys = append(keys, key)
	}

	var text string
	if is_key_has_str {
		text = splice_str_key(&keys)
	} else {
		text = splice_int_key(keys)
	}

	return text
}
Exemplo n.º 3
0
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
}
Exemplo n.º 4
0
func get_1_key_find_func_declare(cfg *generator.Cfg_t, field *generator.Field_t) string {
	if !field.Is_1_key() || field.Is_n_key() {
		return ""
	}

	var text string = "const %cfgtype%* %mgr%::get_%cfg%_by_%key_name%(%key%)"

	var key string = get_field_parameter_c_type(cfg, field) + " " + field.En_name
	text = strings.Replace(text, "%key%", key, -1)
	text = strings.Replace(text, "%key_name%", field.En_name, -1)
	text = strings.Replace(text, "%cfg%", cfg.En_name, -1)
	text = strings.Replace(text, "%cfgtype%", get_cfg_type_name(cfg), -1)
	return text
}
Exemplo n.º 5
0
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
}
Exemplo n.º 6
0
func gen_n_key_map_insert_stmt(cfg *generator.Cfg_t) string {
	var n_key int = len(cfg.Keys)
	if n_key <= 1 {
		return ""
	}

	var keys generator.Fieldvec_t
	for _, v := range cfg.Keys {
		var key generator.Field_t = cfg.Fields[v] // 注意,这里进行了赋值拷贝

		key.En_name = "cfg." + key.En_name
		keys = append(keys, key)
	}

	var map_key string = "\n        " + splice_n_key(cfg, "cfg.")
	var map_insert string = "\n        m_%map%[key] = curcfg;\n"
	map_insert = strings.Replace(map_insert, "%map%", get_n_key_map_name(cfg), -1)

	return map_key + map_insert
}