Beispiel #1
0
object
py_rotate( tuple args, dict kwargs)
{
    Prim* This = extract<Prim*>( args[0]);

    if (!kwargs.has_key("angle")) {
        // This exception is more useful than the keyerror exception below.
        throw std::invalid_argument(
            "primitive.rotate(): angle of rotation must be specified.");
    }

    double angle = extract<double>(kwargs["angle"]);

    // The rotation axis, which defaults to the body axis.
    vector r_axis;
    if (kwargs.has_key("axis"))
        r_axis = tovector(kwargs["axis"]);
    else
        r_axis = This->get_axis();

    // The rotation origin, which defaults to the body position.
    vector origin;
    if (kwargs.has_key("origin"))
        origin = tovector(kwargs["origin"]);
    else
        origin = This->get_pos();

    This->rotate( angle, r_axis, origin);
    return object();
}
void work_with_dict(dict data1, dict data2)
{
    if (!data1.has_key("k1")) {
        throw std::runtime_error("dict does not have key 'k1'");
    }
    data1.update(data2);
}
Beispiel #3
0
void getDouble(dict d, string key, double *value)
{
	if (d.has_key(key))
	{
		object o = d[key];
		extract<double> x(o);
		if (x.check())
		{
			*value = x();
		}
	}
};
Beispiel #4
0
void getShort(dict d, string key, short *value)
{
	if (d.has_key(key))		//检查字典中是否存在该键值
	{
		object o = d[key];	//获取该键值
		extract<int> x(o);	//创建提取器
		if (x.check())		//如果可以提取
		{
			*value = x();	//对目标整数指针赋值
		}
	}
};
Beispiel #5
0
void getChar(dict d, string key, char *value)
{
	if (d.has_key(key))
	{
		object o = d[key];
		extract<string> x(o);
		if (x.check())
		{
			string s = x();
			const char *buffer = s.c_str();
			*value = *buffer;
		}
	}
};
Beispiel #6
0
int ShzdApi::shzdSendInfoToTrade(dict data)
{
	CShZdMessage msg = CShZdMessage();

	//插入信息类型
	if (data.has_key("msgtype"))
	{
		object msgtype = data["msgtype"];
		extract<string> x(msgtype);
		if (x.check())
		{
			string typestr = x();
			msg.SetMsgType(typestr.c_str());
		}
	}
	
	//插入字段
	boost::python::list keyList = data.keys();
	boost::python::list valueList = data.values();

	for (int n = 0; n < len(keyList); n++)		
	{
		//声明
		int keyint = 0;
		string valuestr = "";
		
		//获取整数型的key
		object key = keyList[n];
		extract<string> x1(key);
		if (x1.check())
		{
			string keystr = x1();
			stringstream ss;
			ss << keystr;
			ss >> keyint;
		}

		//获取字符串的value
		object value = valueList[n];
		extract<string> x2(value);
		if (x2.check())
		{
			valuestr = x2();
		}

		//添加到msg中
		msg.SetTag(keyint, valuestr.c_str());
	}
Beispiel #7
0
void getStr(dict d, string key, char *value)
{
	if (d.has_key(key))
	{
		object o = d[key];
		extract<string> x(o);
		if (x.check())
		{
			string s = x();
			const char *buffer = s.c_str();
			//对字符串指针赋值必须使用strcpy_s, vs2013使用strcpy编译通不过
			//+1应该是因为C++字符串的结尾符号?不是特别确定,不加这个1会出错
			strcpy_s(value, strlen(buffer) + 1, buffer);
		}
	}
};
Beispiel #8
0
void getStr(dict d, string key, char *value)
{
	if (d.has_key(key))
	{
		object o = d[key];
		extract<string> x(o);
		if (x.check())
		{
			string s = x();
			const char *buffer = s.c_str();
			//对字符串指针赋值必须使用strcpy_s, vs2013使用strcpy编译通不过
			//+1应该是因为C++字符串的结尾符号?不是特别确定,不加这个1会出错
#ifdef _MSC_VER //WIN32
			strcpy_s(value, strlen(buffer) + 1, buffer);
#elif __GNUC__
			strncpy(value, buffer, strlen(buffer) + 1);
#endif
		}
	}
};