From cb1f655dfc6966405a013eefd0efedbe26a0300c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 6 Apr 2018 11:30:10 +0100 Subject: C++17 Remove all boost things now in the standard library from buffer. --- libadhocutil/buffer.cpp | 26 +++++++++++--------------- libadhocutil/buffer.h | 17 ++++++++--------- libadhocutil/fprintbf.h | 3 ++- 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(str)); } else { - content.push_back(new CStringFragment(str, h)); + content.push_back(std::make_shared(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(str)); } else { - content.push_back(new CStringFragment(str, h)); + content.push_back(std::make_shared(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(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(frag, Free, len)); } else { free(frag); @@ -204,10 +204,10 @@ Buffer::clear() return *this; } -boost::shared_ptr +boost::format Buffer::getFormat(const std::string & msgfmt) { - return boost::shared_ptr(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(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(str) }; return *this; } Buffer & Buffer::operator=(const std::string & str) { - content.resize(1); - content.front() = new StringFragment(str); + content = { std::make_shared(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 #include #include #include -#include #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 Ptr; + typedef std::shared_ptr Ptr; /// Const pointer typedef. - typedef boost::intrusive_ptr CPtr; + typedef std::shared_ptr CPtr; /** Create an empty buffer */ Buffer(); @@ -90,7 +88,8 @@ class DLL_PUBLIC Buffer : public virtual IntrusivePtrBase { template 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 @@ -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 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 FragmentPtr; + typedef std::shared_ptr FragmentPtr; typedef std::vector 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 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 -- cgit v1.2.3