summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2018-04-06 11:30:10 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2018-04-06 16:24:38 +0100
commitcb1f655dfc6966405a013eefd0efedbe26a0300c (patch)
tree78d7b3a00ac790da0ab3f764c283862cc95237e0
parentC++17 (diff)
downloadlibadhocutil-cb1f655dfc6966405a013eefd0efedbe26a0300c.tar.bz2
libadhocutil-cb1f655dfc6966405a013eefd0efedbe26a0300c.tar.xz
libadhocutil-cb1f655dfc6966405a013eefd0efedbe26a0300c.zip
C++17
Remove all boost things now in the standard library from buffer.
-rw-r--r--libadhocutil/buffer.cpp26
-rw-r--r--libadhocutil/buffer.h17
-rw-r--r--libadhocutil/fprintbf.h3
3 files changed, 21 insertions, 25 deletions
diff --git a/libadhocutil/buffer.cpp b/libadhocutil/buffer.cpp
index c7dda56..934aee5 100644
--- a/libadhocutil/buffer.cpp
+++ b/libadhocutil/buffer.cpp
@@ -134,10 +134,10 @@ Buffer::append(const char * str, CStringHandling h)
{
if (str && *str) {
if (h == Copy) {
- content.push_back(new StringFragment(str));
+ content.push_back(std::make_shared<StringFragment>(str));
}
else {
- content.push_back(new CStringFragment(str, h));
+ content.push_back(std::make_shared<CStringFragment>(str, h));
}
}
return *this;
@@ -148,10 +148,10 @@ Buffer::append(char * str, CStringHandling h)
{
if (str && *str) {
if (h == Copy) {
- content.push_back(new StringFragment(str));
+ content.push_back(std::make_shared<StringFragment>(str));
}
else {
- content.push_back(new CStringFragment(str, h));
+ content.push_back(std::make_shared<CStringFragment>(str, h));
}
}
return *this;
@@ -161,7 +161,7 @@ Buffer &
Buffer::append(const std::string & str)
{
if (!str.empty()) {
- content.push_back(new StringFragment(str));
+ content.push_back(std::make_shared<StringFragment>(str));
}
return *this;
}
@@ -182,7 +182,7 @@ Buffer::vappendf(const char * fmt, va_list args)
char * frag;
size_t len = vasprintf(&frag, fmt, args);
if (len > 0) {
- content.push_back(new CStringFragment(frag, Free, len));
+ content.push_back(std::make_shared<CStringFragment>(frag, Free, len));
}
else {
free(frag);
@@ -204,10 +204,10 @@ Buffer::clear()
return *this;
}
-boost::shared_ptr<boost::format>
+boost::format
Buffer::getFormat(const std::string & msgfmt)
{
- return boost::shared_ptr<boost::format>(new boost::format(msgfmt));
+ return boost::format(msgfmt);
}
void
@@ -257,9 +257,7 @@ void
Buffer::flatten() const
{
if (content.size() > 1) {
- auto f = new StringFragment(str());
- content.resize(1);
- content.front() = f;
+ content = { std::make_shared<StringFragment>(str()) };
}
}
@@ -282,16 +280,14 @@ Buffer::length() const
Buffer &
Buffer::operator=(const char * str)
{
- content.resize(1);
- content.front() = new StringFragment(str);
+ content = { std::make_shared<StringFragment>(str) };
return *this;
}
Buffer &
Buffer::operator=(const std::string & str)
{
- content.resize(1);
- content.front() = new StringFragment(str);
+ content = { std::make_shared<StringFragment>(str) };
return *this;
}
diff --git a/libadhocutil/buffer.h b/libadhocutil/buffer.h
index 1d99f22..d553c57 100644
--- a/libadhocutil/buffer.h
+++ b/libadhocutil/buffer.h
@@ -1,12 +1,10 @@
#ifndef ADHOCUTIL_BUFFER_H
#define ADHOCUTIL_BUFFER_H
-#include "intrusivePtrBase.h"
#include <string>
#include <vector>
#include <stdarg.h>
#include <boost/format.hpp>
-#include <boost/shared_ptr.hpp>
#include "visibility.h"
namespace AdHoc {
@@ -20,7 +18,7 @@ namespace std {
namespace AdHoc {
/// High-speed text buffer for easy creation of programatically created strings.
-class DLL_PUBLIC Buffer : public virtual IntrusivePtrBase {
+class DLL_PUBLIC Buffer {
public:
/** How should Buffer handle char * arguments? */
enum CStringHandling {
@@ -33,9 +31,9 @@ class DLL_PUBLIC Buffer : public virtual IntrusivePtrBase {
};
/// Pointer typedef.
- typedef boost::intrusive_ptr<Buffer> Ptr;
+ typedef std::shared_ptr<Buffer> Ptr;
/// Const pointer typedef.
- typedef boost::intrusive_ptr<const Buffer> CPtr;
+ typedef std::shared_ptr<const Buffer> CPtr;
/** Create an empty buffer */
Buffer();
@@ -90,7 +88,8 @@ class DLL_PUBLIC Buffer : public virtual IntrusivePtrBase {
template <typename ... Params>
Buffer & appendbf(const std::string & fmtstr, const Params & ... params)
{
- return appendbf(*getFormat(fmtstr), params...);
+ auto bf = getFormat(fmtstr);
+ return appendbf(bf, params...);
}
/** Append the given boost::format and arguments to the buffer. */
template <typename Param, typename ... Params>
@@ -109,13 +108,13 @@ class DLL_PUBLIC Buffer : public virtual IntrusivePtrBase {
std::string str() const;
/** Helper function to centralize the construction of boost::format instances. */
- static boost::shared_ptr<boost::format> getFormat(const std::string & msgfmt);
+ static boost::format getFormat(const std::string & msgfmt);
private:
Buffer & appendbf(boost::format & fmt);
void DLL_PRIVATE flatten() const;
- class DLL_PRIVATE FragmentBase : public virtual IntrusivePtrBase {
+ class DLL_PRIVATE FragmentBase {
public:
virtual ~FragmentBase() = 0;
@@ -157,7 +156,7 @@ class DLL_PUBLIC Buffer : public virtual IntrusivePtrBase {
const std::string buf;
};
- typedef boost::intrusive_ptr<FragmentBase> FragmentPtr;
+ typedef std::shared_ptr<FragmentBase> FragmentPtr;
typedef std::vector<FragmentPtr> Content;
mutable Content content;
};
diff --git a/libadhocutil/fprintbf.h b/libadhocutil/fprintbf.h
index a997fae..e3c16a7 100644
--- a/libadhocutil/fprintbf.h
+++ b/libadhocutil/fprintbf.h
@@ -15,7 +15,8 @@ DLL_PUBLIC FILE * fopen(const boost::filesystem::path & path, const char * mode)
template <typename ... Params>
size_t inline fprintbf(FILE * f, const std::string & fmt, const Params & ... p)
{
- return fprintbf(f, *AdHoc::Buffer::getFormat(fmt), p...);
+ auto bf = AdHoc::Buffer::getFormat(fmt);
+ return fprintbf(f, bf, p...);
}
template <typename Param, typename ... Params>