Boost logo

Boost Users :

Subject: [Boost-users] ASIO async_read_until...
From: Etienne Philip Pretorius (icewolfhunter_at_[hidden])
Date: 2009-07-23 14:27:16


Hello list,

I have a set of inherited classes as follows:

client [parent of]
stream [parent of]
parser [parent of]
grammar

When I perform the following call:

boost::asio::async_read_until(
    socket_,
        streambuf_,
        stream::parse(),
        boost::bind(
            &client::handle_read,
                this,
                boost::asio::placeholders::error,
                boost::asio::placeholders::bytes_transferred
        )
);

The xml::parser::operator() call for the match condition is a copy of
the classes:

parser [parent of]
grammar

I need to know if someone could suggest a client way for me to use
(shared) pointers to the classes so that the xml::parser::operator() can
keep its state changes over successive calls for async_read_until.

Currently I have this (hack) for the issue, but hope there is a cleaner
approach:

        class parser
            : public grammar {
        public:
            parser(
            ) : parser_(//stupid hack...
                this
            ) {
            };

            virtual ~parser(
            ) {
            };

            parser& parse(
            ) {
                return *this;
            };

            template <typename T>
            std::pair<T, bool> operator()(
                T begin,
                T end
            ) {
        ...[state changes based on content matches]...
            };
        private:
            parser* parser_;//needed for stupid hack...
        protected:
        };

When I call stream::parse() it returns the parser object, at which
async_read_until makes a copy of the parser object and its base classes.
When parser::operator() is called by async_read_until, I then apply all
state changes via parser* parser_ to the original class.

Any suggestions are welcome.

Etienne.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net