aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-05-01 14:47:53 (GMT)
committerPavel Labath <pavelo@centrum.sk>2011-05-10 11:00:45 (GMT)
commit4b47675441b76620519b0204497686b09113daaa (patch)
treec3494c61a82b84418761000d5fc7fc5d12188204
parentfa15400cc24ddcfd6e361bd068ae1986b9f9e561 (diff)
downloadfluxbox_pavel-4b47675441b76620519b0204497686b09113daaa.zip
fluxbox_pavel-4b47675441b76620519b0204497686b09113daaa.tar.bz2
Make RefCount<> more sensible
the previous version of operator*() made no sense. E.g., it violated the invariant (*ptr).foo <=> ptr->foo. The dereferencing operator now returns a reference to the pointed-to object, rather than a pointer to it. I also added a bool conversion operator, which can be used in testing the NULL-ness of the pointer. Anyone wondering if that could be done in a simpler way is encouraged to read <http://www.artima.com/cppsource/safebool.html>. And, finally, I removed the mutable flag from the m_data member, since it does not need it.
-rw-r--r--src/CommandDialog.cc2
-rw-r--r--src/FbTk/LogicCommands.cc6
-rw-r--r--src/FbTk/LogicCommands.hh4
-rw-r--r--src/FbTk/MacroCommand.cc2
-rw-r--r--src/FbTk/MultiButtonMenuItem.cc2
-rw-r--r--src/FbTk/RefCount.hh8
-rw-r--r--src/FbTk/Timer.cc6
-rw-r--r--src/Keys.cc6
-rw-r--r--src/MenuCreator.cc2
-rw-r--r--src/Remember.cc8
-rw-r--r--src/ToolFactory.cc2
-rw-r--r--src/WorkspaceCmd.cc2
12 files changed, 27 insertions, 23 deletions
diff --git a/src/CommandDialog.cc b/src/CommandDialog.cc
index bef8a63..023c22f 100644
--- a/src/CommandDialog.cc
+++ b/src/CommandDialog.cc
@@ -51,7 +51,7 @@ void CommandDialog::exec(const std::string &text){
51 if (cmd.get()) 51 if (cmd.get())
52 cmd->execute(); 52 cmd->execute();
53 // post execute 53 // post execute
54 if (*m_postcommand != 0) 54 if (m_postcommand != 0)
55 m_postcommand->execute(); 55 m_postcommand->execute();
56} 56}
57 57
diff --git a/src/FbTk/LogicCommands.cc b/src/FbTk/LogicCommands.cc
index b3abe31..bda67f5 100644
--- a/src/FbTk/LogicCommands.cc
+++ b/src/FbTk/LogicCommands.cc
@@ -44,7 +44,7 @@ M *addCommands(M *macro, const string &args, bool trusted) {
44 std::vector<std::string>::iterator it = cmds.begin(), it_end = cmds.end(); 44 std::vector<std::string>::iterator it = cmds.begin(), it_end = cmds.end();
45 for (; it != it_end; ++it) { 45 for (; it != it_end; ++it) {
46 cmd = CommandParser<bool>::instance().parse(*it, trusted); 46 cmd = CommandParser<bool>::instance().parse(*it, trusted);
47 if (*cmd) 47 if (cmd)
48 macro->add(cmd); 48 macro->add(cmd);
49 } 49 }
50 50
@@ -91,13 +91,13 @@ Command<void> *IfCommand::parse(const std::string &command, const std::string &a
91 return 0; 91 return 0;
92 92
93 cond = CommandParser<bool>::instance().parse(cmds[0], trusted); 93 cond = CommandParser<bool>::instance().parse(cmds[0], trusted);
94 if (*cond == 0) 94 if (cond == 0)
95 return 0; 95 return 0;
96 96
97 t = CommandParser<void>::instance().parse(cmds[1], trusted); 97 t = CommandParser<void>::instance().parse(cmds[1], trusted);
98 if (cmds.size() >= 3) 98 if (cmds.size() >= 3)
99 f = CommandParser<void>::instance().parse(cmds[2], trusted); 99 f = CommandParser<void>::instance().parse(cmds[2], trusted);
100 if (*t == 0 && *f == 0) 100 if (t == 0 && f == 0)
101 return 0; 101 return 0;
102 102
103 return new IfCommand(cond, t, f); 103 return new IfCommand(cond, t, f);
diff --git a/src/FbTk/LogicCommands.hh b/src/FbTk/LogicCommands.hh
index 5e84473..c0cb938 100644
--- a/src/FbTk/LogicCommands.hh
+++ b/src/FbTk/LogicCommands.hh
@@ -38,9 +38,9 @@ public:
38 m_cond(cond), m_t(t), m_f(f) { } 38 m_cond(cond), m_t(t), m_f(f) { }
39 void execute() { 39 void execute() {
40 if (m_cond->execute()) { 40 if (m_cond->execute()) {
41 if (*m_t) m_t->execute(); 41 if (m_t) m_t->execute();
42 } else 42 } else
43 if (*m_f) m_f->execute(); 43 if (m_f) m_f->execute();
44 } 44 }
45 static Command<void> *parse(const std::string &cmd, const std::string &args, 45 static Command<void> *parse(const std::string &cmd, const std::string &args,
46 bool trusted); 46 bool trusted);
diff --git a/src/FbTk/MacroCommand.cc b/src/FbTk/MacroCommand.cc
index 0b7a6b8..e04d92a 100644
--- a/src/FbTk/MacroCommand.cc
+++ b/src/FbTk/MacroCommand.cc
@@ -42,7 +42,7 @@ M *addCommands(M *macro, const std::string &args, bool trusted) {
42 std::list<std::string>::iterator it = cmds.begin(), it_end = cmds.end(); 42 std::list<std::string>::iterator it = cmds.begin(), it_end = cmds.end();
43 for (; it != it_end; ++it) { 43 for (; it != it_end; ++it) {
44 cmd = CommandParser<void>::instance().parse(*it, trusted); 44 cmd = CommandParser<void>::instance().parse(*it, trusted);
45 if (*cmd) 45 if (cmd)
46 macro->add(cmd); 46 macro->add(cmd);
47 } 47 }
48 } 48 }
diff --git a/src/FbTk/MultiButtonMenuItem.cc b/src/FbTk/MultiButtonMenuItem.cc
index ed67c83..1b61a99 100644
--- a/src/FbTk/MultiButtonMenuItem.cc
+++ b/src/FbTk/MultiButtonMenuItem.cc
@@ -55,7 +55,7 @@ void MultiButtonMenuItem::click(int button, int time, unsigned int mods) {
55 if (button <= 0 || button > static_cast<signed>(buttons()) || buttons() == 0) 55 if (button <= 0 || button > static_cast<signed>(buttons()) || buttons() == 0)
56 return; 56 return;
57 57
58 if (*m_button_exe[button - 1] != 0) 58 if (m_button_exe[button - 1] != 0)
59 m_button_exe[button - 1]->execute(); 59 m_button_exe[button - 1]->execute();
60} 60}
61 61
diff --git a/src/FbTk/RefCount.hh b/src/FbTk/RefCount.hh
index 6d1b9b7..597f847 100644
--- a/src/FbTk/RefCount.hh
+++ b/src/FbTk/RefCount.hh
@@ -27,6 +27,8 @@ namespace FbTk {
27/// holds a pointer with reference counting, similar to std:auto_ptr 27/// holds a pointer with reference counting, similar to std:auto_ptr
28template <typename Pointer> 28template <typename Pointer>
29class RefCount { 29class RefCount {
30 typedef Pointer* RefCount::*bool_type;
31
30public: 32public:
31 RefCount(); 33 RefCount();
32 explicit RefCount(Pointer *p); 34 explicit RefCount(Pointer *p);
@@ -35,9 +37,11 @@ public:
35 ~RefCount(); 37 ~RefCount();
36 RefCount<Pointer> &operator = (const RefCount<Pointer> &copy); 38 RefCount<Pointer> &operator = (const RefCount<Pointer> &copy);
37 RefCount<Pointer> &operator = (Pointer *p); 39 RefCount<Pointer> &operator = (Pointer *p);
38 Pointer *operator * () const { return get(); } 40 Pointer &operator * () const { return *get(); }
39 Pointer *operator -> () const { return get(); } 41 Pointer *operator -> () const { return get(); }
40 Pointer *get() const { return m_data; } 42 Pointer *get() const { return m_data; }
43 /// conversion to "bool"
44 operator bool_type() const { return m_data ? &RefCount::m_data : 0; }
41 45
42private: 46private:
43 /// increase reference count 47 /// increase reference count
@@ -45,7 +49,7 @@ private:
45 /// decrease reference count 49 /// decrease reference count
46 void decRefCount(); 50 void decRefCount();
47 Pointer *m_data; ///< data holder 51 Pointer *m_data; ///< data holder
48 mutable unsigned int *m_refcount; ///< holds reference counting 52 unsigned int *m_refcount; ///< holds reference counting
49}; 53};
50 54
51// implementation 55// implementation
diff --git a/src/FbTk/Timer.cc b/src/FbTk/Timer.cc
index 60df968..cb9ac59 100644
--- a/src/FbTk/Timer.cc
+++ b/src/FbTk/Timer.cc
@@ -98,7 +98,7 @@ void Timer::start() {
98 gettimeofday(&m_start, 0); 98 gettimeofday(&m_start, 0);
99 99
100 // only add Timers that actually DO something 100 // only add Timers that actually DO something
101 if ((! m_timing || m_interval != 0) && *m_handler) { 101 if ((! m_timing || m_interval != 0) && m_handler) {
102 m_timing = true; 102 m_timing = true;
103 addTimer(this); //add us to the list 103 addTimer(this); //add us to the list
104 } 104 }
@@ -121,7 +121,7 @@ void Timer::makeEndTime(timeval &tm) const {
121 121
122 122
123void Timer::fireTimeout() { 123void Timer::fireTimeout() {
124 if (*m_handler) 124 if (m_handler)
125 m_handler->execute(); 125 m_handler->execute();
126} 126}
127 127
@@ -273,7 +273,7 @@ Command<void> *DelayedCmd::parse(const std::string &command,
273 return 0; 273 return 0;
274 274
275 RefCount<Command<void> > cmd(CommandParser<void>::instance().parse(cmd_str, trusted)); 275 RefCount<Command<void> > cmd(CommandParser<void>::instance().parse(cmd_str, trusted));
276 if (*cmd == 0) 276 if (cmd == 0)
277 return 0; 277 return 0;
278 278
279 int delay = 200000; 279 int delay = 200000;
diff --git a/src/Keys.cc b/src/Keys.cc
index d3b82e9..79c273b 100644
--- a/src/Keys.cc
+++ b/src/Keys.cc
@@ -487,7 +487,7 @@ bool Keys::addBinding(const string &linebuffer) {
487 first_new_key = new t_key(type, mod, key, context, 487 first_new_key = new t_key(type, mod, key, context,
488 isdouble); 488 isdouble);
489 current_key = first_new_key; 489 current_key = first_new_key;
490 } else if (*current_key->m_command) // already being used 490 } else if (current_key->m_command) // already being used
491 return false; 491 return false;
492 } else { 492 } else {
493 t_key *temp_key = new t_key(type, mod, key, context, 493 t_key *temp_key = new t_key(type, mod, key, context,
@@ -511,7 +511,7 @@ bool Keys::addBinding(const string &linebuffer) {
511 if (str) // +1 to skip ':' 511 if (str) // +1 to skip ':'
512 current_key->m_command = FbTk::CommandParser<void>::instance().parse(str + 1); 512 current_key->m_command = FbTk::CommandParser<void>::instance().parse(str + 1);
513 513
514 if (!str || *current_key->m_command == 0 || mod) { 514 if (!str || current_key->m_command == 0 || mod) {
515 delete first_new_key; 515 delete first_new_key;
516 return false; 516 return false;
517 } 517 }
@@ -572,7 +572,7 @@ bool Keys::doAction(int type, unsigned int mods, unsigned int key,
572 setKeyMode(next_key); 572 setKeyMode(next_key);
573 return true; 573 return true;
574 } 574 }
575 if (!temp_key || *temp_key->m_command == 0) { 575 if (!temp_key || temp_key->m_command == 0) {
576 if (type == KeyPress && 576 if (type == KeyPress &&
577 !FbTk::KeyUtil::instance().keycodeToModmask(key)) { 577 !FbTk::KeyUtil::instance().keycodeToModmask(key)) {
578 // if we're in the middle of an emacs-style keychain, exit it 578 // if we're in the middle of an emacs-style keychain, exit it
diff --git a/src/MenuCreator.cc b/src/MenuCreator.cc
index 9884187..74968e3 100644
--- a/src/MenuCreator.cc
+++ b/src/MenuCreator.cc
@@ -328,7 +328,7 @@ void translateMenuItem(FbTk::Parser &parse, ParseItem &pitem,
328 // we need to attach command to arguments so command parser can parse it 328 // we need to attach command to arguments so command parser can parse it
329 string line = str_key + " " + str_cmd; 329 string line = str_key + " " + str_cmd;
330 FbTk::RefCount<FbTk::Command<void> > command(FbTk::CommandParser<void>::instance().parse(line)); 330 FbTk::RefCount<FbTk::Command<void> > command(FbTk::CommandParser<void>::instance().parse(line));
331 if (*command != 0) { 331 if (command != 0) {
332 // special NLS default labels 332 // special NLS default labels
333 if (str_label.empty()) { 333 if (str_label.empty()) {
334 if (str_key == "reconfig" || str_key == "reconfigure") { 334 if (str_key == "reconfig" || str_key == "reconfigure") {
diff --git a/src/Remember.cc b/src/Remember.cc
index 6dd636f..10aa52c 100644
--- a/src/Remember.cc
+++ b/src/Remember.cc
@@ -584,8 +584,8 @@ Application* findMatchingPatterns(ClientPattern *pat, Remember::Patterns *patlis
584 for (; it != it_end; ++it) { 584 for (; it != it_end; ++it) {
585 if (*it->first == *pat && is_group == it->second->is_grouped && 585 if (*it->first == *pat && is_group == it->second->is_grouped &&
586 transient == it->second->is_transient && 586 transient == it->second->is_transient &&
587 ((match_pat == 0 && *it->second->group_pattern == 0) || 587 ((match_pat == 0 && it->second->group_pattern == 0) ||
588 (match_pat && *match_pat == **it->second->group_pattern))) { 588 (match_pat && *match_pat == *it->second->group_pattern))) {
589 589
590 Application *ret = it->second; 590 Application *ret = it->second;
591 591
@@ -887,7 +887,7 @@ void Remember::save() {
887 grouped_apps.insert(&a); 887 grouped_apps.insert(&a);
888 // otherwise output this whole group 888 // otherwise output this whole group
889 apps_file << "[group]"; 889 apps_file << "[group]";
890 if (*a.group_pattern) 890 if (a.group_pattern)
891 apps_file << " " << a.group_pattern->toString(); 891 apps_file << " " << a.group_pattern->toString();
892 apps_file << endl; 892 apps_file << endl;
893 893
@@ -1366,7 +1366,7 @@ FluxboxWindow *Remember::findGroup(Application *app, BScreen &screen) {
1366 for (; it != it_end; ++it) { 1366 for (; it != it_end; ++it) {
1367 if (it->second == app && it->first->fbwindow() && 1367 if (it->second == app && it->first->fbwindow() &&
1368 &screen == &it->first->screen() && 1368 &screen == &it->first->screen() &&
1369 (!*app->group_pattern || app->group_pattern->match(*it->first))) 1369 (!app->group_pattern || app->group_pattern->match(*it->first)))
1370 return it->first->fbwindow(); 1370 return it->first->fbwindow();
1371 } 1371 }
1372 1372
diff --git a/src/ToolFactory.cc b/src/ToolFactory.cc
index 2645956..d94105d 100644
--- a/src/ToolFactory.cc
+++ b/src/ToolFactory.cc
@@ -92,7 +92,7 @@ ToolbarItem *ToolFactory::create(const std::string &name, const FbTk::FbWindow &
92 item = new ClockTool(parent, m_clock_theme, screen(), tbar.menu()); 92 item = new ClockTool(parent, m_clock_theme, screen(), tbar.menu());
93 } else { 93 } else {
94 FbTk::RefCount<FbTk::Command<void> > cmd(FbTk::CommandParser<void>::instance().parse(name)); 94 FbTk::RefCount<FbTk::Command<void> > cmd(FbTk::CommandParser<void>::instance().parse(name));
95 if (*cmd == 0) // we need a command 95 if (cmd == 0) // we need a command
96 return 0; 96 return 0;
97 97
98 // TODO maybe direction of arrows should depend on toolbar layout ? 98 // TODO maybe direction of arrows should depend on toolbar layout ?
diff --git a/src/WorkspaceCmd.cc b/src/WorkspaceCmd.cc
index ad88640..34c8f9a 100644
--- a/src/WorkspaceCmd.cc
+++ b/src/WorkspaceCmd.cc
@@ -90,7 +90,7 @@ void WindowListCmd::execute() {
90 WindowCmd<void>::setWindow((*it)->fbwindow()); 90 WindowCmd<void>::setWindow((*it)->fbwindow());
91 else if (typeid(**it) == typeid(WinClient)) 91 else if (typeid(**it) == typeid(WinClient))
92 WindowCmd<void>::setClient(dynamic_cast<WinClient *>(*it)); 92 WindowCmd<void>::setClient(dynamic_cast<WinClient *>(*it));
93 if (!*m_filter || m_filter->execute()) 93 if (!m_filter || m_filter->execute())
94 m_cmd->execute(); 94 m_cmd->execute();
95 } 95 }
96 WindowCmd<void>::setClient(old); 96 WindowCmd<void>::setClient(old);