From b05f27d33a91a1739bb1af5923f064364298fea3 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Fri, 13 Jun 2003 12:02:00 +0000 Subject: minor cleaning --- src/ClientPattern.cc | 30 ++++++++++++++---------------- src/ClientPattern.hh | 51 +++++++++++++++++++++++++++++---------------------- 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/src/ClientPattern.cc b/src/ClientPattern.cc index 7ad3a54..76151aa 100644 --- a/src/ClientPattern.cc +++ b/src/ClientPattern.cc @@ -20,16 +20,16 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ClientPattern.cc,v 1.1 2003/06/12 15:12:19 rathnor Exp $ +// $Id: ClientPattern.cc,v 1.2 2003/06/13 12:01:06 fluxgen Exp $ #include "ClientPattern.hh" #include "RegExp.hh" #include "StringUtil.hh" #include "WinClient.hh" -//use GNU extensions -#ifndef _GNU_SOURCE -#define _GNU_SOURCE +// use GNU extensions +#ifndef _GNU_SOURCE +#define _GNU_SOURCE #endif // _GNU_SOURCE @@ -41,10 +41,6 @@ using namespace std; -/******************************************************** - * ClientPattern * - ***********/ - ClientPattern::ClientPattern(): m_matchlimit(0), m_nummatches(0) {} @@ -161,17 +157,19 @@ std::string ClientPattern::toString() const { Terms::const_iterator it_end = m_terms.end(); for (; it != it_end; ++it) { pat.append(" ("); - if ((*it)->prop == NAME) { + + switch ((*it)->prop) { + case NAME: // do nothing -> this is the default - } else if ((*it)->prop == CLASS) { + break; + case CLASS: pat.append("class="); - } else if ((*it)->prop == TITLE) { + break; + case TITLE: pat.append("title="); - } else { -#ifdef DEBUG - cerr<<"WARNING: unknown window property, can't save properly"<orig); pat.append(")"); } @@ -228,8 +226,8 @@ std::string ClientPattern::getProperty(WinProperty prop, const WinClient &client return client.getWMClassClass(); break; case NAME: - default: return client.getWMClassName(); break; } + return client.getWMClassName(); } diff --git a/src/ClientPattern.hh b/src/ClientPattern.hh index 00a3127..7e89511 100644 --- a/src/ClientPattern.hh +++ b/src/ClientPattern.hh @@ -21,12 +21,13 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: ClientPattern.hh,v 1.1 2003/06/12 15:12:19 rathnor Exp $ +// $Id: ClientPattern.hh,v 1.2 2003/06/13 12:02:00 fluxgen Exp $ #ifndef CLIENTPATTERN_HH #define CLIENTPATTERN_HH #include "RegExp.hh" +#include "NotCopyable.hh" #include #include @@ -37,28 +38,32 @@ class WinClient; * This class represents a "pattern" that we can match against a * Window based on various properties. */ -class ClientPattern { +class ClientPattern:private FbTk::NotCopyable { public: ClientPattern(); - // create the pattern from the given string as it would appear in the - // apps file. the bool value returns the character at which - // there was a parse problem, or -1. + /** + * Create the pattern from the given string as it would appear in the + * apps file. the bool value returns the character at which + * there was a parse problem, or -1. + */ explicit ClientPattern(const char * str); ~ClientPattern(); - // return a string representation of this pattern + /// @return a string representation of this pattern std::string toString() const; enum WinProperty { TITLE, CLASS, NAME }; - // does this client match this pattern? + /// Does this client match this pattern? bool match(const WinClient &win) const; - // add an expression to match against - // The first argument is a regular expression, the second is the member - // function that we wish to match against. - // returns false if the regexp wasn't valid + /** + * Add an expression to match against + * @param str is a regular expression + * @param prop is the member function that we wish to match against + * @return false if the regexp wasn't valid + */ bool addTerm(const std::string &str, WinProperty prop); inline void addMatch() { ++m_nummatches; } @@ -68,18 +73,21 @@ public: return match(win); } - // if there are no terms, then there is assumed to be an error - // the column of the error is stored in m_matchlimit - inline int error() { return (m_terms.empty())?m_matchlimit:0; } + /** + * If there are no terms, then there is assumed to be an error + * the column of the error is stored in m_matchlimit + */ + inline int error() const { return m_terms.empty() ? m_matchlimit : 0; } std::string getProperty(WinProperty prop, const WinClient &winclient) const; private: - // This is the type of the actual pattern we want to match against - // We have a "term" in the whole expression which is the full pattern - // we also need to keep track of the uncompiled regular expression - // for final output - + /** + * This is the type of the actual pattern we want to match against + * We have a "term" in the whole expression which is the full pattern + * we also need to keep track of the uncompiled regular expression + * for final output + */ struct Term { Term(const std::string ®str, bool full_match) :regexp(regstr, full_match){}; std::string orig; @@ -87,11 +95,10 @@ private: WinProperty prop; }; - // our pattern is made up of a sequence of terms - // currently we "and" them all + typedef std::list Terms; - Terms m_terms; + Terms m_terms; ///< our pattern is made up of a sequence of terms currently we "and" them all int m_matchlimit, m_nummatches; }; -- cgit v0.11.2