From 494364c22e065ef6f432a955250147536ea31a8e Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Thu, 15 Feb 2018 10:39:46 +0000 Subject: [PATCH] Put the always-stdin symbol in the right place. --- src/html_pool.cpp | 12 +----------- src/scraplang/xpath_runner.cpp | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/html_pool.cpp b/src/html_pool.cpp index c964884..8f43901 100644 --- a/src/html_pool.cpp +++ b/src/html_pool.cpp @@ -24,12 +24,6 @@ #include #include -//#define HTML_ALWAYS_STDIN - -#if !defined(NDEBUG) && defined(HTML_ALWAYS_STDIN) -# define HTML_ALWAYS_STDIN_ENABLED -#endif - namespace duck { HtmlPool::HtmlPool (std::string&& agent_name) : m_agent(std::move(agent_name)) @@ -39,13 +33,9 @@ namespace duck { auto HtmlPool::OnResourceLoad (ResourceObjectParameterType parRes) -> ResourceType* { std::unique_ptr html; - std::cout << "Fetching html from \"" << parRes << "\"\n"; + std::cout << "OnResourceLoad(): fetching html from \"" << parRes << "\"\n"; -#if defined(HTML_ALWAYS_STDIN_ENABLED) - if (true) { -#else if (parRes == "-") { -#endif html = std::make_unique(read_all(std::cin)); } else { diff --git a/src/scraplang/xpath_runner.cpp b/src/scraplang/xpath_runner.cpp index d1167e6..84014da 100644 --- a/src/scraplang/xpath_runner.cpp +++ b/src/scraplang/xpath_runner.cpp @@ -21,6 +21,12 @@ #include #include +//#define HTML_ALWAYS_STDIN + +#if !defined(NDEBUG) && defined(HTML_ALWAYS_STDIN) +# define HTML_ALWAYS_STDIN_ENABLED +#endif + namespace duck { namespace sl { struct XPathRunner::XPathKey { XPathKey (const std::string_view& parSrc, const std::string_view& parQuery) : @@ -53,17 +59,22 @@ namespace duck { namespace sl { std::string_view parSrc, std::string_view parQuery ) { - std::cout << "XPathRunner::query() - \"" << parQuery << "\"\n"; + std::cout << "XPathRunner::query(\"" << parSrc << "\", \"" << parQuery << "\")\"\n"; auto ins_retval = m_cached_results.insert(std::make_pair(XPathKey(parSrc, parQuery), std::vector())); const bool inserted = ins_retval.second; assert(ins_retval.first != m_cached_results.end()); std::vector& curr_vec = ins_retval.first->second; if (inserted) { - const auto id = m_pool->AddResource(parSrc); +#if defined(HTML_ALWAYS_STDIN_ENABLED) + const auto id = m_pool->GetOrAdd("-"); +#else + const auto id = m_pool->GetOrAdd(parSrc); +#endif const std::string* html = m_pool->GetByID(id); curr_vec = xpath_query(*html, std::string(parQuery)); + std::cout << "First time for this query, result cached now\n"; } std::cout << "returning " << curr_vec.size() << " items: ";