diff options
author | XhmikosR <xhmikosr@users.sourceforge.net> | 2011-02-12 11:35:52 +0000 |
---|---|---|
committer | XhmikosR <xhmikosr@users.sourceforge.net> | 2011-02-12 11:35:52 +0000 |
commit | e8fe28744afb3acb7f75960dd88569ac65b64a7d (patch) | |
tree | f3c3adb2ce2dd0762c2a70e78cb4fc3e76901690 /scintilla/lexlib | |
parent | ae7765d7a9b9032d403279236199995e0d5ef3f9 (diff) | |
download | notepad2-mod-e8fe28744afb3acb7f75960dd88569ac65b64a7d.zip notepad2-mod-e8fe28744afb3acb7f75960dd88569ac65b64a7d.tar.gz notepad2-mod-e8fe28744afb3acb7f75960dd88569ac65b64a7d.tar.bz2 |
add missing file from previous commit
git-svn-id: https://notepad2-mod.googlecode.com/svn/trunk@407 28bd50df-7adb-d945-0439-6e466c6a13cc
Diffstat (limited to 'scintilla/lexlib')
-rw-r--r-- | scintilla/lexlib/SparseState.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/scintilla/lexlib/SparseState.h b/scintilla/lexlib/SparseState.h new file mode 100644 index 0000000..ce92aeb --- /dev/null +++ b/scintilla/lexlib/SparseState.h @@ -0,0 +1,73 @@ +// Scintilla source code edit control
+/** @file SparseState.h
+ ** Hold lexer state that may change rarely.
+ ** This is often per-line state such as whether a particular type of section has been entered.
+ ** A state continues until it is changed.
+ **/
+// Copyright 2011 by Neil Hodgson <neilh@scintilla.org>
+// The License.txt file describes the conditions under which this software may be distributed.
+
+#ifndef SPARSESTATE_H
+#define SPARSESTATE_H
+
+#ifdef SCI_NAMESPACE
+namespace Scintilla {
+#endif
+
+template <typename T>
+class SparseState {
+ struct State {
+ int position;
+ T value;
+ State(int position_, T value_) : position(position_), value(value_) {
+ }
+ inline bool operator<(const State &other) const {
+ return position < other.position;
+ }
+ };
+ typedef std::vector<State> stateVector;
+ stateVector states;
+public:
+ void Set(int position, T value) {
+ Delete(position);
+ if ((states.size() == 0) || (value != states[states.size()-1].value)) {
+ states.push_back(State(position, value));
+ }
+ }
+ T ValueAt(int position) {
+ if (!states.size())
+ return T();
+ if (position < states[0].position)
+ return T();
+ State searchValue(position, T());
+ typename stateVector::iterator low =
+ lower_bound(states.begin(), states.end(), searchValue);
+ if (low == states.end()) {
+ return states[states.size()-1].value;
+ } else {
+ if (low->position > position) {
+ low--;
+ }
+ return low->value;
+ }
+ }
+ bool Delete(int position) {
+ State searchValue(position, T());
+ typename stateVector::iterator low =
+ lower_bound(states.begin(), states.end(), searchValue);
+ if (low != states.end()) {
+ states.erase(low, states.end());
+ return true;
+ }
+ return false;
+ }
+ size_t size() {
+ return states.size();
+ }
+};
+
+#ifdef SCI_NAMESPACE
+}
+#endif
+
+#endif
|