| 1 |
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the libabw project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
*/ |
| 9 |
|
| 10 |
#ifndef __ABWXMLHELPER_H__ |
| 11 |
#define __ABWXMLHELPER_H__ |
| 12 |
|
| 13 |
#include <memory> |
| 14 |
|
| 15 |
#include <librevenge-stream/librevenge-stream.h> |
| 16 |
|
| 17 |
#include <libxml/xmlreader.h> |
| 18 |
#include <libxml/xmlstring.h> |
| 19 |
|
| 20 |
namespace libabw |
| 21 |
{ |
| 22 |
|
| 23 |
// An exception-safe wrapper around xmlChar * |
| 24 |
class ABWXMLString |
| 25 |
{ |
| 26 |
public: |
| 27 |
ABWXMLString(xmlChar *xml); |
| 28 |
|
| 29 |
const xmlChar *get() const; |
| 30 |
|
| 31 |
operator const char *() const; |
| 32 |
|
| 33 |
private: |
| 34 |
std::shared_ptr<xmlChar> m_xml; |
| 35 |
}; |
| 36 |
|
| 37 |
class ABWXMLProgressWatcher |
| 38 |
{ |
| 39 |
ABWXMLProgressWatcher(const ABWXMLProgressWatcher &) = delete; |
| 40 |
ABWXMLProgressWatcher &operator=(const ABWXMLProgressWatcher &) = delete; |
| 41 |
|
| 42 |
public: |
| 43 |
ABWXMLProgressWatcher(); |
| 44 |
|
| 45 |
void setReader(xmlTextReaderPtr reader); |
| 46 |
|
| 47 |
bool isStuck() const; |
| 48 |
void signalError(); |
| 49 |
|
| 50 |
private: |
| 51 |
xmlTextReaderPtr m_reader; |
| 52 |
int m_line; |
| 53 |
int m_col; |
| 54 |
bool m_wasError; |
| 55 |
bool m_isStuck; |
| 56 |
}; |
| 57 |
|
| 58 |
// create an xmlTextReader pointer from a librevenge::RVNGInputStream pointer |
| 59 |
std::unique_ptr<xmlTextReader, void(*)(xmlTextReaderPtr)> xmlReaderForStream(librevenge::RVNGInputStream *input, ABWXMLProgressWatcher *watcher = nullptr); |
| 60 |
|
| 61 |
} // namespace libabw |
| 62 |
|
| 63 |
#endif // __ABWXMLHELPER_H__ |
| 64 |
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */ |