MySQL 8.0.32
Source Code Documentation
xid_extract.h
Go to the documentation of this file.
1/* Copyright (c) 2022, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef XA_XID_EXTRACTOR_INCLUDED
24#define XA_XID_EXTRACTOR_INCLUDED
25
26#include <iostream>
27#include <string>
28
29#include "sql/xa.h"
30
31namespace xa {
32/**
33 @class XID_extractor
34
35 Processes a string and extracts XIDs of the form X'...',X'...',0-9.
36
37 Extracted XIDs are stored internally and are iterable through either
38 iterator or direct access semantics:
39
40 XID_extractor tokenizer;
41 tokenizer.extract("XA COMMIT X'1234',X'123456',1;"
42 "XA ROLLBACK X'1234',X'123456',1;");
43 for (auto xid : tokenizer)
44 std::cout << xid << std::endl << std::flush;
45
46 if (tokenizer.size() != 0)
47 std::cout << tokenizer[0] << std::endl << std::flush
48
49 At each extraction, the internal list of extracted XIDs is cleared.
50 */
52 public:
53 using xid_list = std::vector<xid_t>;
54
55 XID_extractor() = default;
56 /**
57 Constructs a new instance and tries to extract XIDs from the given
58 string. The extracted XID will be stored internally and iterable either
59 through iterator or direct access semantics.
60
61 @param source The string containing XID to be extracted.
62 @param max_extractions The maximum number of XIDs to be extracted from
63 the string.
64 */
65 XID_extractor(std::string const &source,
66 size_t max_extractions = std::numeric_limits<size_t>::max());
67 virtual ~XID_extractor() = default;
68
69 /**
70 Processes the given string and extracts well-formed XIDs.
71
72 The extracted XID will be stored internally and iterable either through
73 iterator or direct access semantics. Per each invocatian of this
74 method, the internal list of extracted XIDs is cleared.
75
76 @param source The string containing XID to be extracted.
77 @param max_extractions The maximum number of XIDs to be extracted from
78 the string.
79
80 @return the number of XIDs that were actually extracted.
81 */
82 size_t extract(std::string const &source,
83 size_t max_extractions = std::numeric_limits<size_t>::max());
84 /**
85 Retrieves an iterator pointing to the beginning of the extracted XID
86 list.
87
88 @return an iterator to the beginning of the XID list.
89 */
90 xid_list::iterator begin();
91 /**
92 Retrieves an iterator pointing to the end of the extracted XID list.
93
94 @return an iterator to the end of the XID list.
95 */
96 xid_list::iterator end();
97 /**
98 Retrieves the size of the extracted XID list.
99
100 @return an the size of the XID list.
101 */
102 size_t size();
103 /**
104 Retrieves the nth XID in the list of extracted XIDs.
105
106 @param idx The index of the XID to be retrieved
107
108 @return a reference to the XID at index idx.
109 */
110 xid_t &operator[](size_t idx);
111
112 private:
113 /** List of extracted XIDs. */
115};
116} // namespace xa
117#endif // XA_XID_EXTRACTOR_INCLUDED
Processes a string and extracts XIDs of the form X'...',X'...',0-9.
Definition: xid_extract.h:51
xid_t & operator[](size_t idx)
Retrieves the nth XID in the list of extracted XIDs.
Definition: xid_extract.cc:96
size_t size()
Retrieves the size of the extracted XID list.
Definition: xid_extract.cc:94
std::vector< xid_t > xid_list
Definition: xid_extract.h:53
virtual ~XID_extractor()=default
xid_list::iterator begin()
Retrieves an iterator pointing to the beginning of the extracted XID list.
Definition: xid_extract.cc:86
size_t extract(std::string const &source, size_t max_extractions=std::numeric_limits< size_t >::max())
Processes the given string and extracts well-formed XIDs.
Definition: xid_extract.cc:44
xid_list m_xids
List of extracted XIDs.
Definition: xid_extract.h:114
XID_extractor()=default
xid_list::iterator end()
Retrieves an iterator pointing to the end of the extracted XID list.
Definition: xid_extract.cc:90
Definition: recovery.h:38
repeated Source source
Definition: replication_asynchronous_connection_failover.proto:41
struct xid_t is binary compatible with the XID structure as in the X/Open CAE Specification,...
Definition: xa.h:82