From d21ceb4a235d8f8994390d7bc7611b990e6c0c31 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Fri, 22 Jul 2011 17:52:58 +0200 Subject: Remove the assignment operator from a regular pointer to a RefCount it is too easy too shoot yourself in the foot with it, other smart pointers also don't allow such assignments. If you do want to assign to a RefCount pointer, use reset(). ps: assignment between two RefCounts remains possible, of course. --- src/FbTk/LogicCommands.cc | 8 ++++---- src/FbTk/MacroCommand.cc | 2 +- src/FbTk/RefCount.hh | 6 ++---- src/FocusableList.cc | 2 +- src/Keys.cc | 2 +- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/FbTk/LogicCommands.cc b/src/FbTk/LogicCommands.cc index bda67f5..121823f 100644 --- a/src/FbTk/LogicCommands.cc +++ b/src/FbTk/LogicCommands.cc @@ -43,7 +43,7 @@ M *addCommands(M *macro, const string &args, bool trusted) { std::vector::iterator it = cmds.begin(), it_end = cmds.end(); for (; it != it_end; ++it) { - cmd = CommandParser::instance().parse(*it, trusted); + cmd.reset( CommandParser::instance().parse(*it, trusted) ); if (cmd) macro->add(cmd); } @@ -90,13 +90,13 @@ Command *IfCommand::parse(const std::string &command, const std::string &a if (cmds.size() < 2) return 0; - cond = CommandParser::instance().parse(cmds[0], trusted); + cond.reset( CommandParser::instance().parse(cmds[0], trusted) ); if (cond == 0) return 0; - t = CommandParser::instance().parse(cmds[1], trusted); + t.reset( CommandParser::instance().parse(cmds[1], trusted) ); if (cmds.size() >= 3) - f = CommandParser::instance().parse(cmds[2], trusted); + f.reset( CommandParser::instance().parse(cmds[2], trusted) ); if (t == 0 && f == 0) return 0; diff --git a/src/FbTk/MacroCommand.cc b/src/FbTk/MacroCommand.cc index e04d92a..549f2da 100644 --- a/src/FbTk/MacroCommand.cc +++ b/src/FbTk/MacroCommand.cc @@ -41,7 +41,7 @@ M *addCommands(M *macro, const std::string &args, bool trusted) { if (remainder.length() == 0) { std::list::iterator it = cmds.begin(), it_end = cmds.end(); for (; it != it_end; ++it) { - cmd = CommandParser::instance().parse(*it, trusted); + cmd.reset( CommandParser::instance().parse(*it, trusted) ); if (cmd) macro->add(cmd); } diff --git a/src/FbTk/RefCount.hh b/src/FbTk/RefCount.hh index 2595864..cc8c917 100644 --- a/src/FbTk/RefCount.hh +++ b/src/FbTk/RefCount.hh @@ -37,11 +37,10 @@ public: RefCount(const RefCount ©); ~RefCount(); RefCount &operator = (const RefCount ©); - RefCount &operator = (Pointer *p); Pointer &operator * () const { return *get(); } Pointer *operator -> () const { return get(); } Pointer *get() const { return m_data; } - void reset(Pointer *p) { *this = p; } + void reset(Pointer *p = 0); /// conversion to "bool" operator bool_type() const { return m_data ? &RefCount::m_data : 0; } @@ -100,12 +99,11 @@ RefCount &RefCount::operator = (const RefCount ©) } template -RefCount &RefCount::operator = (Pointer *p) { +void RefCount::reset(Pointer *p) { decRefCount(); m_data = p; // set data pointer m_refcount = new unsigned int(0); // create new counter incRefCount(); - return *this; } template diff --git a/src/FocusableList.cc b/src/FocusableList.cc index 77ff247..3373890 100644 --- a/src/FocusableList.cc +++ b/src/FocusableList.cc @@ -255,7 +255,7 @@ void FocusableList::attachSignals(Focusable &win) { FbTk::RefCount &tracker = m_signal_map[&win]; if (! tracker) { // we have not attached to this window yet - tracker = new SignalTracker; + tracker.reset(new SignalTracker); tracker->join(win.titleSig(), MemFunSelectArg1(*this, &FocusableList::updateTitle)); tracker->join(win.dieSig(), MemFun(*this, &FocusableList::remove)); if(fbwin) { diff --git a/src/Keys.cc b/src/Keys.cc index 0c20f9e..6bb0e42 100644 --- a/src/Keys.cc +++ b/src/Keys.cc @@ -518,7 +518,7 @@ bool Keys::addBinding(const string &linebuffer) { const char *str = FbTk::StringUtil::strcasestr(linebuffer.c_str(), val[argc].c_str()); if (str) // +1 to skip ':' - current_key->m_command = FbTk::CommandParser::instance().parse(str + 1); + current_key->m_command.reset(FbTk::CommandParser::instance().parse(str + 1)); if (!str || current_key->m_command == 0 || mod) { delete first_new_key; -- cgit v0.11.2