35 template <
typename Depth>
40 error +=
"Cannot re-depth order book " 41 "due to lack of capacity [newDepth=";
43 toStr(error, newDepth);
45 error +=
",maxDepth=";
47 toStr(error, maxDepth);
51 throw std::runtime_error(error);
58 template <
class EntryType,
class DepthType>
80 MbpBook(Depth capacity, Entry* bids, Entry* offers)
83 , bids_(bids, capacity)
84 , offers_(offers, capacity)
101 return bids_.capacity();
107 if (depth > capacity())
112 if (bids_.size() > depth)
115 if (offers_.size() > depth)
116 offers_.resize(depth);
220 template <
class TargetPriceLevel,
class SourcePriceLevel,
class Depth>
224 Depth maxDepth = static_cast<Depth>(-1)
227 if (maxDepth > source.
depth())
229 maxDepth = source.
depth();
232 target.
depth(maxDepth);
244 template <
class PriceLevelType,
class DepthType>
261 return (
sizeof(Book) + 2 * maxDepth *
sizeof(Entry));
269 const size_t bookSize = calcSize(maxDepth);
271 return inplaceConstruct(maxDepth,
new Byte[bookSize]);
281 delete[]
reinterpret_cast<Byte*
>(book);
288 Entry*
const entries =
reinterpret_cast<Entry*
>(
reinterpret_cast<Byte*
>(block) +
sizeof(Book));
290 inplaceConstruct(entries, entries + 2 * maxDepth);
292 return new (block) Book(maxDepth, entries, entries + maxDepth);
296 static void inplaceConstruct(Entry* first, Entry* last)
298 while (first != last)
299 new (first++) Entry();
Base attributes of order book.
void depth(Depth depth)
Updates the maximal number of price levels.
UInt8 Byte
Alias for Byte.
static size_t calcSize(Depth maxDepth)
Calculates size of memory required to keep in memory book of given depth.
void reset(BookState::Enum bookState)
Wipes out all bids and offers and other data associated with book (like instance of last applied FIX ...
Tag class for accessing bids in templates.
BookState::Enum state() const
Indicates current state of book.
MbpBook< TargetPriceLevel, Depth > & copy(MbpBook< TargetPriceLevel, Depth > &target, const MbpBook< SourcePriceLevel, Depth > &source, Depth maxDepth=static_cast< Depth >(-1))
Copies content of one book to another.
static Book * inplaceConstruct(Depth maxDepth, void *block)
Constructs book on a given memory block.
Depth capacity() const
Indicates book capacity which is maximal value of book depth allowed.
static Book * construct(Depth maxDepth)
Constructs book instance of given capacity.
EntryType Entry
Indicates price level data type.
void toStr(std::string &str, const Message &message)
Serializes FIX message into tag=value format.
Entries::ConstIterator EntryIterator
Iterator over bids and offers.
Entries & operator[](const Bids &)
List of descending bid prices.
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Depth depth() const
Returns the maximal number of price levels.
MbpBook< PriceLevelType, DepthType > Book
Type of book constructed by given factory.
const Entries & bids() const
List of descending bid prices.
VectorOverArray< Entry, Depth > Entries
Collection of price levels allowing modifications.
void state(BookState::Enum state)
Updates state of book.
MbpBook(Depth capacity, Entry *bids, Entry *offers)
Initializes instance with given attributes.
static void destruct(Book *book)
Destructs previously constructed book.
Book::Entry Entry
Book entry type.
DepthType Depth
Aliases book dimension type.
Entries & operator[](const Offers &)
List of ascending offer prices.
const Entries & operator[](const Bids &) const
List of descending bid prices.
Entries & bids()
List of descending bid prices.
Entries & offers()
List of ascending offer prices.
const Entries & operator[](const Offers &) const
List of ascending offer prices.
const Item * ConstIterator
Aliases constant iterator type.
void throwMbpBookRedepthFailure(Depth newDepth, Depth maxDepth)
Raises exception on book re-depth failure.
Book::Depth Depth
Book depth type.
const Entries & offers() const
List of ascending offer prices.
Serves as a factory for book of given type.
Tag class for accessing offers in templates.
#define ONIXS_CMEMDH_NAMESPACE_END