数据量大,怎么样处理才能最快的完成参数模板赋值。急急急急!!!
传入参数有, Aname ,Anum ,status,
但是现在参数的模板有100多个。
就像这个样子
AAA|Method=SetMOAttributes(BBB={CCC};DDD =Status;)
AAA|Method=GetMOAttributes(BBB={CCC};DDD =Status;)
。。。。。。。
其中SetMOAttributes是变化的,有好多个方法。
BBB 和DDD也是变化的但是这个在模板中是死的。
就像上面这个有100多个。
用的时候,CCC里面的值就是传入的参数Anum ,Status 的值就是status
Aname 是此次操作的名称,在参数中没用,
我想配到数据库中去根据ANAME在区分开来,在找到,然后进行参数赋值,
发现还是要处理好多次。而且效率低了。
怎么样处理才能最快的速度。将传入参数与参数模板找到,并且将值能给模板中的赋值。
形成一个完整的指令。
并且数据量是很大的。 100 多个可能还是要扩展的。
也就是说这个操作比较频繁。
速速啊。在线等待中。。。 参数赋值 行业数据 数据库 ?c++??逻辑
[解决办法]
1、你的模板以字符串的方式表达为正则表达式的模式;
2、你的具体参数也以字符串的形式进行存取;
3、当参数匹配某个模板时,就进入该模板的解析程序;
4、正则表达式参考http://www.wuzesheng.com/?p=929
我的意思是如果查出来了,在赋值。因为每一个赋值参数都是不一样的,难道你要赋值一百次??
你是说, 如果 SetMOAttributes 这个是函数名的话, 一共会有 100 多个函数?
每一个不同的 SetMOAttributes 需要调用不同的函数?
是的。。但是那个传参个数是一样的。但是模板一会发生变化。
函数也会发生变化。
类型是一样的
参数个数一样, 类型是否一样呢? 如果参数类型也一样, 用函数指针就行了.
类型是一样的,能否细说一下呢谢谢
#include <map>
#include <string>
#include <stdio.h>
#include <string.h>
#include <iostream>
// 根据你的函数接受的参数定义固定的函数指针类型, 这里是随便写的
typedef void (*Method_t)(const std::string& x1, int x2);
void f1(const std::string& x1, int x2) {};
void f2(const std::string& x1, int x2) {};
void SetMOAttributes(const std::string& x1, int x2) {
std::cout << x1 << ": " << x2 << std::endl;
}
#define INIT_FUNC(x) g_funcs[#x] = x;
int main(int argc,char* argv[])
{
// 初始化函数列表
std::map<std::string, Method_t> g_funcs;
INIT_FUNC(f1);
INIT_FUNC(f2);
INIT_FUNC(SetMOAttributes);
char str[1024] = "AAA
[解决办法]
Method=SetMOAttributes(BBB={CCC};DDD =200;)";
if(1) //while(fgets(str, 10, NULL)) 假设这里是在用循环读取文件中的每一行到 str 中.
{
// 获取参数
char* method = strstr(str, "Method=") + strlen("Method=");
char* ender = strstr(method, "(");
ender[0] = 0; // 把 ( 改成 0, method 就是方法的字符串了.
char* firstArg = strstr(ender + 1, "=");
++firstArg;
ender = strstr(firstArg, ";"); // 分号作为第一个参数的结束.
ender[0] = 0;
char* secondArg = strstr(ender + 1, "=");
++secondArg;
ender = strstr(secondArg, ";");
ender[0] = 0;
// 假设上面是取到的函数名和参数
g_funcs[method](firstArg, atoi(secondArg)); // 用参数调用指定函数名的函数.
}
return 0;
}