我正在处理通用配置文件解析器。C++中的通用配置文件解析器设置器
第一个,应该调用一个函数来设置变量的数据类型。
enum type {a,b,c};
union{int a; double b; float c;};
void SetTypes(type x, string *names){
// names[] contains the names of the variables
// type is what data type from the union needs to be used
union name.x; //------(1)
}
但是我面临的问题与字符串[]长度。
所以,我做我的函数以下列方式
void setTypes(type a, string name...){}
有使之更为高效的任何方式;这样我可以将相同类型的数据捆绑在一起?
该程序的目的是让我们不必在我们的代码中预定义数据类型,使配置解析器更加灵活。
的秒问题在这里是行标(1) 我如何<union> <varname>.<enum>
发生呢?其中VARNAME和枚举是变量
编辑1:加入实施例
例如,
struct EXAMPLE{
/*Some Code*/
enum allowed_types {vec3D, complex_num};
union {
Vector3D vec3D;
Complex complex_num;
};
/* More Code*/
};
当我调用该函数的方式
setType(vec3D, {"point1", "point 2", "point3"}, complex_num, {"num1", "num2"});
然后我需要的函数使变量(每个结构) point1 of type Vector3D point2 of type Vector3D point3 of type Vector3D num1 of type Complex num2 of type Complex
我使用枚举,以便对使用的类型有更多的控制。 我正在使用联合,以便我可以使用指针将值存储在散列表中,以最大限度地减少空间损失。
推荐编辑:'a'使用了三种不同的方式来制作混淆阅读。 – user4581301
我在这里有点困惑。你对名字的长度有什么问题?他们是数百万?你真的确定你需要一个工会来存储数据吗?你能否更精确地了解所需的行为并举例说明? – user1620443
@ user4581301它使用的是“a”。 –