mercredi 4 septembre 2019

How do constructors work with type alias code?

I was looking at some code in a github repo, and I was wondering if anyone could explain how the following line works.

using order_finder_t   = Order (OrderBook::*)(price_t, order_id_t const &);

Some of the other parts of the code referenced are

    struct OrderBook
    {
        //public methods
        //processNewBuyOrder
        //processNewSelOrder
        //processCancel
        //processMod
        //printBook
        //ctors/assg/dtor w/ object semantics

        //processing a new order involves trying to match it against the current book
        //and then giving it an order finder and sticking it in the book if
        //there's anything left after the attempt to match
        //book orders and their find information are removed if they are fully matched
        //during the match process

        //cancelling causes no match, so we just retreive the order and throw it away
        //modifies, b/c they can switch sides and match, are done as a cancel, but then
        //we alter the retrieve order, and push it back into processNew...

        using price_t          = uint64_t;
        using order_vector_t   = std::vector<Order>;
        using order_id_t       = std::string;

        using bid_book_t       = std::map<price_t, order_vector_t, std::greater<price_t>>;
        using ask_book_t       = std::map<price_t, order_vector_t>;
        using order_finder_t   = Order (OrderBook::*)(price_t, order_id_t const &);
        using order_map_t      = std::map<order_id_t, std::pair<order_finder_t, price_t>>;

    OrderBook():mBids(), mAsks(), mOrderFinders(){}
        ...
        .
        .
        };


struct Order
{
    std::string Side;
    std::string TimeInForce;
    uint64_t    Price;
    uint64_t    Quantity;
    std::string ID;

    //default object semantics w/ a ctor for message tokens
    explicit Order(message_tokens_t const & messageTokens)
    :Side        (messageTokens.at(0)),
    TimeInForce (messageTokens.at(1)),
    Price       (-1),
    Quantity    (-1),
    ID          (messageTokens.at(4))
    {
        std::stringstream(messageTokens.at(2)) >> Price;
        std::stringstream(messageTokens.at(3)) >> Quantity;
    }
    Order():Side(), TimeInForce(), Price(-1), Quantity(-1), ID(){}
    DEFAULT_OBJECT_SEMANTICS(Order)
    ~Order(){}
};

I have never seen type aliasing used like this and am struggling to interpret what exactly is going on in that code.

Any help would be appreciated!

Aucun commentaire:

Enregistrer un commentaire