/** 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))); }
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()); }
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); } }
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); }
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); }