aboutsummaryrefslogtreecommitdiff
path: root/src/ClientPattern.hh
diff options
context:
space:
mode:
authorrathnor <rathnor>2003-06-12 15:12:19 (GMT)
committerrathnor <rathnor>2003-06-12 15:12:19 (GMT)
commite139cbb0283f7480fc26c58dc3f8a48e69011eab (patch)
tree2058a848943cb008dfe17270ad49853747212481 /src/ClientPattern.hh
parent94f1c164161e8faaf064d8b7cdfe36c9ca978055 (diff)
downloadfluxbox_pavel-e139cbb0283f7480fc26c58dc3f8a48e69011eab.zip
fluxbox_pavel-e139cbb0283f7480fc26c58dc3f8a48e69011eab.tar.bz2
add regular expression support in remember capabilities
see ChangeLog for details
Diffstat (limited to 'src/ClientPattern.hh')
-rw-r--r--src/ClientPattern.hh99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/ClientPattern.hh b/src/ClientPattern.hh
new file mode 100644
index 0000000..00a3127
--- /dev/null
+++ b/src/ClientPattern.hh
@@ -0,0 +1,99 @@
1// ClientPattern.hh for Fluxbox Window Manager
2// Copyright (c) 2002 Xavier Brouckaert
3// Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
4// and Simon Bowden (rathnor at users.sourceforge.net)
5//
6// Permission is hereby granted, free of charge, to any person obtaining a
7// copy of this software and associated documentation files (the "Software"),
8// to deal in the Software without restriction, including without limitation
9// the rights to use, copy, modify, merge, publish, distribute, sublicense,
10// and/or sell copies of the Software, and to permit persons to whom the
11// Software is furnished to do so, subject to the following conditions:
12//
13// The above copyright notice and this permission notice shall be included in
14// all copies or substantial portions of the Software.
15//
16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22// DEALINGS IN THE SOFTWARE.
23
24// $Id: ClientPattern.hh,v 1.1 2003/06/12 15:12:19 rathnor Exp $
25
26#ifndef CLIENTPATTERN_HH
27#define CLIENTPATTERN_HH
28
29#include "RegExp.hh"
30
31#include <string>
32#include <list>
33
34class WinClient;
35
36/**
37 * This class represents a "pattern" that we can match against a
38 * Window based on various properties.
39 */
40class ClientPattern {
41public:
42 ClientPattern();
43 // create the pattern from the given string as it would appear in the
44 // apps file. the bool value returns the character at which
45 // there was a parse problem, or -1.
46 explicit ClientPattern(const char * str);
47
48 ~ClientPattern();
49
50 // return a string representation of this pattern
51 std::string toString() const;
52
53 enum WinProperty { TITLE, CLASS, NAME };
54
55 // does this client match this pattern?
56 bool match(const WinClient &win) const;
57
58 // add an expression to match against
59 // The first argument is a regular expression, the second is the member
60 // function that we wish to match against.
61 // returns false if the regexp wasn't valid
62 bool addTerm(const std::string &str, WinProperty prop);
63
64 inline void addMatch() { ++m_nummatches; }
65 inline void delMatch() { --m_nummatches; }
66
67 inline bool operator == (const WinClient &win) const {
68 return match(win);
69 }
70
71 // if there are no terms, then there is assumed to be an error
72 // the column of the error is stored in m_matchlimit
73 inline int error() { return (m_terms.empty())?m_matchlimit:0; }
74
75 std::string getProperty(WinProperty prop, const WinClient &winclient) const;
76
77private:
78 // This is the type of the actual pattern we want to match against
79 // We have a "term" in the whole expression which is the full pattern
80 // we also need to keep track of the uncompiled regular expression
81 // for final output
82
83 struct Term {
84 Term(const std::string &regstr, bool full_match) :regexp(regstr, full_match){};
85 std::string orig;
86 RegExp regexp;
87 WinProperty prop;
88 };
89
90 // our pattern is made up of a sequence of terms
91 // currently we "and" them all
92 typedef std::list<Term *> Terms;
93
94 Terms m_terms;
95
96 int m_matchlimit, m_nummatches;
97};
98
99#endif // CLIENTPATTERN_HH