From 7470c95aae9a0d9dc3d31b1485b95163f282af87 Mon Sep 17 00:00:00 2001 From: cxx24 Date: Sun, 21 Apr 2024 15:13:34 -0700 Subject: [PATCH] allow custom Ad structure --- rtb/core/ad_selector.hpp | 16 ++++++++++++++-- rtb/core/bidder.hpp | 5 ++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/rtb/core/ad_selector.hpp b/rtb/core/ad_selector.hpp index 3b25351..52747f5 100644 --- a/rtb/core/ad_selector.hpp +++ b/rtb/core/ad_selector.hpp @@ -52,6 +52,12 @@ static auto chain_function(BidRequest &&req, Impression &&imp, Arg &&arg, } // namespace detail +template +concept is_vanilla_standard_ad = requires(T value) { + value.auth_bid_micros; + value.max_bid_micros; +}; + template class ad_selector { public: @@ -66,10 +72,16 @@ class ad_selector { template auto select(BidRequest&& req, Impression&& imp, HeadArg&& head, Funcs... funcs) { auto ads = detail::chain_function( std::forward(req), std::forward(imp), std::forward(head), funcs...); - if(selection_algo) { + if (selection_algo) { return selection_algo(ads); + } else { + if constexpr ( is_vanilla_standard_ad) { + return algorithm::calculate_max_bid(ads); + } else { + // TODO: add compile time warning for using dummy algo + return std::unique_ptr{}; + } } - return algorithm::calculate_max_bid(ads); } template diff --git a/rtb/core/bidder.hpp b/rtb/core/bidder.hpp index a06420d..5b96178 100644 --- a/rtb/core/bidder.hpp +++ b/rtb/core/bidder.hpp @@ -92,7 +92,10 @@ namespace vanilla { bid.id = boost::uuids::to_string(bidid); // TODO check documentation // Is it the same as response.bidid? bid.impid = imp.id; - bid.price = ad.auth_bid_micros ? *ad.auth_bid_micros / 1000000.0 : ad.max_bid_micros / 1000000.0 ; // Not micros? + if constexpr (sizeof...(Processor) <= 0) { + bid.price = + ad.auth_bid_price ? *ad.auth_bid_price / 1000000.0 : ad.max_bid_micros / 1000000.0; + } bid.w = ad.width; bid.h = ad.height; bid.adm = ad.code;