]> git.lyx.org Git - lyx.git/commitdiff
separate insetcommand.[Ch] into two files
authorAndré Pönitz <poenitz@gmx.net>
Thu, 4 Jul 2002 13:54:28 +0000 (13:54 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Thu, 4 Jul 2002 13:54:28 +0000 (13:54 +0000)
we should be ble to use this later to reduce include dependencies

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4530 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/ChangeLog
src/insets/Makefile.am
src/insets/insetcommand.C
src/insets/insetcommand.h
src/insets/insetcommandparams.C [new file with mode: 0644]
src/insets/insetcommandparams.h [new file with mode: 0644]

index 979b57f0cf1793c7d86ce1c758c29cba9e1b505d..0373696c39eda58ad65c471d7f766a7a222e4d35 100644 (file)
@@ -1,3 +1,10 @@
+
+2002-07-04  André Pönitz <poenitz@gmx.net>
+
+       * insetcommandparams.[Ch]: new files
+
+       * insetcommand.[Ch]: move code to insetcommandparams.[Ch]
+
 2002-06-15  Herbert Voss  <voss@perce.de>
 
        * insetgraphics.C (prepareFile): bugfix; return always
 2002-06-15  Herbert Voss  <voss@perce.de>
 
        * insetgraphics.C (prepareFile): bugfix; return always
index 8817b75e0621e0de168f9904b4b8bc1cdad22597..4063687fbd3998c025999ac0548c1151c0a66a42 100644 (file)
@@ -29,6 +29,8 @@ libinsets_la_SOURCES = \
        insetcollapsable.h \
        insetcommand.C \
        insetcommand.h \
        insetcollapsable.h \
        insetcommand.C \
        insetcommand.h \
+       insetcommandparams.C \
+       insetcommandparams.h \
        inseterror.C \
        inseterror.h \
        insetert.C \
        inseterror.C \
        inseterror.h \
        insetert.C \
index dd1b3afac8696743da276bf6fb50420f020e6416..1c47948e7e17d327765068c63583dfb58e098a07 100644 (file)
 #include "insetcommand.h"
 #include "debug.h"
 #include "frontends/Painter.h"
 #include "insetcommand.h"
 #include "debug.h"
 #include "frontends/Painter.h"
-#include "lyxlex.h"
 
 using std::ostream;
 using std::endl;
 
 
 
 using std::ostream;
 using std::endl;
 
 
-InsetCommandParams::InsetCommandParams()
-{}
-
-
-InsetCommandParams::InsetCommandParams(string const & n,
-                                       string const & c,
-                                       string const & o)
-       : cmdname(n), contents(c), options(o)
-{}
-
-
-string const InsetCommandParams::getAsString() const
-{
-       return cmdname + "|++|" + contents + "|++|" + options;
-}
-
-
-void InsetCommandParams::setFromString(string const & b)
-{
-       string::size_type idx = b.find("|++|");
-       if (idx == string::npos) {
-               cmdname = b;
-               contents = "";
-               options = "";
-               return;
-       }
-
-       cmdname = b.substr(0, idx);
-       string tmp = b.substr(idx+4);
-
-       idx = tmp.find("|++|");
-       if (idx == string::npos) {
-               contents = tmp;
-               options = "";
-       } else {
-               contents  = tmp.substr(0, idx);
-               options = tmp.substr(idx+4);
-       }
-}
-
-
-bool InsetCommandParams::operator==(InsetCommandParams const & o) const
-{
-       return cmdname == o.cmdname && contents == o.contents
-               && options == o.options;
-}
-
-
-bool InsetCommandParams::operator!=(InsetCommandParams const & o) const
-{
-       return !(*this == o);
-}
-
-
-void InsetCommandParams::scanCommand(string const & cmd)
-{
-       string tcmdname, toptions, tcontents;
-
-       if (cmd.empty()) return;
-
-       enum { WS, CMDNAME, OPTION, CONTENT } state = WS;
-
-       // Used to handle things like \command[foo[bar]]{foo{bar}}
-       int nestdepth = 0;
-
-       for (string::size_type i = 0; i < cmd.length(); ++i) {
-               char c = cmd[i];
-               if ((state == CMDNAME && c == ' ') ||
-                   (state == CMDNAME && c == '[') ||
-                   (state == CMDNAME && c == '{')) {
-                       state = WS;
-               }
-               if ((state == OPTION  && c == ']') ||
-                   (state == CONTENT && c == '}')) {
-                       if (nestdepth == 0) {
-                               state = WS;
-                       } else {
-                               --nestdepth;
-                       }
-               }
-               if ((state == OPTION  && c == '[') ||
-                   (state == CONTENT && c == '{')) {
-                       ++nestdepth;
-               }
-               switch (state) {
-               case CMDNAME:   tcmdname += c; break;
-               case OPTION:    toptions += c; break;
-               case CONTENT:   tcontents += c; break;
-               case WS:
-                       if (c == '\\') {
-                               state = CMDNAME;
-                       } else if (c == '[') {
-                               state = OPTION;
-                               nestdepth = 0; // Just to be sure
-                       } else if (c == '{') {
-                               state = CONTENT;
-                               nestdepth = 0; // Just to be sure
-                       }
-                       break;
-               }
-       }
-
-       // Don't mess with this.
-       if (!tcmdname.empty())  setCmdName(tcmdname);
-       if (!toptions.empty())  setOptions(toptions);
-       if (!tcontents.empty()) setContents(tcontents);
-
-       if (lyxerr.debugging(Debug::PARSER))
-               lyxerr << "Command <" <<  cmd
-                      << "> == <" << getCommand()
-                      << "> == <" << getCmdName()
-                      << '|' << getContents()
-                      << '|' << getOptions() << '>' << endl;
-}
-
-
-// This function will not be necessary when lyx3
-void InsetCommandParams::read(LyXLex & lex)
-{
-       string token;
-
-       if (lex.eatLine()) {
-               token = lex.getString();
-               scanCommand(token);
-       } else {
-               lex.printError("InsetCommand: Parse error: `$$Token'");
-       }
-
-       while (lex.isOK()) {
-               lex.nextToken();
-               token = lex.getString();
-               if (token == "\\end_inset")
-                       break;
-       }
-       if (token != "\\end_inset") {
-               lex.printError("Missing \\end_inset at this point. "
-                              "Read: `$$Token'");
-       }
-}
-
-
-void InsetCommandParams::write(ostream & os) const
-{
-       os << "LatexCommand " << getCommand() << "\n";
-}
-
-
-string const InsetCommandParams::getCommand() const
-{
-       string s;
-       if (!getCmdName().empty()) s += "\\"+getCmdName();
-       if (!getOptions().empty()) s += "["+getOptions()+']';
-       s += "{"+getContents()+'}';
-       return s;
-}
-
-
 InsetCommand::InsetCommand(InsetCommandParams const & p, bool)
        : p_(p.getCmdName(), p.getContents(), p.getOptions())
 {}
 InsetCommand::InsetCommand(InsetCommandParams const & p, bool)
        : p_(p.getCmdName(), p.getContents(), p.getOptions())
 {}
index 466bef87f605591796e8352c2c5cd062543d7767..edae5131190f0a7fa8992aa62fc3917b21d43f75 100644 (file)
@@ -17,6 +17,7 @@
 #endif
 
 #include "insetbutton.h"
 #endif
 
 #include "insetbutton.h"
+#include "insetcommandparams.h"
 #include <boost/signals/signal0.hpp>
 #include <boost/utility.hpp>
 
 #include <boost/signals/signal0.hpp>
 #include <boost/utility.hpp>
 
  * Similar to InsetLaTeX but having control of the basic structure of a
  *   LaTeX command: \name[options]{contents}.
  */
  * Similar to InsetLaTeX but having control of the basic structure of a
  *   LaTeX command: \name[options]{contents}.
  */
-class InsetCommandParams {
-public:
-       ///
-       InsetCommandParams();
-       ///
-       explicit
-       InsetCommandParams(string const & n,
-                           string const & c = string(),
-                           string const & o = string());
-       ///
-       bool operator==(InsetCommandParams const &) const;
-       ///
-       bool operator!=(InsetCommandParams const &) const;
-       ///
-       void read(LyXLex &);
-       /// Parse the command
-       void scanCommand(string const &);
-       ///
-       void write(std::ostream &) const;
-       /// Build the complete LaTeX command
-       string const getCommand() const;
-       ///
-       string const & getCmdName() const { return cmdname; }
-       ///
-       string const & getOptions() const { return options; }
-       ///
-       string const & getContents() const { return contents; }
-       ///
-       void setCmdName(string const & n) { cmdname = n; }
-       ///
-       void setOptions(string const & o) { options = o; }
-       ///
-       void setContents(string const & c) { contents = c; }
-       ///
-       string const getAsString() const;
-       ///
-       void setFromString(string const &);
-private:
-       ///
-       string cmdname;
-       ///
-       string contents;
-       ///
-       string options;
-};
-
 
 ///
 class InsetCommand : public InsetButton, boost::noncopyable {
 
 ///
 class InsetCommand : public InsetButton, boost::noncopyable {
diff --git a/src/insets/insetcommandparams.C b/src/insets/insetcommandparams.C
new file mode 100644 (file)
index 0000000..93a3070
--- /dev/null
@@ -0,0 +1,174 @@
+/* This file is part of
+ * ======================================================
+ *
+ *           LyX, The Document Processor
+ *
+ *          Copyright 2002-2002 The LyX Team.
+ *
+ * ====================================================== */
+
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "insetcommandparams.h"
+#include "lyxlex.h"
+#include "debug.h"
+
+
+InsetCommandParams::InsetCommandParams()
+{}
+
+
+InsetCommandParams::InsetCommandParams(string const & n,
+                                       string const & c,
+                                       string const & o)
+       : cmdname(n), contents(c), options(o)
+{}
+
+
+string const InsetCommandParams::getAsString() const
+{
+       return cmdname + "|++|" + contents + "|++|" + options;
+}
+
+
+void InsetCommandParams::setFromString(string const & b)
+{
+       string::size_type idx = b.find("|++|");
+       if (idx == string::npos) {
+               cmdname = b;
+               contents = "";
+               options = "";
+               return;
+       }
+
+       cmdname = b.substr(0, idx);
+       string tmp = b.substr(idx+4);
+
+       idx = tmp.find("|++|");
+       if (idx == string::npos) {
+               contents = tmp;
+               options = "";
+       } else {
+               contents  = tmp.substr(0, idx);
+               options = tmp.substr(idx+4);
+       }
+}
+
+
+bool InsetCommandParams::operator==(InsetCommandParams const & o) const
+{
+       return cmdname == o.cmdname && contents == o.contents
+               && options == o.options;
+}
+
+
+bool InsetCommandParams::operator!=(InsetCommandParams const & o) const
+{
+       return !(*this == o);
+}
+
+
+void InsetCommandParams::scanCommand(string const & cmd)
+{
+       string tcmdname, toptions, tcontents;
+
+       if (cmd.empty()) return;
+
+       enum { WS, CMDNAME, OPTION, CONTENT } state = WS;
+
+       // Used to handle things like \command[foo[bar]]{foo{bar}}
+       int nestdepth = 0;
+
+       for (string::size_type i = 0; i < cmd.length(); ++i) {
+               char c = cmd[i];
+               if ((state == CMDNAME && c == ' ') ||
+                   (state == CMDNAME && c == '[') ||
+                   (state == CMDNAME && c == '{')) {
+                       state = WS;
+               }
+               if ((state == OPTION  && c == ']') ||
+                   (state == CONTENT && c == '}')) {
+                       if (nestdepth == 0) {
+                               state = WS;
+                       } else {
+                               --nestdepth;
+                       }
+               }
+               if ((state == OPTION  && c == '[') ||
+                   (state == CONTENT && c == '{')) {
+                       ++nestdepth;
+               }
+               switch (state) {
+               case CMDNAME:   tcmdname += c; break;
+               case OPTION:    toptions += c; break;
+               case CONTENT:   tcontents += c; break;
+               case WS:
+                       if (c == '\\') {
+                               state = CMDNAME;
+                       } else if (c == '[') {
+                               state = OPTION;
+                               nestdepth = 0; // Just to be sure
+                       } else if (c == '{') {
+                               state = CONTENT;
+                               nestdepth = 0; // Just to be sure
+                       }
+                       break;
+               }
+       }
+
+       // Don't mess with this.
+       if (!tcmdname.empty())  setCmdName(tcmdname);
+       if (!toptions.empty())  setOptions(toptions);
+       if (!tcontents.empty()) setContents(tcontents);
+
+       if (lyxerr.debugging(Debug::PARSER))
+               lyxerr << "Command <" <<  cmd
+                      << "> == <" << getCommand()
+                      << "> == <" << getCmdName()
+                      << '|' << getContents()
+                      << '|' << getOptions() << '>' << endl;
+}
+
+
+void InsetCommandParams::read(LyXLex & lex)
+{
+       string token;
+
+       if (lex.eatLine()) {
+               token = lex.getString();
+               scanCommand(token);
+       } else {
+               lex.printError("InsetCommand: Parse error: `$$Token'");
+       }
+
+       while (lex.isOK()) {
+               lex.nextToken();
+               token = lex.getString();
+               if (token == "\\end_inset")
+                       break;
+       }
+       if (token != "\\end_inset") {
+               lex.printError("Missing \\end_inset at this point. "
+                              "Read: `$$Token'");
+       }
+}
+
+
+void InsetCommandParams::write(ostream & os) const
+{
+       os << "LatexCommand " << getCommand() << "\n";
+}
+
+
+string const InsetCommandParams::getCommand() const
+{
+       string s;
+       if (!getCmdName().empty()) s += "\\"+getCmdName();
+       if (!getOptions().empty()) s += "["+getOptions()+']';
+       s += "{"+getContents()+'}';
+       return s;
+}
+
diff --git a/src/insets/insetcommandparams.h b/src/insets/insetcommandparams.h
new file mode 100644 (file)
index 0000000..90bb0eb
--- /dev/null
@@ -0,0 +1,73 @@
+// -*- C++ -*-
+/* This file is part of*
+ * ======================================================
+ *
+ *           LyX, The Document Processor
+ *
+ *           Copyright 2002-2001 The LyX Team.
+ *
+ * ====================================================== */
+
+#ifndef INSETCOMMANDPARAMS_H
+#define INSETCOMMANDPARAMS_H
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include <config.h>
+
+#include "LString.h"
+
+#include <iosfwd>
+
+class LyXLex;
+
+class InsetCommandParams {
+public:
+       ///
+       InsetCommandParams();
+       ///
+       explicit
+       InsetCommandParams(string const & n,
+                           string const & c = string(),
+                           string const & o = string());
+       ///
+       bool operator==(InsetCommandParams const &) const;
+       ///
+       bool operator!=(InsetCommandParams const &) const;
+       ///
+       void read(LyXLex &);
+       /// Parse the command
+       void scanCommand(string const &);
+       ///
+       void write(std::ostream &) const;
+       /// Build the complete LaTeX command
+       string const getCommand() const;
+       ///
+       string const & getCmdName() const { return cmdname; }
+       ///
+       string const & getOptions() const { return options; }
+       ///
+       string const & getContents() const { return contents; }
+       ///
+       void setCmdName(string const & n) { cmdname = n; }
+       ///
+       void setOptions(string const & o) { options = o; }
+       ///
+       void setContents(string const & c) { contents = c; }
+       ///
+       string const getAsString() const;
+       ///
+       void setFromString(string const &);
+private:
+       ///
+       string cmdname;
+       ///
+       string contents;
+       ///
+       string options;
+};
+
+
+#endif