当前位置: 首页>>代码示例>>C++>>正文


C++ optional::c_str方法代码示例

本文整理汇总了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)));

}
开发者ID:Gnucash,项目名称:gnucash,代码行数:67,代码来源:gnc-imp-props-tx.cpp

示例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());
}
开发者ID:the-kenny,项目名称:flusspferd,代码行数:9,代码来源:namespace.cpp

示例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);
     }
 }
开发者ID:OSVR,项目名称:OSVR-Core,代码行数:9,代码来源:VrpnBasedConnection.cpp

示例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);
}
开发者ID:tomhughes,项目名称:osm2pgsql,代码行数:18,代码来源:parse-osmium.cpp

示例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);
}
开发者ID:the-kenny,项目名称:flusspferd,代码行数:6,代码来源:node.cpp


注:本文中的boost::optional::c_str方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。