GnuCash c935c2f+
Loading...
Searching...
No Matches
Public Member Functions
GncQuotesImpl Class Reference

Public Member Functions

 GncQuotesImpl (QofBook *book)
 
 GncQuotesImpl (QofBook *, std::unique_ptr< GncQuoteSource >)
 
void fetch (QofBook *book)
 
void fetch (CommVec &commodities)
 
void fetch (gnc_commodity *comm)
 
void report (const char *source, const StrVec &commodities, bool verbose)
 
const std::string & version () noexcept
 
const QuoteSources & sources () noexcept
 
bool had_failures () noexcept
 
const QFVec & failures () noexcept
 
std::string report_failures () noexcept
 

Detailed Description

Definition at line 117 of file gnc-quotes.cpp.

Constructor & Destructor Documentation

◆ GncQuotesImpl() [1/3]

GncQuotesImpl::GncQuotesImpl ( )

Definition at line 298 of file gnc-quotes.cpp.

298 : m_quotesource{new GncFQQuoteSource},
299 m_sources{}, m_failures{},
300 m_book{qof_session_get_book(gnc_get_current_session())},
301 m_dflt_curr{gnc_default_currency()}
302{
303 m_sources = m_quotesource->get_sources();
304}
QofBook * qof_session_get_book(const QofSession *session)
Returns the QofBook of this session.
gnc_commodity * gnc_default_currency(void)
Return the default currency set by the user.

◆ GncQuotesImpl() [2/3]

GncQuotesImpl::GncQuotesImpl ( QofBook book)
explicit

Definition at line 306 of file gnc-quotes.cpp.

306 : m_quotesource{new GncFQQuoteSource},
307m_sources{}, m_book{book},
308m_dflt_curr{gnc_default_currency()}
309{
310 m_sources = m_quotesource->get_sources();
311}

◆ GncQuotesImpl() [3/3]

GncQuotesImpl::GncQuotesImpl ( QofBook book,
std::unique_ptr< GncQuoteSource quote_source 
)

Definition at line 313 of file gnc-quotes.cpp.

313 :
314m_quotesource{std::move(quote_source)},
315m_sources{}, m_book{book}, m_dflt_curr{gnc_default_currency()}
316{
317 m_sources = m_quotesource->get_sources();
318}

Member Function Documentation

◆ failures()

const QFVec & GncQuotesImpl::failures ( )
noexcept

Definition at line 379 of file gnc-quotes.cpp.

380{
381 return m_failures;
382}

◆ fetch() [1/3]

void GncQuotesImpl::fetch ( CommVec &  commodities)

Definition at line 338 of file gnc-quotes.cpp.

339{
340 m_failures.clear();
341 if (commodities.empty())
342 throw (GncQuoteException(bl::translate("GncQuotes::Fetch called with no commodities.")));
343 auto quote_str{query_fq (commodities)};
344 auto ptree{parse_quotes (quote_str)};
345 create_quotes(ptree, commodities);
346}

◆ fetch() [2/3]

void GncQuotesImpl::fetch ( gnc_commodity *  comm)

Definition at line 331 of file gnc-quotes.cpp.

332{
333 auto commodities = CommVec {comm};
334 fetch (commodities);
335}

◆ fetch() [3/3]

void GncQuotesImpl::fetch ( QofBook book)

Definition at line 321 of file gnc-quotes.cpp.

322{
323 if (!book)
324 throw (GncQuoteException(bl::translate("GncQuotes::Fetch called with no book.")));
325 auto commodities = gnc_quotes_get_quotable_commodities (
327 fetch (commodities);
328}
gnc_commodity_table * gnc_commodity_table_get_table(QofBook *book)
Returns the commodity table associated with a book.

◆ had_failures()

bool GncQuotesImpl::had_failures ( )
inlinenoexcept

Definition at line 132 of file gnc-quotes.cpp.

132{ return !m_failures.empty(); }

◆ report()

void GncQuotesImpl::report ( const char *  source,
const StrVec &  commodities,
bool  verbose 
)

Definition at line 349 of file gnc-quotes.cpp.

351{
352 if (!source)
353 throw (GncQuoteException(bl::translate("GncQuotes::Report called with no source.")));
354
355 bool is_currency{strcmp(source, "currency") == 0};
356 m_failures.clear();
357 if (commodities.empty())
358 {
359 std::cerr << _("There were no commodities for which to retrieve quotes.") << std::endl;
360 return;
361 }
362 try
363 {
364 auto quote_str{query_fq (source, commodities)};
365 auto ptree{parse_quotes (quote_str)};
366 auto source_pt_ai{ptree.find(source)};
367 if (is_currency)
368 show_currency_quotes(source_pt_ai->second, commodities, verbose);
369 else
370 show_quotes(source_pt_ai->second, commodities, verbose);
371 }
372 catch (const GncQuoteException& err)
373 {
374 std::cerr << _("Finance::Quote retrieval failed with error ") << err.what() << std::endl;
375 }
376}

◆ report_failures()

std::string GncQuotesImpl::report_failures ( )
noexcept

Definition at line 423 of file gnc-quotes.cpp.

424{
425 std::string retval{_("Quotes for the following commodities were unavailable or unusable:\n")};
426 std::for_each(m_failures.begin(), m_failures.end(),
427 [&retval](auto failure)
428 {
429 auto [ns, sym, reason, err] = failure;
430 retval += "* " + ns + ":" + sym + " " +
431 explain(reason, err) + "\n";
432 });
433 return retval;
434}

◆ sources()

const QuoteSources & GncQuotesImpl::sources ( )
inlinenoexcept

Definition at line 131 of file gnc-quotes.cpp.

131{ return m_sources; }

◆ version()

const std::string & GncQuotesImpl::version ( )
inlinenoexcept

Definition at line 130 of file gnc-quotes.cpp.

130{ return m_quotesource->get_version(); }

The documentation for this class was generated from the following file: