]> git.lyx.org Git - features.git/commitdiff
Extract toString method into InsetParams
authorYuriy Skalko <yuriy.skalko@gmail.com>
Fri, 1 Jan 2021 22:18:54 +0000 (00:18 +0200)
committerYuriy Skalko <yuriy.skalko@gmail.com>
Fri, 15 Jan 2021 19:09:15 +0000 (21:09 +0200)
41 files changed:
src/Makefile.am
src/insets/InsetBox.cpp
src/insets/InsetBox.h
src/insets/InsetBranch.cpp
src/insets/InsetBranch.h
src/insets/InsetCommandParams.cpp
src/insets/InsetCommandParams.h
src/insets/InsetERT.cpp
src/insets/InsetERT.h
src/insets/InsetExternal.cpp
src/insets/InsetExternal.h
src/insets/InsetFloat.cpp
src/insets/InsetFloat.h
src/insets/InsetGraphicsParams.cpp
src/insets/InsetGraphicsParams.h
src/insets/InsetIPAMacro.cpp
src/insets/InsetIPAMacro.h
src/insets/InsetIndex.cpp
src/insets/InsetIndex.h
src/insets/InsetListingsParams.cpp
src/insets/InsetListingsParams.h
src/insets/InsetNewline.cpp
src/insets/InsetNewline.h
src/insets/InsetNewpage.cpp
src/insets/InsetNewpage.h
src/insets/InsetNote.cpp
src/insets/InsetNote.h
src/insets/InsetParams.cpp [new file with mode: 0644]
src/insets/InsetParams.h
src/insets/InsetPhantom.cpp
src/insets/InsetPhantom.h
src/insets/InsetScript.cpp
src/insets/InsetScript.h
src/insets/InsetSeparator.cpp
src/insets/InsetSeparator.h
src/insets/InsetSpace.cpp
src/insets/InsetSpace.h
src/insets/InsetVSpace.cpp
src/insets/InsetVSpace.h
src/insets/InsetWrap.cpp
src/insets/InsetWrap.h

index 7dec8a1a6d4e20e6da50246aa20ee21e20e5b249..8627d6b8fb22f461c4a182c659578a432df232a9 100644 (file)
@@ -577,6 +577,7 @@ SOURCEFILESINSETS = \
        insets/InsetNewpage.cpp \
        insets/InsetNomencl.cpp \
        insets/InsetNote.cpp \
+       insets/InsetParams.cpp \
        insets/InsetPhantom.cpp \
        insets/InsetPreview.cpp \
        insets/InsetQuotes.cpp \
index 60291bf62ba228cfc6d52026e3a79377b7bc04a0..80518c7ddfd0a860e0108a53794a0befbaac0265 100644 (file)
@@ -834,15 +834,6 @@ string InsetBox::contextMenuName() const
 }
 
 
-string InsetBoxParams::toString() const
-{
-       ostringstream data;
-       data << "box" << ' ';
-       write(data);
-       return data.str();
-}
-
-
 void InsetBox::string2params(string const & in, InsetBoxParams & params)
 {
        if (in.empty())
index 6cc0db6bf3e4698ef4abb5725f23f6c597b62d70..16ebf4a79495e9bd7347583fbea4ab7ecc4a81b3 100644 (file)
@@ -31,7 +31,7 @@ public:
        ///
        void read(Lexer & lex) override;
        ///
-       std::string toString() const override;
+       std::string name() const override { return "box"; }
 
        ///
        std::string type;
index baa6c587685b6f8e700c9f43213f7df253226178..80fd56afa280bc217c8a6118c821fa01c8302058 100644 (file)
@@ -387,14 +387,6 @@ bool InsetBranch::isMacroScope() const
 }
 
 
-string InsetBranchParams::toString() const
-{
-       ostringstream data;
-       write(data);
-       return data.str();
-}
-
-
 void InsetBranch::string2params(string const & in, InsetBranchParams & params)
 {
        params = InsetBranchParams();
index 87eb71ff917a945a0863537a9688a4638b5f349a..e7b9a508880d576984ded05844090c3de0d269f1 100644 (file)
@@ -28,8 +28,6 @@ public:
        ///
        void read(Lexer & lex) override;
        ///
-       std::string toString() const override;
-       ///
        docstring branch;
        ///
        bool inverted;
index 4ea716f9c451d5e2783d789b650fe3cc5139229e..f74f1ee40cfa536850da9a8b02262f4736ad70aa 100644 (file)
@@ -406,6 +406,12 @@ void InsetCommandParams::Write(ostream & os, Buffer const * buffer) const
 }
 
 
+string InsetCommandParams::name() const
+{
+       return insetName(code());
+}
+
+
 bool InsetCommandParams::writeEmptyOptional(ParamInfo::const_iterator ci) const
 {
        LASSERT(ci->isOptional(), return false);
@@ -604,16 +610,6 @@ docstring InsetCommandParams::getFirstNonOptParam() const
 }
 
 
-string InsetCommandParams::toString() const
-{
-       ostringstream data;
-       data << insetName(code()) << ' ';
-       write(data);
-       data << "\\end_inset\n";
-       return data.str();
-}
-
-
 docstring const & InsetCommandParams::operator[](string const & name) const
 {
        static const docstring dummy;
index a7656dc4fc0dd18ef244c5f1f28440988739bbad..cd4d76a6c64a6efeebf45a6940c65a24ae7c633b 100644 (file)
@@ -137,7 +137,8 @@ public:
        ///
        void Write(std::ostream & os, Buffer const * buf) const;
        ///
-       std::string toString() const override;
+       std::string name() const override;
+       bool writeEndInset() const override { return true; }
        /// Build the complete LaTeX command
        docstring getCommand(OutputParams const &) const;
        /// Return the command name
index 00eb1d04057eec937833e3fca99f4d218e9522f8..f7549544664759273b5c673875d9bebb2fef1ef5 100644 (file)
@@ -207,15 +207,6 @@ void InsetERTParams::read(Lexer & lex)
 }
 
 
-string InsetERTParams::toString() const
-{
-       ostringstream data;
-       data << "ert" << ' ';
-       write(data);
-       return data.str();
-}
-
-
 docstring InsetERT::xhtml(XMLStream &, OutputParams const &) const
 {
        return docstring();
index 57a8c4ed0ed8b6678076b0772ca6fa2d665a7d08..6656a99d12051ae32d221e85a089e1d8c3a5da5d 100644 (file)
@@ -28,7 +28,7 @@ struct InsetERTParams : public InsetParams {
        ///
        void read(Lexer & lex) override;
        ///
-       std::string toString() const override;
+       std::string name() const override { return "ert"; }
        ///
        CollapseStatus status_;
 };
index 42918ec81dce85ab5f79ac727664c84168e85c48..9dd0fa2690e1904e0e97c76c26acfef79568e858 100644 (file)
@@ -934,13 +934,4 @@ void InsetExternal::string2params(string const & in, InsetExternalParams & param
 }
 
 
-string InsetExternalParams::toString() const
-{
-       ostringstream data;
-       data << "external" << ' ';
-       write(data);
-       data << "\\end_inset\n";
-       return data.str();
-}
-
 } // namespace lyx
index 8d233c80b748cf4a6289546b9cf251dedf26e345..af4c496550006f6dbd50082fb3bc8a427810ac94 100644 (file)
@@ -53,7 +53,8 @@ public:
 
        void write(std::ostream &) const override;
        void read(Lexer &) override;
-       std::string toString() const override;
+       std::string name() const override { return "external"; }
+       bool writeEndInset() const override { return true; }
 
        Buffer const * buffer() { return buffer_; }
        void setBuffer(Buffer const * b) { buffer_ = b; }
index b6120ddd986c5c943c197b513640269ed15af369..11b349256f4804cfa5ce65b53d1ead26f904b6cb 100644 (file)
@@ -967,12 +967,4 @@ void InsetFloat::string2params(string const & in, InsetFloatParams & params)
 }
 
 
-string InsetFloatParams::toString() const
-{
-       ostringstream data;
-       write(data);
-       return data.str();
-}
-
-
 } // namespace lyx
index 9a043b5babb9b0ec97d7952b240e721bcc1138f3..58ac723a0a0147c745ba566812f8dbb024f52c58 100644 (file)
@@ -32,8 +32,6 @@ public:
        ///
        void read(Lexer & lex) override;
        ///
-       std::string toString() const override;
-       ///
        std::string type;
        ///
        std::string placement;
index c4de6335528e67cb5563f64c9cad44e28a33969d..60db34490eccf6fc21526ef6c8cc8417ced873a5 100644 (file)
@@ -254,13 +254,9 @@ bool InsetGraphicsParams::read(Lexer & lex, string const & token, bool allowOrig
 }
 
 
