本文整理汇总了C++中item_t::size方法的典型用法代码示例。如果您正苦于以下问题:C++ item_t::size方法的具体用法?C++ item_t::size怎么用?C++ item_t::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类item_t
的用法示例。
在下文中一共展示了item_t::size方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: states
std::vector<int>
galleryd::queue::status(item_t &items, const std::string &category)
{
std::vector<int> states (items.size());
// build sql statement
auto stmt = category.empty()
? query_status_(items)
: query_status_with_category_(items, category);
// insert all found items into a map
std::map<std::string, int> lookup;
for(auto&& row : stmt)
lookup.emplace(row.as_string(0), row.as_int(1));
// build array with state-values for each item in the request.
// if the item doesn't exist, the value is '0'.
std::map<std::string, int>::const_iterator iter, end = lookup.end();
for(size_t i = 0, e = items.size(); i < e; ++i)
{
iter = lookup.find(items[i]);
states[i] = iter == end ? 0 : iter->second;
}
return states;
}
示例2: match
sqlite3pp::statement
galleryd::queue::query_status_(item_t &items)
{
// get category-ids for items
const auto len = items.size();
const auto categories = match(items);
// build query string
std::string q {
"SELECT item, state "
"FROM queue "
"WHERE (item=? AND category_id=?)"
};
for(size_t i = 1; i < len; ++i)
q += " OR (item=? AND category_id=?)";
// bind values to statement
auto stmt = db.prepare(q);
for(size_t i = 0; i < len; ++i)
{
stmt.bind(2*i+1, items[i]);
stmt.bind(2*i+2, categories[i]);
}
return stmt;
}
示例3: categories
galleryd::queue::category_t
galleryd::queue::match(
item_t &items)
{
std::smatch match;
const auto len = items.size();
category_t categories (len);
for(size_t i = 0; i < len; ++i)
{
// test with the last successfull regex first
if(std::regex_match(items[i], match, re_list[re_last].first))
{
items[i] = match[1];
categories[i] = re_list[re_last].second;
continue;
}
for(size_t j = 0; j < re_list.size(); ++j)
{
if(j == re_last)
continue;
if(std::regex_match(items[i], match, re_list[j].first))
{
items[i] = match[1];
categories[i] = re_list[j].second;
re_last = j;
}
}
}
return categories;
}
示例4:
void
galleryd::queue::query_add_with_category_(
item_t &items,
const std::string &category)
{
// get id from name
const auto category_id = query_category_id_(category);
// build query
auto stmt = db.prepare(
"INSERT INTO queue "
"(item, category_id) "
"VALUES (?, ?)"
);
stmt.bind(2, category_id);
// add items
auto tr = db.begin_transaction();
for(size_t i = 0, len = items.size(); i < len; ++i)
{
stmt.bind(1, items[i]);
stmt.exec();
}
tr.commit();
}
示例5: IN
sqlite3pp::statement
galleryd::queue::query_status_with_category_(
item_t &items,
const std::string &category)
{
// build query string
std::string q {
"SELECT item, state "
"FROM queue JOIN category "
"ON queue.category_id = category.id "
"WHERE category.name=? AND item IN (?"
};
for(size_t i = 1, e = items.size(); i < e; ++i)
q += ",?";
q += ')';
// bind values to statement
int idx = 1;
auto stmt = db.prepare(q);
stmt.bind(1, category);
for(auto&& item : items)
stmt.bind(++idx, item);
return stmt;
}