00001 // 00002 // Author: Lorenzo Bettini <http://www.lorenzobettini.it>, (C) 2004-2008 00003 // 00004 // Copyright: See COPYING file that comes with this distribution 00005 // 00006 00007 #ifndef HIGHLIGHTSTATE_H_ 00008 #define HIGHLIGHTSTATE_H_ 00009 00010 #include <deque> 00011 #include <vector> 00012 #include <string> 00013 #include <boost/shared_ptr.hpp> 00014 00015 namespace srchilite { 00016 00017 class HighlightRule; 00018 class HighlightToken; 00019 class MatchingParameters; 00020 00029 typedef boost::shared_ptr<HighlightRule> HighlightRulePtr; 00030 00032 typedef std::deque<HighlightRulePtr> RuleList; 00033 00036 typedef std::vector<std::string> ReplacementList; 00037 00038 class HighlightState; 00039 00041 typedef boost::shared_ptr<HighlightState> HighlightStatePtr; 00042 00047 class HighlightState { 00049 static unsigned int global_id; 00050 00052 const unsigned int id; 00053 00057 std::string defaultElement; 00058 00060 RuleList ruleList; 00061 00063 bool needsReferenceReplacement; 00064 00069 HighlightStatePtr originalState; 00070 00071 public: 00075 HighlightState(const std::string &e = "normal"); 00076 ~HighlightState(); 00077 00082 void addRule(HighlightRulePtr rule); 00083 00091 HighlightRulePtr replaceRule(RuleList::size_type index, 00092 HighlightRulePtr rule); 00093 00094 unsigned int getId() const { 00095 return id; 00096 } 00097 const RuleList &getRuleList() const { 00098 return ruleList; 00099 } 00100 00101 const std::string &getDefaultElement() const { 00102 return defaultElement; 00103 } 00104 void setDefaultElement(const std::string &e) { 00105 defaultElement = e; 00106 } 00107 00116 bool findBestMatch(const std::string &s, HighlightToken &token, 00117 const MatchingParameters ¶ms) const; 00118 00128 bool findBestMatch(std::string::const_iterator start, 00129 std::string::const_iterator end, HighlightToken &token, 00130 const MatchingParameters ¶ms) const; 00131 00140 static bool betterThan(const HighlightToken &t1, const HighlightToken &t2); 00141 00149 void replaceReferences(const ReplacementList &rep); 00150 00151 bool getNeedsReferenceReplacement() const { 00152 return needsReferenceReplacement; 00153 } 00154 00155 void setNeedsReferenceReplacement(bool b = true) { 00156 needsReferenceReplacement = b; 00157 } 00158 00159 HighlightStatePtr getOriginalState() const { 00160 return originalState; 00161 } 00162 00163 void setOriginalState(HighlightStatePtr orig) { 00164 originalState = orig; 00165 } 00166 00167 }; 00168 00169 } 00170 00171 #endif /*HIGHLIGHTSTATE_H_*/
1.5.6