-string InsetGraphicsParams::toString() const
+void InsetGraphicsParams::read(Lexer & lex)
 {
-       ostringstream data;
-       data << "graphics" << ' ';
-       write(data);
-       data << "\\end_inset\n";
-       return data.str();
+       // TODO
 }
 
 
index be3fae8a14bd6b48c9634b2f0c67073e68241302..2315459edf763ce4fa3099193ecd287b14a6457a 100644 (file)
@@ -30,7 +30,7 @@ class Buffer;
 
 
 /// This class holds all the parameters needed by insetGraphics.
-class InsetGraphicsParams
+class InsetGraphicsParams : public InsetParams
 {
 public:
        /// Image filename.
@@ -78,11 +78,14 @@ public:
        InsetGraphicsParams & operator=(InsetGraphicsParams const &);
        /// Save the parameters in the LyX format stream.
        /// Buffer is needed to figure out if a figure is embedded.
-       void write(std::ostream & os) const;
+       void write(std::ostream & os) const override;
        /// If the token belongs to our parameters, read it.
        bool read(Lexer & lex, std::string const & token, bool allowOrigin);
+       void read(Lexer & lex) override;
        ///
-       std::string toString() const;
+       std::string name() const override { return "graphics"; }
+       ///
+       bool writeEndInset() const override { return true; }
        /// convert
        // Only a subset of InsetGraphicsParams is needed for display purposes.
        // This function also interrogates lyxrc to ascertain whether
index 1da5e295995f94f9d3760385b6ed09bc91808ae6..d908349fc86fbab8e170e9d8dbed0f39a374eb03 100644 (file)
@@ -340,15 +340,6 @@ docstring InsetIPADeco::toolTip(BufferView const &, int, int) const
 }
 
 
-string InsetIPADecoParams::toString() const
-{
-       ostringstream data;
-       data << "IPADeco" << ' ';
-       write(data);
-       return data.str();
-}
-
-
 void InsetIPADeco::string2params(string const & in, InsetIPADecoParams & params)
 {
        params = InsetIPADecoParams();
index 41dd3bf405f4c2433bfd0588597e4aa40e4a66e9..6627539319e22cfcfd61ead9c86bd1078b020321 100644 (file)
@@ -35,7 +35,7 @@ public:
        ///
        void read(Lexer & lex) override;
        ///
-       std::string toString() const override;
+       std::string name() const override { return "IPADeco"; }
        ///
        Type type;
 };
index 4deae0eba304e245e919e3bdc90ba82557db4b09..c076700ad99b5b6a14f96eae380bd2e8f3c4690a 100644 (file)
@@ -520,15 +520,6 @@ void InsetIndex::read(Lexer & lex)
 }
 
 
-string InsetIndexParams::toString() const
-{
-       ostringstream data;
-       data << "index";
-       write(data);
-       return data.str();
-}
-
-
 void InsetIndex::string2params(string const & in, InsetIndexParams & params)
 {
        params = InsetIndexParams();
index c2f23a610c1b995eb416e536a1b9997447efe03f..7c0cb60753bb2794443cb85df1b6d554f4da374a 100644 (file)
@@ -29,7 +29,7 @@ public:
        ///
        void read(Lexer & lex) override;
        ///
-       std::string toString() const override;
+       std::string name() const override { return "index"; }
 
        docstring index;
 };
index ab8a0573c36261305321ed9efce2e0eb70fbc0b6..8ffb4387974b8be06fd58b4275c4abbfecc2c3b6 100644 (file)
@@ -1006,15 +1006,6 @@ void InsetListingsParams::read(Lexer & lex)
 }
 
 
-string InsetListingsParams::toString() const
-{
-       ostringstream data;
-       data << "listings" << ' ';
-       write(data);
-       return data.str();
-}
-
-
 string InsetListingsParams::params(string const & sep) const
 {
        string par;
index 6f008b88653e9c680fe4bfc4206a95067b3ae312..f2d43733e7d7022cc3f61de286f259b0c693c85b 100644 (file)
@@ -34,7 +34,7 @@ public:
        void read(Lexer &) override;
 
        ///
-       std::string toString() const override;
+       std::string name() const override { return "listings"; }
 
        /// valid parameter string
        std::string params(std::string const & sep=",") const;
index 983457dd533313d3323d468f4a4f5b318edc5444..b7c83cb5bdde05e364728ee47d30e5c8ecc0887f 100644 (file)
@@ -281,13 +281,4 @@ void InsetNewline::string2params(string const & in, InsetNewlineParams & params)
 }
 
 
