Skip to content

Commit

Permalink
Change callback params from reference to pointer, template params to …
Browse files Browse the repository at this point in the history
…OrderBook,
  • Loading branch information
iamtheschmitzer committed Apr 4, 2013
1 parent 9fa1a37 commit 914130c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/book/bbo_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ template <class OrderBook, class DepthTracker >
class BboListener {
public:
/// @brief callback for top of book change
virtual void on_bbo_change(const OrderBook& book,
const DepthTracker& depth) = 0;
virtual void on_bbo_change(const OrderBook* book,
const DepthTracker* depth) = 0;
};

} }
Expand Down
4 changes: 2 additions & 2 deletions src/book/depth_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ template <class OrderBook, class DepthTracker >
class DepthListener {
public:
/// @brief callback for change in tracked aggregated depth
virtual void on_depth_change(const OrderBook& book,
const DepthTracker& depth) = 0;
virtual void on_depth_change(const OrderBook* book,
const DepthTracker* depth) = 0;
};

} }
Expand Down
4 changes: 2 additions & 2 deletions src/book/depth_order_book.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ DepthOrderBook<OrderPtr, SIZE>::perform_callback(DobCallback& cb)
// Book was updated, see if the depth we track was effected
if (depth_.changed()) {
if (depth_listener_) {
depth_listener_->on_depth_change(*this, depth_);
depth_listener_->on_depth_change(this, &depth_);
}
if (bbo_listener_) {
ChangeId last_change = depth_.last_published_change();
// May have been the first level which changed
if ((depth_.bids()->changed_since(last_change)) ||
(depth_.asks()->changed_since(last_change))) {
bbo_listener_->on_bbo_change(*this, depth_);
bbo_listener_->on_bbo_change(this, &depth_);
}

}
Expand Down
21 changes: 11 additions & 10 deletions src/book/order_book.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace liquibook { namespace book {
template<class OrderPtr>
class OrderListener;

template<class OrderPtr>
template<class OrderBook>
class OrderBookListener;

/// @brief Tracker of an order's state, to keep inside the OrderBook.
Expand Down Expand Up @@ -76,7 +76,8 @@ class OrderBook {
typedef OrderTracker<OrderPtr > Tracker;
typedef Callback<OrderPtr > TypedCallback;
typedef OrderListener<OrderPtr > TypedOrderListener;
typedef OrderBookListener<OrderPtr > TypedOrderBookListener;
typedef OrderBook<OrderPtr > MyClass;
typedef OrderBookListener<MyClass > TypedOrderBookListener;
typedef std::vector<TypedCallback > Callbacks;
typedef std::multimap<Price, Tracker, std::greater<Price> > Bids;
typedef std::multimap<Price, Tracker, std::less<Price> > Asks;
Expand All @@ -87,10 +88,10 @@ class OrderBook {
OrderBook();

/// @brief set the order listener
void set_order_listener(TypedOrderListener* order_listener);
void set_order_listener(TypedOrderListener* listener);

/// @brief set the order book listener
void set_book_listener(TypedOrderBookListener* book_listener);
void set_order_book_listener(TypedOrderBookListener* listener);

/// @brief add an order to book
/// @param order the order to add
Expand Down Expand Up @@ -188,7 +189,7 @@ class OrderBook {
DeferredAskCrosses deferred_ask_crosses_;
Callbacks callbacks_;
TypedOrderListener* order_listener_;
TypedOrderBookListener* book_listener_;
TypedOrderBookListener* order_book_listener_;
TransId trans_id_;

Price sort_price(const OrderPtr& order);
Expand Down Expand Up @@ -280,7 +281,7 @@ OrderTracker<OrderPtr>::immediate_or_cancel() const
template <class OrderPtr>
OrderBook<OrderPtr>::OrderBook()
: order_listener_(NULL),
book_listener_(NULL),
order_book_listener_(NULL),
trans_id_(0)
{
callbacks_.reserve(16);
Expand All @@ -295,9 +296,9 @@ OrderBook<OrderPtr>::set_order_listener(TypedOrderListener* listener)

template <class OrderPtr>
void
OrderBook<OrderPtr>::set_book_listener(TypedOrderBookListener* listener)
OrderBook<OrderPtr>::set_order_book_listener(TypedOrderBookListener* listener)
{
book_listener_ = listener;
order_book_listener_ = listener;
}

template <class OrderPtr>
Expand Down Expand Up @@ -680,8 +681,8 @@ OrderBook<OrderPtr>::perform_callback(TypedCallback& cb)
std::runtime_error("Unexpected callback type for order");
break;
}
} else if (cb.order_book && book_listener_) {
book_listener_->on_order_book_change(*cb.order_book);
} else if (cb.type == TypedCallback::cb_book_update && order_book_listener_) {
order_book_listener_->on_order_book_change(this);
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/book/order_book_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
namespace liquibook { namespace book {

/// @brief generic listener of order book events
template <class OrderPtr = Order*>
template <class OrderBook >
class OrderBookListener {
public:
typedef OrderBook<OrderPtr> TypedOrderBook;

/// @brief callback for change anywhere in order book
virtual void on_order_book_change(const TypedOrderBook& book) = 0;
virtual void on_order_book_change(const OrderBook* book) = 0;
};

} }
Expand Down

0 comments on commit 914130c

Please sign in to comment.