Use std[::tr1]::shared_ptr instead of local RefCntr by default

This commit is contained in:
Jean-Francois Dockes
2015-08-09 13:54:24 +02:00
parent 83939e45ab
commit 4d1f679eac
61 changed files with 313 additions and 288 deletions
+2 -2
View File
@@ -1330,7 +1330,7 @@ using namespace std;
bool resizecc(const string& dir, int newmbs)
{
RefCntr<CirCache> occ(new CirCache(dir));
STD_SHARED_PTR<CirCache> occ(new CirCache(dir));
string ofn = occ->getpath();
string backupfn = ofn + ".orig";
@@ -1353,7 +1353,7 @@ bool resizecc(const string& dir, int newmbs)
}
}
RefCntr<CirCache> ncc(new CirCache(tmpdir));
STD_SHARED_PTR<CirCache> ncc(new CirCache(tmpdir));
string nfn = ncc->getpath();
if (!ncc->create(off_t(newmbs) * 1000 * 1024,
CirCache::CC_CRUNIQUE | CirCache::CC_CRTRUNCATE)) {
+2 -2
View File
@@ -690,7 +690,7 @@ int ExecCmd::doexec(const string &cmd, const vector<string>& args,
LOGERR(("ExecCmd::doexec: no connection from command\n"));
return -1;
}
oclicon->setcallback(RefCntr<NetconWorker>
oclicon->setcallback(STD_SHARED_PTR<NetconWorker>
(new ExecReader(output, m_advise)));
myloop.addselcon(m_fromcmd, Netcon::NETCONPOLL_READ);
// Give up ownership
@@ -703,7 +703,7 @@ int ExecCmd::doexec(const string &cmd, const vector<string>& args,
LOGERR(("ExecCmd::doexec: no connection from command\n"));
return -1;
}
iclicon->setcallback(RefCntr<NetconWorker>
iclicon->setcallback(STD_SHARED_PTR<NetconWorker>
(new ExecWriter(input, m_provide)));
myloop.addselcon(m_tocmd, Netcon::NETCONPOLL_WRITE);
// Give up ownership
+6 -4
View File
@@ -19,6 +19,8 @@
#ifndef TEST_NETCON
#include "autoconfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -1230,8 +1232,8 @@ int trycli(char *host, char *serv)
}
}
#else
RefCntr<NetconWorker> worker =
RefCntr<NetconWorker>(new CliNetconWorker());
STD_SHARED_PTR<NetconWorker> worker =
STD_SHARED_PTR<NetconWorker>(new CliNetconWorker());
clicon->setcallback(worker);
SelectLoop myloop;
myloop.addselcon(con, Netcon::NETCONPOLL_WRITE);
@@ -1296,8 +1298,8 @@ protected:
if (con == 0) {
return -1;
}
RefCntr<NetconWorker> worker =
RefCntr<NetconWorker>(new ServNetconWorker());
STD_SHARED_PTR<NetconWorker> worker =
STD_SHARED_PTR<NetconWorker>(new ServNetconWorker());
con->setcallback(worker);
m_loop.addselcon(NetconP(con), NETCONPOLL_READ);
return 1;
+6 -4
View File
@@ -16,11 +16,13 @@
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "autoconfig.h"
#include <sys/time.h>
#include <map>
#include <string>
#include "refcntr.h"
#include MEMORY_INCLUDE
/// A set of classes to manage client-server communication over a
/// connection-oriented network, or a pipe.
@@ -37,7 +39,7 @@
/// Base class for all network endpoints:
class Netcon;
typedef RefCntr<Netcon> NetconP;
typedef STD_SHARED_PTR<Netcon> NetconP;
class SelectLoop;
class Netcon {
@@ -240,7 +242,7 @@ public:
virtual int getline(char *buf, int cnt, int timeo = -1);
/// Set handler to be called when the connection is placed in the
/// selectloop and an event occurs.
virtual void setcallback(RefCntr<NetconWorker> user) {
virtual void setcallback(STD_SHARED_PTR<NetconWorker> user) {
m_user = user;
}
@@ -249,7 +251,7 @@ private:
char *m_bufbase; // Pointer to current 1st byte of useful data
int m_bufbytes; // Bytes of data.
int m_bufsize; // Total buffer size
RefCntr<NetconWorker> m_user;
STD_SHARED_PTR<NetconWorker> m_user;
virtual int cando(Netcon::Event reason); // Selectloop slot
};
+4 -2
View File
@@ -16,13 +16,15 @@
*/
#ifndef _PATHUT_H_INCLUDED_
#define _PATHUT_H_INCLUDED_
#include "autoconfig.h"
#include <unistd.h>
#include <string>
#include <vector>
#include <set>
#include "refcntr.h"
#include MEMORY_INCLUDE
/// Add a / at the end if none there yet.
extern void path_catslash(std::string &s);
@@ -116,7 +118,7 @@ private:
bool m_noremove;
};
typedef RefCntr<TempFileInternal> TempFile;
typedef STD_SHARED_PTR<TempFileInternal> TempFile;
/// Temporary directory class. Recursively deleted by destructor.
class TempDir {
+19 -12
View File
@@ -1,5 +1,21 @@
#ifndef _REFCNTR_H_
#define _REFCNTR_H_
/* Copyright (C) 2014 J.F.Dockes
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// See Stroustrup C++ 3rd ed, p. 783
// This is only used if std::shared_ptr is not available
@@ -33,8 +49,7 @@ public:
(*pcount)++;
return *this;
}
void release()
{
void reset() {
if (pcount && --(*pcount) == 0) {
delete rep;
delete pcount;
@@ -42,22 +57,14 @@ public:
rep = 0;
pcount = 0;
}
void reset() {
release();
}
~RefCntr()
{
release();
reset();
}
X *operator->() {return rep;}
X *getptr() const {return rep;}
X *get() const {return rep;}
const X *getconstptr() const {return rep;}
int getcnt() const {return pcount ? *pcount : 0;}
bool isNull() const {return rep == 0;}
bool isNotNull() const {return rep != 0;}
int use_count() const {return pcount ? *pcount : 0;}
operator bool() const {return rep != 0;}
};
#endif /*_REFCNTR_H_ */