-string InsetNewlineParams::toString() const
-{
-       ostringstream data;
-       data << "newline" << ' ';
-       write(data);
-       return data.str();
-}
-
-
 } // namespace lyx
index 82667f524050369243bd06c9476234744ae1ab22..9b57e772c301630d5e65f0083d890949373485b9 100644 (file)
@@ -34,7 +34,7 @@ public:
        ///
        void read(Lexer & lex) override;
        ///
-       std::string toString() const override;
+       std::string name() const override { return "newline"; }
        ///
        Kind kind;
 };
index 6ab41fa3cedcc082ec97d192f3a4657bcc3078b3..6a33b8469f10b561df8e027aeb50b81b94335cf0 100644 (file)
@@ -351,13 +351,4 @@ void InsetNewpage::string2params(string const & in, InsetNewpageParams & params)
 }
 
 
-string InsetNewpageParams::toString() const
-{
-       ostringstream data;
-       data << "newpage" << ' ';
-       write(data);
-       return data.str();
-}
-
-
 } // namespace lyx
index 55df6b8b96c3a85a3e3c2574c9e74a5eb1f9b069..72038e5ffe79d4a7796ee630c125bf1e7a4776b5 100644 (file)
@@ -40,7 +40,7 @@ public:
        ///
        void read(Lexer & lex) override;
        ///
-       std::string toString() const override;
+       std::string name() const override { return "newpage"; }
        ///
        Kind kind;
 };
index c2ab7e003f58a506963e66e45d74fcb8d3b26529..b0afd7d282cdd2d1f058f9f012f0326cd9843058 100644 (file)
@@ -338,15 +338,6 @@ FontInfo InsetNote::getFont() const
 }
 
 
-string InsetNoteParams::toString() const
-{
-       ostringstream data;
-       data << "note" << ' ';
-       write(data);
-       return data.str();
-}
-
-
 void InsetNote::string2params(string const & in, InsetNoteParams & params)
 {
        params = InsetNoteParams();
index eb99a139e003f7012be76a91fa8aa4ccff70da9f..dca27d0d6a634ffada30ce9eb70b68a62d67bf91 100644 (file)
@@ -32,7 +32,7 @@ public:
        ///
        void read(Lexer & lex) override;
        ///
-       std::string toString() const override;
+       std::string name() const override { return "note"; }
 
        Type type;
 };
