File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -99,7 +99,9 @@ namespace classdesc
99
99
public:
100
100
string schema;
101
101
bool prettyPrint; // / if true, the layout XML in more human friendly form
102
-
102
+ volatile bool abort=false ; // / set to true to cancel packing from another thread
103
+ struct PackAborted : public std ::exception {};
104
+
103
105
xml_pack_t (std::ostream& o, const string& schema=" " ):
104
106
o (&o), taglevel(0 ), schema(schema), prettyPrint(false ) {}
105
107
@@ -142,6 +144,7 @@ namespace classdesc
142
144
template <class T >
143
145
void pack (const string& d, const T&x)
144
146
{
147
+ if (abort) throw PackAborted ();
145
148
std::string tag=tail (d);
146
149
pretty (d);
147
150
*o << " <" <<tag<<" >" ;
@@ -155,6 +158,7 @@ namespace classdesc
155
158
*/
156
159
template <class T >
157
160
void pack_notag (const string& d, const T&x) {
161
+ if (abort) throw PackAborted ();
158
162
*o<<x;
159
163
if (!*o) throw std::runtime_error (" failed to serialise" );
160
164
}
@@ -192,7 +196,7 @@ namespace classdesc
192
196
inline void xml_pack (xml_pack_t & x,const string& d, std::string& a)
193
197
{
194
198
std::string tmp;
195
- for (std::string::size_type i=0 ; i<a.length (); i++) tmp+=classdesc::xml_quote (a[i]);
199
+ for (std::string::size_type i=0 ; i<a.length () && !x. abort ; i++) tmp+=classdesc::xml_quote (a[i]);
196
200
x.pack (d,tmp);
197
201
}
198
202
You can’t perform that action at this time.
0 commit comments