本文整理汇总了C++中boost::optional::c_str方法的典型用法代码示例。如果您正苦于以下问题:C++ optional::c_str方法的具体用法?C++ optional::c_str怎么用?C++ optional::c_str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::optional
的用法示例。
在下文中一共展示了optional::c_str方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: trans_add_split
/** Adds a split to a transaction.
* @param trans The transaction to add a split to
* @param account The split's account
* @param amount The split's amount
* @param rec_state The split's reconcile status
* @param rec_date The split's reconcile date
* @param price The split's conversion rate from account commodity to transaction commodity
*/
static void trans_add_split (Transaction* trans, Account* account, GncNumeric amount,
const boost::optional<std::string>& action,
const boost::optional<std::string>& memo,
const boost::optional<char>& rec_state,
const boost::optional<GncDate>& rec_date,
const boost::optional<GncNumeric> price)
{
QofBook* book = xaccTransGetBook (trans);
auto split = xaccMallocSplit (book);
xaccSplitSetAccount (split, account);
xaccSplitSetParent (split, trans);
xaccSplitSetAmount (split, static_cast<gnc_numeric>(amount));
auto trans_curr = xaccTransGetCurrency(trans);
auto acct_comm = xaccAccountGetCommodity(account);
GncNumeric value;
if (gnc_commodity_equiv(trans_curr, acct_comm))
value = amount;
else if (price)
value = amount * *price;
else
{
auto time = xaccTransRetDatePosted (trans);
/* Import data didn't specify price, let's lookup the nearest in time */
auto nprice =
gnc_pricedb_lookup_nearest_in_time64(gnc_pricedb_get_db(book),
acct_comm, trans_curr, time);
if (nprice)
{
/* Found a usable price. Let's check if the conversion direction is right */
GncNumeric rate;
if (gnc_commodity_equiv(gnc_price_get_currency(nprice), trans_curr))
rate = gnc_price_get_value(nprice);
else
rate = static_cast<GncNumeric>(gnc_price_get_value(nprice)).inv();
value = amount * rate;
}
else
{
PWARN("No price found, using a price of 1.");
value = amount;
}
}
xaccSplitSetValue (split, static_cast<gnc_numeric>(value));
if (memo)
xaccSplitSetMemo (split, memo->c_str());
/* Note, this function assumes the num/action switch is done at a higher level
* if needed by the book option */
if (action)
xaccSplitSetAction (split, action->c_str());
if (rec_state && *rec_state != 'n')
xaccSplitSetReconcile (split, *rec_state);
if (rec_state && *rec_state == YREC && rec_date)
xaccSplitSetDateReconciledSecs (split,
static_cast<time64>(GncDateTime(*rec_date, DayPart::neutral)));
}
示例2: set_prefix
void namespace_::set_prefix(boost::optional<std::string> const &x) {
if (ptr->prefix)
xmlFree((xmlChar *) ptr->prefix);
if (!x)
ptr->prefix = 0;
else
ptr->prefix = xmlStrdup((xmlChar const *) x->c_str());
}
示例3:
VrpnBasedConnection::VrpnBasedConnection(
boost::optional<std::string const &> iface, boost::optional<int> port) {
int myPort = port.get_value_or(0);
if (iface && !(iface->empty())) {
m_initConnection(iface->c_str(), myPort);
} else {
m_initConnection(nullptr, myPort);
}
}
示例4: parse_bbox
osmium::Box parse_osmium_t::parse_bbox(const boost::optional<std::string> &bbox)
{
double minx, maxx, miny, maxy;
int n = sscanf(bbox->c_str(), "%lf,%lf,%lf,%lf",
&minx, &miny, &maxx, &maxy);
if (n != 4)
throw std::runtime_error("Bounding box must be specified like: minlon,minlat,maxlon,maxlat\n");
if (maxx <= minx)
throw std::runtime_error("Bounding box failed due to maxlon <= minlon\n");
if (maxy <= miny)
throw std::runtime_error("Bounding box failed due to maxlat <= minlat\n");
fprintf(stderr, "Applying Bounding box: %f,%f to %f,%f\n", minx, miny, maxx, maxy);
return osmium::Box(minx, miny, maxx, maxy);
}
示例5: set_content
void node::set_content(boost::optional<std::string> const &x) {
xmlNodeSetContent(ptr, 0);
if (x)
xmlNodeAddContent(ptr, (xmlChar const *) x->c_str());
create_all_children(ptr, true, false);
}