本文整理汇总了C++中dict类的典型用法代码示例。如果您正苦于以下问题:C++ dict类的具体用法?C++ dict怎么用?C++ dict使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了dict类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: py_rotate
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();
}
开发者ID:guitorri,项目名称:vpython-wx,代码行数:30,代码来源:wrap_primitive.cpp
示例2: work_with_dict
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);
}
开发者ID:AndroidAppList,项目名称:Android-Supertux,代码行数:7,代码来源:dict.cpp
示例3: shzdSendInfoToTrade
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());
}
开发者ID:BetabrainLEE,项目名称:vnpy,代码行数:48,代码来源:vnshzd.cpp
示例4: NearestNeighbourSearch
NearestNeighbourSearch(const object pycloud, const SearchType searchType = NNSNabo::KDTREE_LINEAR_HEAP, const Index dim = maxI, const dict params = dict())
{
// build cloud
eigenFromBoostPython(cloud, pycloud, "cloud");
// build params
Nabo::Parameters _params;
object it = params.iteritems();
for(int i = 0; i < len(params); ++i)
{
const tuple item(it.attr("next")());
const std::string key = extract<std::string>(item[0]);
const object val(item[1]);
const std::string valType(val.ptr()->ob_type->tp_name);
if (valType == "int")
{
const int iVal = extract<int>(val);
if (iVal >= 0)
_params[key] = (unsigned)iVal;
else
_params[key] = iVal;
}
}
// create search
nns = NNSNabo ::create(cloud, dim, searchType, 0, _params);
}
开发者ID:xthepoet,项目名称:libnabo,代码行数:27,代码来源:nabo.cpp
示例5: encode
void HuffmanEncoder::encode(dict d)
{
ofstream out;
out.open((path + ".ashf").c_str());
vector < Code > word_concat;
for (int i = 0; i < d.size(); i++)
{
if (d[i].c.q == -1 || d[i].c.r == -1)
continue;
word_concat.push_back(d[i].c);
}
// coding of min(i1, i2)
vector < string > r_s;
int k = 0;
for (int i = 0; i < word_concat.size(); i++)
{
int q_log = get_log(word_concat[i].q);
string kemp = "";
for (int i = 0; i <= q_log; i++)
{
kemp += (1 << i) & word_concat[i].r ? "1" : "0";
}
reverse(kemp.begin(), kemp.end());
r_s.push_back(kemp);
int r = word_concat[i].q;
word_concat[i].q -= k;
k = r;
}
root = build_tree(word_concat);
get_codes(root);
print_tree(root);
string long_string = "";
int q = 0;
for (int i = 0; i < word_concat.size(); i++)
{
string tempor = get_code(word_concat[i].q) + r_s[i] + (word_concat[i].d == true ? "1" : "0");
long_string = long_string + tempor;
}
int l_str_size = long_string.size();
int cur_p = 0;
while (cur_p < l_str_size)
{
unsigned char c = 0;
for (int i = 0; i < min(8, l_str_size - cur_p); i++)
{
int t = long_string[i + cur_p] == '0' ? 0 : 1;
c += (t << i);
}
cur_p += 8;
out << c;
}
out.close();
}
开发者ID:IsachenkoV,项目名称:ArchAssembly,代码行数:60,代码来源:HuffmanEncoder.cpp
示例6: dict_to_map
inline std::map<T1, T2> dict_to_map(const dict& d) {
std::map<T1, T2> result;
stl_input_iterator<tuple> begin(d.iteritems()), end;
std::transform(begin, end, map_inserter(result),
boost::bind(tuple_to_pair<T1, T2>(), _1));
return result;
}
开发者ID:kobolog,项目名称:lymc,代码行数:9,代码来源:python.hpp
示例7: getDouble
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();
}
}
};
开发者ID:BetabrainLEE,项目名称:vnpy,代码行数:12,代码来源:vnsgitmd.cpp
示例8: getShort
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(); //对目标整数指针赋值
}
}
};
开发者ID:BetabrainLEE,项目名称:vnpy,代码行数:12,代码来源:vnsgitmd.cpp
示例9: getChar
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;
}
}
};
开发者ID:BetabrainLEE,项目名称:vnpy,代码行数:14,代码来源:vnsgitmd.cpp
示例10: getStr
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);
}
}
};
开发者ID:BetabrainLEE,项目名称:vnpy,代码行数:16,代码来源:vnsgitmd.cpp
示例11: getStr
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
}
}
};
开发者ID:h1222443,项目名称:vnpy,代码行数:20,代码来源:vnxtptrader.cpp
示例12: dict_items
object dict_items(dict data)
{
return data.items();
}
开发者ID:AndroidAppList,项目名称:Android-Supertux,代码行数:4,代码来源:dict.cpp
示例13: dict_values
object dict_values(dict data)
{
return data.values();
}
开发者ID:AndroidAppList,项目名称:Android-Supertux,代码行数:4,代码来源:dict.cpp
示例14: dict_keys
object dict_keys(dict data)
{
return data.keys();
}
开发者ID:AndroidAppList,项目名称:Android-Supertux,代码行数:4,代码来源:dict.cpp
注:本文中的dict类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论