1 #ifndef IMAGE_IO_XML_XML_ACTION_H_ // NOLINT 2 #define IMAGE_IO_XML_XML_ACTION_H_ // NOLINT 3 4 #include <functional> 5 6 #include "image_io/base/data_match_result.h" 7 #include "image_io/xml/xml_handler_context.h" 8 9 namespace photos_editing_formats { 10 namespace image_io { 11 12 class XmlActionContext; 13 class XmlTerminal; 14 15 /// The definition for an action function associated with an XmlTerminal. 16 /// If the action does not need to change the result of the terminal, it can 17 /// simply return the value from XmlActionContext::GetResult(). 18 using XmlAction = 19 std::function<DataMatchResult(const XmlActionContext& context)>; 20 21 /// The data context passed from an XmlTerminal to its action function. 22 class XmlActionContext : public XmlHandlerContext { 23 public: XmlActionContext(const XmlHandlerContext & context,XmlTerminal * terminal,const DataMatchResult & result)24 XmlActionContext(const XmlHandlerContext& context, XmlTerminal* terminal, 25 const DataMatchResult& result) 26 : XmlHandlerContext(context), terminal_(terminal), result_(result) {} XmlActionContext(size_t location,const DataRange & range,const DataSegment & segment,const DataLineMap & data_line_map,XmlHandler * handler,XmlTerminal * terminal,const DataMatchResult & result)27 XmlActionContext(size_t location, const DataRange& range, 28 const DataSegment& segment, const DataLineMap& data_line_map, 29 XmlHandler* handler, XmlTerminal* terminal, 30 const DataMatchResult& result) 31 : XmlHandlerContext(location, range, segment, data_line_map, handler), 32 terminal_(terminal), 33 result_(result) {} 34 35 /// @return The terminal associated with the context. GetTerminal()36 XmlTerminal* GetTerminal() const { return terminal_; } 37 38 /// @return The result associated with the constext. GetResult()39 const DataMatchResult& GetResult() const { return result_; } 40 41 /// @param bytes_consumed The value to set in the returned result. 42 /// @return A result based on the context's action, but with its bytes 43 /// consumed value set to the given value. GetResultWithBytesConsumed(size_t bytes_consumed)44 DataMatchResult GetResultWithBytesConsumed(size_t bytes_consumed) const { 45 auto result = result_; 46 return result.SetBytesConsumed(bytes_consumed); 47 } 48 49 private: 50 XmlTerminal* terminal_; 51 DataMatchResult result_; 52 }; 53 54 } // namespace image_io 55 } // namespace photos_editing_formats 56 57 #endif // IMAGE_IO_XML_XML_ACTION_H_ // NOLINT 58