aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Document.h
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2021-08-22 22:14:19 +1000
committerNeil <nyamatongwe@gmail.com>2021-08-22 22:14:19 +1000
commit6f709917a1134aaf55fc83d8a9f18a30b50efd89 (patch)
tree303457f17677c8c92d484b4485e1ec4cfc2499c8 /src/Document.h
parent557bea24106e3868d2b5c5c4b066575c5236538a (diff)
downloadscintilla-mirror-6f709917a1134aaf55fc83d8a9f18a30b50efd89.tar.gz
Encapsulate an ILexer5* in LexerInstance class to simplify client code.
Diffstat (limited to 'src/Document.h')
-rw-r--r--src/Document.h36
1 files changed, 28 insertions, 8 deletions
diff --git a/src/Document.h b/src/Document.h
index 7984ad018..e2962b4a3 100644
--- a/src/Document.h
+++ b/src/Document.h
@@ -164,21 +164,41 @@ public:
bool isEnabled;
};
+struct LexerReleaser {
+ // Called by unique_ptr to destroy/free the Resource
+ void operator()(Scintilla::ILexer5 *pLexer) noexcept {
+ if (pLexer) {
+ try {
+ pLexer->Release();
+ } catch (...) {
+ // ILexer5::Release must not throw, ignore if it does.
+ }
+ }
+ }
+};
+
+using LexerInstance = std::unique_ptr<Scintilla::ILexer5, LexerReleaser>;
+
+// LexInterface defines the interface to ILexer used in Document.
+// The LexState subclass is actually created and that is used within ScintillaBase
+// to provide more methods that are exposed through Scintilla's external API.
class LexInterface {
protected:
Document *pdoc;
- Scintilla::ILexer5 *instance;
+ LexerInstance instance;
bool performingStyle; ///< Prevent reentrance
public:
- explicit LexInterface(Document *pdoc_) noexcept : pdoc(pdoc_), instance(nullptr), performingStyle(false) {
- }
- virtual ~LexInterface() {
- }
+ explicit LexInterface(Document *pdoc_) noexcept;
+ // Deleted so LexInterface objects can not be copied.
+ LexInterface(const LexInterface &) = delete;
+ LexInterface(LexInterface &&) = delete;
+ LexInterface &operator=(const LexInterface &) = delete;
+ LexInterface &operator=(LexInterface &&) = delete;
+ virtual ~LexInterface() noexcept;
+ void SetInstance(ILexer5 *instance_);
void Colourise(Sci::Position start, Sci::Position end);
virtual Scintilla::LineEndType LineEndTypesSupported();
- bool UseContainerLexing() const noexcept {
- return instance == nullptr;
- }
+ bool UseContainerLexing() const noexcept;
};
struct RegexError : public std::runtime_error {