Source-highlight Library
/home/bettini/work/source-highlight/src-highlite/lib/srchilite/highlightstate.h
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 struct HighlightToken;
00019 struct 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");
00081     HighlightState(const HighlightState &copy);
00082     ~HighlightState();
00083 
00088     void addRule(HighlightRulePtr rule);
00089 
00097     HighlightRulePtr replaceRule(RuleList::size_type index,
00098             HighlightRulePtr rule);
00099 
00100     unsigned int getId() const {
00101         return id;
00102     }
00103     const RuleList &getRuleList() const {
00104         return ruleList;
00105     }
00106 
00107     const std::string &getDefaultElement() const {
00108         return defaultElement;
00109     }
00110     void setDefaultElement(const std::string &e) {
00111         defaultElement = e;
00112     }
00113 
00122     bool findBestMatch(const std::string &s, HighlightToken &token,
00123             const MatchingParameters &params) const;
00124 
00134     bool findBestMatch(std::string::const_iterator start,
00135             std::string::const_iterator end, HighlightToken &token,
00136             const MatchingParameters &params) const;
00137 
00146     static bool betterThan(const HighlightToken &t1, const HighlightToken &t2);
00147 
00155     void replaceReferences(const ReplacementList &rep);
00156 
00157     bool getNeedsReferenceReplacement() const {
00158         return needsReferenceReplacement;
00159     }
00160 
00161     void setNeedsReferenceReplacement(bool b = true) {
00162         needsReferenceReplacement = b;
00163     }
00164 
00165     HighlightStatePtr getOriginalState() const {
00166         return originalState;
00167     }
00168 
00169     void setOriginalState(HighlightStatePtr orig) {
00170         originalState = orig;
00171     }
00172 
00173 };
00174 
00175 }
00176 
00177 #endif /*HIGHLIGHTSTATE_H_*/