diff --git a/src/insets/InsetParams.cpp b/src/insets/InsetParams.cpp
new file mode 100644 (file)
index 0000000..d5b2849
--- /dev/null
@@ -0,0 +1,33 @@
+/**
+ * \file InsetParams.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Yuriy Skalko
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "InsetParams.h"
+
+#include <sstream>
+
+using namespace std;
+
+namespace lyx {
+
+
+string InsetParams::toString() const
+{
+       ostringstream data;
+       data << name() << ' ';
+       write(data);
+       if (writeEndInset())
+               data << "\\end_inset\n";
+       return data.str();
+}
+
+
+} // namespace lyx
index 81866cb33ab862ea965bc195cf9549531edcb1cd..c6709b4de529318056fcbb0d3e34bcbac3dd0dc3 100644 (file)
@@ -30,7 +30,10 @@ public:
        ///
        virtual void read(Lexer & lex) = 0;
        ///
-       virtual std::string toString() const = 0;
+       std::string toString() const;
+protected:
+       virtual std::string name() const { return std::string(); }
+       virtual bool writeEndInset() const { return false; }
 };
 
 
index 61d41ca2b2230678b7a1c82569a2ca535f8be8e6..4a40a4238cab2c40b7d8c295bf94d0e49db9600a 100644 (file)
@@ -362,15 +362,6 @@ string InsetPhantom::contextMenuName() const
 }
 
 
-string InsetPhantomParams::toString() const
-{
-       ostringstream data;
-       data << "phantom" << ' ';
-       write(data);
-       return data.str();
-}
-
-
 void InsetPhantom::string2params(string const & in, InsetPhantomParams & params)
 {
        params = InsetPhantomParams();
index 4d31099b031e1c295b2b8a81b3b1e341a30a98ca..ebfe747c3f77f2fb82eb69171164fbdb1c912165 100644 (file)
@@ -32,7 +32,7 @@ public:
        ///
        void read(Lexer & lex) override;
        ///
-       std::string toString() const override;
+       std::string name() const override { return "phantom"; }
        Type type;
 };
 
index 4a9ed85ee84512c590cc6626ea26aa7f2c53542c..4eb10fc2c3fc08bf6931174e1774c08cb73c8eba 100644 (file)
@@ -378,15 +378,6 @@ string InsetScript::contextMenuName() const
 }
 
 
-string InsetScriptParams::toString() const
-{
-       ostringstream data;
-       data << "script ";
-       write(data);
-       return data.str();
-}
-
-
 void InsetScript::string2params(string const & in, InsetScriptParams & params)
 {
        params = InsetScriptParams();
index 516f40fc1419ba5dcb1a743b82921e851da79cdd..612dcb025e143d0ab332bb6dc6f02f6c374867a2 100644 (file)
@@ -32,7 +32,7 @@ public:
        ///
        void read(Lexer & lex) override;
        ///
-       std::string toString() const override;
+       std::string name() const override { return "script"; }
        ///
        int shift(FontInfo const & font) const;
        ///
index 5d6b71f7342db0ab9ba467f2d1e38b2b95f92edf..fdfd4157c8e28707008111353e43db5c9d4397f8 100644 (file)
@@ -302,13 +302,4 @@ void InsetSeparator::string2params(string const & in, InsetSeparatorParams & par
 }
 
 
-string InsetSeparatorParams::toString() const
-{
-       ostringstream data;
-       data << "separator" << ' ';
-       write(data);
-       return data.str();
-}
-
-
 } // namespace lyx
index b930a2ada2c8dfcbd15f5e268834ea124185c705..cf6861f211fae5be36e22c04c39089ba0668afa1 100644 (file)
@@ -33,7 +33,7 @@ public:
        ///
        void read(Lexer & lex) override;
        ///
-       std::string toString() const override;
+       std::string name() const override { return "separator"; }
 
        Kind kind;
 };
index 4f9ba96e5910dfae0c722c48790b002d0309b253..a9f4dc73c649a5d28be6557cf7decac602b45843 100644 (file)
@@ -946,15 +946,4 @@ void InsetSpace::string2params(string const & in, InsetSpaceParams & params)
 }
 
 
-string InsetSpaceParams::toString() const
-{
-       ostringstream data;
-       if (math)
-               data << "math";
-       data << "space" << ' ';
-       write(data);
-       return data.str();
-}
-
-
 } // namespace lyx
index 44f6a5e61e871b38dd705c7389f9ed6d151922e0..98948704a49c3a33c4c3e96dc2df810cf2c72db9 100644 (file)
@@ -81,7 +81,7 @@ struct InsetSpaceParams : public InsetParams {
        ///
        void read(Lexer & lex) override;
        ///
-       std::string toString() const override;
+       std::string name() const override { return math ? "mathspace" : "space"; }
        ///
        Kind kind;
        ///
index a96a83c5016e2f5dfd768051719c53c150d3d895..7174430c1e58127ece8353e69a4d9e99c6d7138d 100644 (file)
@@ -271,13 +271,4 @@ void InsetVSpaceParams::read(Lexer & lex)
 }
 
 
-string InsetVSpaceParams::toString() const
-{
-       ostringstream data;
-       data << "vspace" << ' ';
-       write(data);
-       return data.str();
-}
-
-
 } // namespace lyx
index 0022d224d87c3e91154f5a215e4a01503d782823..55b31d6904acc2313f5a91e9a76c6ec8202263e1 100644 (file)
@@ -27,7 +27,7 @@ struct InsetVSpaceParams : public InsetParams {
        ///
        void read(Lexer & lex) override;
        ///
-       std::string toString() const override;
+       std::string name() const override { return "vspace"; }
        ///
        VSpace space_;
 };
index d70f8818da67a38665e03657d3e9c8d73174a85f..9400bf85d9dbab09306c787ac609b2d36d3e8a04 100644 (file)
@@ -268,13 +268,4 @@ void InsetWrap::string2params(string const & in, InsetWrapParams & params)
 }
 
 
-string InsetWrapParams::toString() const
-{
-       ostringstream data;
-       data << "wrap" << ' ';
-       write(data);
-       return data.str();
-}
-
-
 } // namespace lyx
index bf65db4e58766eab2f630d0dc7de04b373c64feb..795eb8b21f9c3ca310990fe429c9dbff0fbb3008 100644 (file)
@@ -27,7 +27,7 @@ public:
        ///
        void read(Lexer &) override;
        ///
-       std::string toString() const override;
+       std::string name() const override { return "wrap"; }
        ///
        std::string type;
        ///