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.
This commit is contained in:
parent
1f34dee9b3
commit
d21ceb4a23
5 changed files with 9 additions and 11 deletions
|
@ -43,7 +43,7 @@ M *addCommands(M *macro, const string &args, bool trusted) {
|
|||
|
||||
std::vector<std::string>::iterator it = cmds.begin(), it_end = cmds.end();
|
||||
for (; it != it_end; ++it) {
|
||||
cmd = CommandParser<bool>::instance().parse(*it, trusted);
|
||||
cmd.reset( CommandParser<bool>::instance().parse(*it, trusted) );
|
||||
if (cmd)
|
||||
macro->add(cmd);
|
||||
}
|
||||
|
@ -90,13 +90,13 @@ Command<void> *IfCommand::parse(const std::string &command, const std::string &a
|
|||
if (cmds.size() < 2)
|
||||
return 0;
|
||||
|
||||
cond = CommandParser<bool>::instance().parse(cmds[0], trusted);
|
||||
cond.reset( CommandParser<bool>::instance().parse(cmds[0], trusted) );
|
||||
if (cond == 0)
|
||||
return 0;
|
||||
|
||||
t = CommandParser<void>::instance().parse(cmds[1], trusted);
|
||||
t.reset( CommandParser<void>::instance().parse(cmds[1], trusted) );
|
||||
if (cmds.size() >= 3)
|
||||
f = CommandParser<void>::instance().parse(cmds[2], trusted);
|
||||
f.reset( CommandParser<void>::instance().parse(cmds[2], trusted) );
|
||||
if (t == 0 && f == 0)
|
||||
return 0;
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ M *addCommands(M *macro, const std::string &args, bool trusted) {
|
|||
if (remainder.length() == 0) {
|
||||
std::list<std::string>::iterator it = cmds.begin(), it_end = cmds.end();
|
||||
for (; it != it_end; ++it) {
|
||||
cmd = CommandParser<void>::instance().parse(*it, trusted);
|
||||
cmd.reset( CommandParser<void>::instance().parse(*it, trusted) );
|
||||
if (cmd)
|
||||
macro->add(cmd);
|
||||
}
|
||||
|
|
|
@ -37,11 +37,10 @@ public:
|
|||
RefCount(const RefCount<Pointer2> ©);
|
||||
~RefCount();
|
||||
RefCount<Pointer> &operator = (const RefCount<Pointer> ©);
|
||||
RefCount<Pointer> &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<Pointer> &RefCount<Pointer>::operator = (const RefCount<Pointer> ©)
|
|||
}
|
||||
|
||||
template <typename Pointer>
|
||||
RefCount<Pointer> &RefCount<Pointer>::operator = (Pointer *p) {
|
||||
void RefCount<Pointer>::reset(Pointer *p) {
|
||||
decRefCount();
|
||||
m_data = p; // set data pointer
|
||||
m_refcount = new unsigned int(0); // create new counter
|
||||
incRefCount();
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Pointer>
|
||||
|
|
|
@ -255,7 +255,7 @@ void FocusableList::attachSignals(Focusable &win) {
|
|||
FbTk::RefCount<FbTk::SignalTracker> &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) {
|
||||
|
|
|
@ -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<void>::instance().parse(str + 1);
|
||||
current_key->m_command.reset(FbTk::CommandParser<void>::instance().parse(str + 1));
|
||||
|
||||
if (!str || current_key->m_command == 0 || mod) {
|
||||
delete first_new_key;
|
||||
|
|
Loading…
Reference in a new issue