]> git.lyx.org Git - lyx.git/commitdiff
Replace auto_ptr with unique_ptr
authorGuillaume Munch <gm@lyx.org>
Thu, 2 Jun 2016 20:58:52 +0000 (21:58 +0100)
committerGuillaume Munch <gm@lyx.org>
Thu, 9 Jun 2016 14:21:39 +0000 (15:21 +0100)
This is a mechanical replacement. For now it seems that unique_ptrs are
essentially used for exception-safety. More could certainly be done to clarify
pointer ownership in general.

src/Buffer.cpp
src/Buffer.h
src/BufferList.cpp
src/Text.cpp
src/factory.cpp
src/frontends/qt4/GuiViewSource.cpp
src/frontends/qt4/GuiViewSource.h
src/insets/ExternalSupport.cpp
src/insets/ExternalTransforms.h
src/mathed/MathExtern.cpp
src/mathed/MathParser.cpp

index 3cb7aac094e73250d50a8b26b385eda93dbc5e49..b75ddd0d70ece6f3d27bce2d2f3a62aa3daf5edd 100644 (file)
@@ -3654,11 +3654,11 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to)
 }
 
 // returns NULL if id-to-row conversion is unsupported
-auto_ptr<TexRow> Buffer::getSourceCode(odocstream & os, string const & format,
-                          pit_type par_begin, pit_type par_end,
-                          OutputWhat output, bool master) const
+unique_ptr<TexRow> Buffer::getSourceCode(odocstream & os, string const & format,
+                                         pit_type par_begin, pit_type par_end,
+                                         OutputWhat output, bool master) const
 {
-       auto_ptr<TexRow> texrow(NULL);
+       unique_ptr<TexRow> texrow;
        OutputParams runparams(&params().encoding());
        runparams.nice = true;
        runparams.flavor = params().getOutputFlavor(format);
@@ -3712,7 +3712,7 @@ auto_ptr<TexRow> Buffer::getSourceCode(odocstream & os, string const & format,
                        LaTeXFeatures features(*this, params(), runparams);
                        params().validate(features);
                        runparams.use_polyglossia = features.usePolyglossia();
-                       texrow.reset(new TexRow());
+                       texrow = make_unique<TexRow>();
                        texrow->newline();
                        texrow->newline();
                        // latex or literate
@@ -3755,7 +3755,7 @@ auto_ptr<TexRow> Buffer::getSourceCode(odocstream & os, string const & format,
                                writeDocBookSource(os, absFileName(), runparams, output);
                } else {
                        // latex or literate
-                       texrow.reset(new TexRow());
+                       texrow = make_unique<TexRow>();
                        texrow->newline();
                        texrow->newline();
                        otexstream ots(os, *texrow);
index d4074b0fdb3b916e6d6bae2a918292ba12171015..f488c4a4e0c22b68af55da0db84c3bcbae1b1864 100644 (file)
@@ -15,6 +15,7 @@
 #include "OutputEnums.h"
 #include "OutputParams.h"
 
+#include "support/unique_ptr.h"
 #include "support/strfwd.h"
 #include "support/types.h"
 
@@ -623,8 +624,8 @@ public:
 
        /// get source code (latex/docbook) for some paragraphs, or all paragraphs
        /// including preamble
-       /// returns NULL if Id to Row conversion is unsupported
-       std::auto_ptr<TexRow> getSourceCode(odocstream & os,
+       /// returns nullptr if Id to Row conversion is unsupported
+       unique_ptr<TexRow> getSourceCode(odocstream & os,
                        std::string const & format, pit_type par_begin,
                        pit_type par_end, OutputWhat output, bool master) const;
 
index ff99a090f35ea08ad398bbb8eabaf1ca92ef9238..9a5c4e1c27bef836a145ebcb156c64c14a497c2c 100644 (file)
@@ -130,9 +130,9 @@ Buffer * BufferList::newBuffer(string const & s)
 
 Buffer * BufferList::createNewBuffer(string const & s)
 {
-       auto_ptr<Buffer> tmpbuf;
+       unique_ptr<Buffer> tmpbuf;
        try {
-               tmpbuf.reset(new Buffer(s));
+               tmpbuf = make_unique<Buffer>(s);
        } catch (ExceptionMessage const & message) {
                if (message.type_ == ErrorException) {
                        Alert::error(message.title_, message.details_);
index 794605405a8440bc1bd5e53479f3a87c20b496f5..12ab04f043397925fbfdd47059172509702d7149 100644 (file)
@@ -69,6 +69,7 @@
 #include "support/lyxalgo.h"
 #include "support/lyxtime.h"
 #include "support/textutils.h"
+#include "support/unique_ptr.h"
 
 #include <sstream>
 
@@ -463,8 +464,7 @@ void Text::readParToken(Paragraph & par, Lexer & lex,
        } else if (token == "\\SpecialChar" ||
                   (token == "\\SpecialCharNoPassThru" &&
                    !par.layout().pass_thru && !inset().isPassThru())) {
-               auto_ptr<Inset> inset;
-               inset.reset(new InsetSpecialChar);
+               auto inset = make_unique<InsetSpecialChar>();
                inset->read(lex);
                inset->setBuffer(*buf);
                par.insertInset(par.size(), inset.release(), font, change);
@@ -473,8 +473,7 @@ void Text::readParToken(Paragraph & par, Lexer & lex,
                docstring const s = ltrim(lex.getDocString(), "\\");
                par.insert(par.size(), s, font, change);
        } else if (token == "\\IPAChar") {
-               auto_ptr<Inset> inset;
-               inset.reset(new InsetIPAChar);
+               auto inset = make_unique<InsetIPAChar>();
                inset->read(lex);
                inset->setBuffer(*buf);
                par.insertInset(par.size(), inset.release(), font, change);
@@ -499,7 +498,7 @@ void Text::readParToken(Paragraph & par, Lexer & lex,
        } else if (token == "\\backslash") {
                par.appendChar('\\', font, change);
        } else if (token == "\\LyXTable") {
-               auto_ptr<Inset> inset(new InsetTabular(buf));
+               auto inset = make_unique<InsetTabular>(buf);
                inset->read(lex);
                par.insertInset(par.size(), inset.release(), font, change);
        } else if (token == "\\change_unchanged") {
index b8d94336b9f74294f14d61161e360294a9251d23..a03f88fa2838900d71da17959df81bcd4d2afc1d 100644 (file)
 #include "frontends/alert.h"
 
 #include "support/debug.h"
-#include "support/lstrings.h"
 #include "support/ExceptionMessage.h"
-
 #include "support/lassert.h"
+#include "support/lstrings.h"
+#include "support/unique_ptr.h"
 
 #include <sstream>
 
+
 using namespace std;
 using namespace lyx::support;
 
@@ -309,7 +310,7 @@ Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd)
                        case EXTERNAL_CODE: {
                                InsetExternalParams iep;
                                InsetExternal::string2params(to_utf8(cmd.argument()), *buf, iep);
-                               auto_ptr<InsetExternal> inset(new InsetExternal(buf));
+                               auto inset = make_unique<InsetExternal>(buf);
                                inset->setBuffer(*buf);
                                inset->setParams(iep);
                                return inset.release();
@@ -318,7 +319,7 @@ Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd)
                        case GRAPHICS_CODE: {
                                InsetGraphicsParams igp;
                                InsetGraphics::string2params(to_utf8(cmd.argument()), *buf, igp);
-                               auto_ptr<InsetGraphics> inset(new InsetGraphics(buf));
+                               auto inset = make_unique<InsetGraphics>(buf);
                                inset->setParams(igp);
                                return inset.release();
                        }
@@ -514,7 +515,7 @@ Inset * readInset(Lexer & lex, Buffer * buf)
        if (lex.getString() != "\\begin_inset")
                LYXERR0("Buffer::readInset: Consistency check failed.");
 
-       auto_ptr<Inset> inset;
+       unique_ptr<Inset> inset;
 
        string tmptok;
        lex >> tmptok;
index d5838976a9fd013b9e0b71e80ac4740866d66f93..46dd35884eadc7e9d05dac8ff64caafa350ea0dd 100644 (file)
@@ -111,8 +111,8 @@ void ViewSourceWidget::getContent(BufferView const * view,
        if (par_begin > par_end)
                swap(par_begin, par_end);
        odocstringstream ostr;
-       texrow_ = view->buffer().getSourceCode(ostr, format,
-                                                                               par_begin, par_end + 1, output, master);
+       texrow_ = view->buffer()
+               .getSourceCode(ostr, format, par_begin, par_end + 1, output, master);
        //ensure that the last line can always be selected in its full width
        str = ostr.str() + "\n";
 }
@@ -201,7 +201,7 @@ void ViewSourceWidget::realUpdateView()
 #ifdef DEVEL_VERSION
        // output tex<->row correspondences in the source panel if the "-dbg latex"
        // option is given.
-       if (texrow_.get() && lyx::lyxerr.debugging(Debug::LATEX)) {
+       if (texrow_ && lyx::lyxerr.debugging(Debug::LATEX)) {
                QStringList list = qcontent.split(QChar('\n'));
                docstring_list dlist;
                for (QStringList::const_iterator it = list.begin(); it != list.end(); ++it)
@@ -216,7 +216,7 @@ void ViewSourceWidget::realUpdateView()
        viewSourceTV->blockSignals(true);
        bool const changed = setText(qcontent);
 
-       if (changed && !texrow_.get()) {
+       if (changed && !texrow_) {
                // position-to-row is unavailable
                // we jump to the first modification
                const QChar * oc = old.constData();
@@ -246,7 +246,7 @@ void ViewSourceWidget::realUpdateView()
                //c.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor,1);
                viewSourceTV->setTextCursor(c);
 
-       } else if (texrow_.get()) {
+       } else if (texrow_) {
                // Use the available position-to-row conversion to highlight
                // the current selection in the source
                std::pair<int,int> rows = texrow_->rowFromCursor(bv_->cursor());
@@ -309,7 +309,7 @@ void ViewSourceWidget::realUpdateView()
 // need a proper LFUN if we want to implement it in release mode
 void ViewSourceWidget::gotoCursor()
 {
-       if (!bv_ || !texrow_.get())
+       if (!bv_ || !texrow_)
                return;
        int row = viewSourceTV->textCursor().blockNumber() + 1;
        const_cast<BufferView *>(bv_)->setCursorFromRow(row, *texrow_);
index e089305be58fabb1985616ff6485b293ecd398f1..428da050118e4333f296badd695e00062cbaae1d 100644 (file)
@@ -85,7 +85,7 @@ private:
        QTimer * update_timer_;
        /// TexRow information from the last source view. If TexRow is unavailable
        /// for the last format then texrow_ is null.
-       std::auto_ptr<TexRow> texrow_;
+       unique_ptr<TexRow> texrow_;
 };
 
 
index cbbb88bc2b3e8cf6b076758fe749d1f3d6e38ee4..7ea6d566fda73911d930f81646e9e77f7d024365 100644 (file)
@@ -434,7 +434,7 @@ string const substituteIt<TransformCommand>(string const & input,
        else if (id == Resize)
                ptr = store.getCommandTransformer(params.resizedata);
 
-       if (!ptr.get())
+       if (!ptr)
                return input;
 
        string result =
@@ -473,7 +473,7 @@ string const substituteIt<TransformOption>(string const & input,
                break;
        }
 
-       if (!ptr.get())
+       if (!ptr)
                return input;
 
        return subst(input, ptr->placeholder(), ptr->option());
index c4213bd7de8bdd0b9347e14fa189c8dd51ed8640..8e531f31d8258902a3dc0b723c9fde612ccad73b 100644 (file)
@@ -16,6 +16,8 @@
 
 #include "graphics/GraphicsParams.h"
 
+#include "support/unique_ptr.h"
+
 #include <boost/any.hpp>
 #include <boost/function.hpp>
 
@@ -121,7 +123,7 @@ public:
  */
 class TransformCommand {
 public:
-       typedef std::auto_ptr<TransformCommand const> ptr_type;
+       typedef unique_ptr<TransformCommand const> ptr_type;
        virtual ~TransformCommand() {}
 
        /// The string from the External Template that we seek to replace.
@@ -200,7 +202,7 @@ private:
  */
 class TransformOption {
 public:
-       typedef std::auto_ptr<TransformOption const> ptr_type;
+       typedef unique_ptr<TransformOption const> ptr_type;
        virtual ~TransformOption() {}
 
        /// The string from the External Template that we seek to replace.
index 7fbb4af732fb10fa941cb57d9d01c50d3a0d758b..f3df8c884e93129b66dca1ab6ca1244d6e2f8e7b 100644 (file)
@@ -45,6 +45,7 @@
 #include "support/lstrings.h"
 #include "support/TempFile.h"
 #include "support/textutils.h"
+#include "support/unique_ptr.h"
 
 #include <algorithm>
 #include <sstream>
@@ -370,7 +371,7 @@ void splitScripts(MathData & ar)
 
                // create extra script inset and move superscript over
                InsetMathScript * p = ar[i].nucleus()->asScriptInset();
-               auto_ptr<InsetMathScript> q(new InsetMathScript(buf, true));
+               auto q = make_unique<InsetMathScript>(buf, true);
                swap(q->up(), p->up());
                p->removeScript(true);
 
@@ -598,7 +599,7 @@ void extractFunctions(MathData & ar, ExternalMath kind)
                extractScript(exp, jt, ar.end(), true);
 
                // create a proper inset as replacement
-               auto_ptr<InsetMathExFunc> p(new InsetMathExFunc(buf, name));
+               auto p = make_unique<InsetMathExFunc>(buf, name);
 
                // jt points to the "argument". Get hold of this.
                MathData::iterator st = 
@@ -683,7 +684,7 @@ void extractIntegrals(MathData & ar, ExternalMath kind)
                        continue;
 
                // core ist part from behind the scripts to the 'd'
-               auto_ptr<InsetMathExInt> p(new InsetMathExInt(buf, from_ascii("int")));
+               auto p = make_unique<InsetMathExInt>(buf, from_ascii("int"));
 
                // handle scripts if available
                if (!testIntSymbol(*it)) {
@@ -768,7 +769,7 @@ void extractSums(MathData & ar)
                        continue;
 
                // create a proper inset as replacement
-               auto_ptr<InsetMathExInt> p(new InsetMathExInt(buf, from_ascii("sum")));
+               auto p = make_unique<InsetMathExInt>(buf, from_ascii("sum"));
 
                // collect lower bound and summation index
                InsetMathScript const * sub = ar[i]->asScriptInset();
@@ -856,7 +857,7 @@ void extractDiff(MathData & ar)
                }
 
                // create a proper diff inset
-               auto_ptr<InsetMathDiff> diff(new InsetMathDiff(buf));
+               auto diff = make_unique<InsetMathDiff>(buf);
 
                // collect function, let jt point behind last used item
                MathData::iterator jt = it + 1;
index 2849b0f80b79c46ca36269c68f413ee8b46c6a34..d3263175205ea46cb95a1877c1a63d2fafe3de7d 100644 (file)
@@ -74,9 +74,10 @@ following hack as starting point to write some macros:
 #include "Encoding.h"
 #include "Lexer.h"
 
-#include "support/debug.h"
 #include "support/convert.h"
+#include "support/debug.h"
 #include "support/docstream.h"
+#include "support/unique_ptr.h"
 
 #include <sstream>
 
@@ -1945,7 +1946,7 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
 
                // Disabled
                else if (1 && t.cs() == "ar") {
-                       auto_ptr<InsetMathXYArrow> p(new InsetMathXYArrow);
+                       auto p = make_unique<InsetMathXYArrow>();
                        // try to read target
                        parse(p->cell(0), FLAG_OTPTION, mode);
                        // try to read label