本文整理汇总了C++中IdSet::size方法的典型用法代码示例。如果您正苦于以下问题:C++ IdSet::size方法的具体用法?C++ IdSet::size怎么用?C++ IdSet::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IdSet
的用法示例。
在下文中一共展示了IdSet::size方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: listAllSeries
bool listAllSeries(const std::string& rootCategory, const std::string& outputFile) {
bool result(false);
using namespace fredcpp;
// Initialize
Api api;
api.withLogger(external::SimpleLogger::getInstance())
.withExecutor(external::CurlHttpClient::getInstance())
.withParser(external::PugiXmlParser::getInstance())
;
external::SimpleLogger::getInstance().enableInfo();
FREDCPP_LOG_INFO(FREDCPP_FACILITY << " version " << FREDCPP_VERSION_STRING
<< " (" << FREDCPP_BRIEF << ")");
FREDCPP_LOG_INFO("Getting API key from environment variable " << ENV_API_KEY << " ...");
api.withKey(getKeyFromEnv(ENV_API_KEY));
// Build a list of available sub-categories under the root
FREDCPP_LOG_INFO("Building list of available sub-categories of category " << rootCategory << " ...");
ChildrenByIdMap categoryTree;
if ( 0 == buildCategoryTree(api, categoryTree, rootCategory)) {
FREDCPP_LOG_FATAL("Unable to retrieve categories");
exit(EXIT_FAILURE);
}
FREDCPP_LOG_INFO("Available categories count:" << categoryTree.size());
FREDCPP_LOG_INFO("Creating output data file " << outputFile << " ...");
std::ofstream output(outputFile.c_str());
if (!output) {
exitOnBadOutputFile(outputFile);
}
// Get series
IdSet uniqueSeries;
ApiResponse response;
for (ChildrenByIdMap::iterator it = categoryTree.begin();
it != categoryTree.end();
++it) {
std::string categoryId(it->first);
api.get(ApiRequestBuilder::CategorySeries(categoryId)
, response) || exitOnApiError(response);
if (!response.entities.size()) {
FREDCPP_LOG_INFO("category:" << categoryId << " contains no series");
}
// Print series
// NOTE: a given series can belong to multiple categories,
// so keep track of unique series
for (std::size_t n = 0; n < response.entities.size(); ++n) {
std::string seriesId (response.entities[n].attribute("id"));
if (uniqueSeries.find(seriesId) != uniqueSeries.end()) {
continue;
}
uniqueSeries.insert(seriesId);
output << response.entities[n].attribute("id")
<< "|" << response.entities[n].attribute("frequency_short")
<< "|" << response.entities[n].attribute("title")
<< "|" << response.entities[n].attribute("observation_start")
<< "|" << response.entities[n].attribute("observation_end")
<< "|"
<< std::endl;
}
}
// Report stats
FREDCPP_LOG_INFO("root-category:" << rootCategory
<< " sub-categories-count:" << categoryTree.size() - 1
<< " series-count:" << uniqueSeries.size());
output.close();
FREDCPP_LOG_INFO("Successfully created file " << outputFile);
result = true;
return (result);
//.........这里部分代码省略.........
示例2: buildCategoryTree
std::size_t buildCategoryTree(fredcpp::Api& api, ChildrenByIdMap& tree, const std::string& rootCategory) {
std::size_t categoryCount;
using namespace fredcpp;
tree.clear();
// Request children categories for sub-categories starting from rootCategory
std::string parentId(rootCategory);
// Add top-level categories
categoryCount = addCategoryToTree(api, tree, parentId);
if (categoryCount == 0) {
return (categoryCount);
}
std::list<IdSet> parentLevels;
IdSet parents;
IdSet children = tree[parentId];
if (children.size()) {
parentLevels.push_back(children);
} else {
return (categoryCount);
}
while (parentLevels.size()) {
parents = parentLevels.front();
for (IdSet::iterator itNextParent = parents.begin();
itNextParent != parents.end();
++itNextParent) {
for (IdSet::iterator itChild = children.begin();
itChild != children.end();
++itChild) {
std::string childId(*itChild);
//FREDCPP_LOG_INFO("category:" << childId << " parent:" << parentId);
categoryCount += addCategoryToTree(api, tree, childId);
}
parentId = *itNextParent;
children = tree[parentId];
if (children.size()) {
parentLevels.push_back(children);
}
}
parentLevels.pop_front();
}
return (categoryCount);
}