Updated v2_0_cpp_visitor (markdown)

Takatoshi Kondo
2016-05-26 21:31:51 +09:00
parent dd348978c1
commit f55e7cca02
+13 -2
@@ -91,6 +91,7 @@ struct null_visitor {
}
void insufficient_bytes(size_t /*parsed_offset*/, size_t /*error_offset*/) {
}
bool referenced() const; // Only when you want to use the visitor with a parser
};
```
@@ -208,7 +209,7 @@ They are similar to unpack APIs.
When you call a parse function, then the parse function callback the visitor that you passed. If parsing process is successfully finished, then the parse function returns true, otherwise returns false. If the visitor's visit function returns false, then the parse function returns false.
You can use visitors with stream interface like an unpacker.
You can use visitors with stream interface like an `unpacker`.
```C++
template <typename VisitorHolder, typename ReferencedBufferHook>
@@ -217,6 +218,16 @@ class parser
`VisitorHolder` need to have a function named `visitor()` that returns a reference of the visitor object that satisfies the visitor concept.
`ReferencedBufferHook` need to have an `operator()(char *)`. The operator() is called with the current buffer pointer only when the all following conditions are satisfied:
1. Called `parser::reserve_buffer(std::size_t)`.
2. The current buffer doesn't have sufficient size and then new buffer is allocated.
3. The current buffer is referenced by the visitor. In this case, `visitor::referenced()` should return true.
If `visitor::referenced() returns true, the `parser` doesn't free the current buffer but call `ReferencedBufferHook`. So you can get a chance to set something cleanup function for the current buffer.
See [unpacker's memory management mechanism](v2_0_cpp_unpacker#msgpack-controls-a-buffer).
`parser` has the same public member functions as unpacker except `bool next()`.
`unpacker` has the following member functions named `next`:
@@ -231,4 +242,4 @@ class parser
bool next();
```
When you call `next()` then parse one MessagePack formatted data.
When you call `next()` then parse one MessagePack formatted data. So visitor's visit functions are called. If the parsing process successfully finished, then returns true, otherwise returns false.