Changed scroll size of PackageList;

Added 'collapse' option for card notes;
Made variant of  DECLARE_TYPEOF for maps (two template arguments).

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@202 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-02-08 22:15:11 +00:00
parent 73a2f61e68
commit e83c00c05a
35 changed files with 292 additions and 81 deletions
+106
View File
@@ -7,6 +7,10 @@
// ----------------------------------------------------------------------------- : Includes
#include <data/keyword.hpp>
#include <util/tagged_string.hpp>
class KeywordTrie;
DECLARE_TYPEOF2(map<Char, KeywordTrie*>);
// ----------------------------------------------------------------------------- : Reflection
@@ -57,4 +61,106 @@ IMPLEMENT_REFLECTION(Keyword) {
REFLECT(mode);
}
// ----------------------------------------------------------------------------- : KeywordTrie
/// A node in a trie to match keywords
class KeywordTrie {
public:
KeywordTrie();
~KeywordTrie();
map<Char, KeywordTrie*> children; ///< children after a given character (owned)
KeywordTrie* on_any_star; ///< children on /.*/ (owned)
Keyword* finished; ///< keywords that end in this node
/// Insert nodes representing the given string
/** return the node where the evaluation will be after matching the string */
KeywordTrie* insert(const String& match);
/// Insert nodes representing the regex /.*/
/** return the node where the evaluation will be after matching that regex */
KeywordTrie* insertAnyStar();
};
KeywordTrie::KeywordTrie()
: on_any_star(nullptr)
, finished(nullptr)
{}
KeywordTrie::~KeywordTrie() {
FOR_EACH(c, children) {
delete c.second;
}
delete on_any_star;
}
KeywordTrie* KeywordTrie::insert(const String& match) {
KeywordTrie* cur = this;
FOR_EACH_CONST(c, match) {
KeywordTrie*& child = cur->children[c];
if (!child) child = new KeywordTrie;
cur = child;
}
return cur;
}
KeywordTrie* KeywordTrie::insertAnyStar() {
if (!on_any_star) on_any_star = new KeywordTrie;
return on_any_star;
}
// ----------------------------------------------------------------------------- : KeywordMatcher
/// State of the matching algorithm
class KeywordMatcher {
public:
KeywordMatcher(const String& s);
private:
String str;
size_t pos;
};
// ----------------------------------------------------------------------------- : KeywordDatabase
/// A database of keywords to allow for fast matching
/** NOTE: keywords may not be altered after they are added to the database,
* The database should be rebuild.
*/
class KeywordDatabase {
public:
/// Add a keyword to be matched
void addKeyword(const Keyword&);
/// Find the first matching keyword, return its position
size_t firstMatch(const String& input, Keyword* keyword);
private:
KeywordTrie root;
};
void KeywordDatabase::addKeyword(const Keyword& kw) {
// TODO
}
// ----------------------------------------------------------------------------- : Using keywords
KeywordDatabaseP new_keyword_database() {
return new_shared<KeywordDatabase>();
}
void add_keyword(KeywordDatabase& db, const Keyword& kw) {
db.addKeyword(kw);
}
String expand_keywords(const KeywordDatabase& db, const String& text) {
// 1. Remove all old reminder texts
String s = remove_tag_contents(text, _("<atom-keyword>"));
// 2. Process keywords
// TODO
return s;
}