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