本文整理汇总了C++中boost::property_tree::ptree::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ ptree::clear方法的具体用法?C++ ptree::clear怎么用?C++ ptree::clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::property_tree::ptree
的用法示例。
在下文中一共展示了ptree::clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GeneratePhonesXml
void CContentParser::GeneratePhonesXml(const TPhones& mpPhones, boost::property_tree::ptree& xmlResult)
{
xmlResult.clear();
boost::property_tree::ptree& xmlRoot = xmlResult.put(std::string(PHONES_ROOT_NAME), "");
TPhones::const_iterator it = mpPhones.begin();
const TPhones::const_iterator itEnd = mpPhones.end();
for (; it != itEnd; ++it)
{
if (it->second < 2)
continue;
xmlRoot.push_back(std::make_pair(std::string(PHONES_ITEM_NAME), boost::property_tree::ptree()));
boost::property_tree::ptree& xmlPhone = xmlRoot.back().second;
xmlPhone.put(std::string("<xmlattr>.") + PHONES_NUMBER_NAME, it->first);
xmlPhone.put(std::string("<xmlattr>.") + PHONES_COUNT_NAME, boost::lexical_cast< std::string > (it->second));
}
}
示例2: ParseSite
bool CContentParser::ParseSite(const std::string& sURL, boost::property_tree::ptree& xmlResult)
{
bool bNotEmpty = false;
xmlResult.clear();
boost::property_tree::ptree& xmlRoot = xmlResult.put("data", "");
std::size_t nPageCount = 1;
std::size_t nEmptyPages = 0;
while(1)
{
try
{
const std::string sPage = (boost::format(sURL) % nPageCount++).str();
std::cout << (boost::format("Processing page: [%s]...") % sPage).str();
CDownloader Dwnldr;
Dwnldr.Open(sPage);
std::string sBuffer;
Dwnldr.Read(sBuffer);
const std::string::size_type encoding = sBuffer.find("charset=");
if (encoding != std::string::npos)
{
const std::string::size_type encodingEnd = sBuffer.find("\"", encoding);
if (encodingEnd != std::string::npos)
{
const std::string encodingValue(sBuffer.substr(encoding + 8, encodingEnd - encoding - 8));
if (boost::algorithm::iequals(encodingValue, "utf-8"))
{
const std::wstring out = boost::locale::conv::utf_to_utf<wchar_t, char>(sBuffer);
sBuffer = boost::locale::conv::from_utf<wchar_t>(out, "cp1251");
}
}
}
std::vector< std::string > vecItems;
ParsePage(sBuffer, vecItems);
std::cout << (boost::format("\titems parsed: [%s]") % vecItems.size()).str() << std::endl;
if (vecItems.empty())
++nEmptyPages;
else
nEmptyPages = 0;
if (nEmptyPages > 5)
break;
bNotEmpty = true;
std::vector< std::string >::iterator it = vecItems.begin();
const std::vector< std::string >::iterator itEnd = vecItems.end();
BOOST_FOREACH(std::string& sCurrent, vecItems)
{
xmlRoot.push_back(std::pair< std::string, boost::property_tree::ptree > ("item", boost::property_tree::ptree()));
boost::property_tree::ptree& xmlItem = xmlRoot.back().second;
ParseItem(sCurrent, xmlItem);
}
}
catch (std::exception& e)
{
std::cout << e.what() << std::endl;
}
}
return bNotEmpty;
}