]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_macro.h
small cleanup, doxygen, formatting changes
[lyx.git] / src / mathed / math_macro.h
index 7c25643a0cfa13ddf228ea619bebccee5276c37f..f44ac9de5a132f85e9f7c275eb1eda116d02fdf5 100644 (file)
@@ -8,7 +8,7 @@
  *
  *  Dependencies: Mathed
  *
- *  Copyright: (c) 1996, 1997 Alejandro Aguilar Sierra
+ *  Copyright: 1996, 1997 Alejandro Aguilar Sierra
  *
  *   Version: 0.2, Mathed & Lyx project.
  *
 #pragma interface
 #endif
 
-#include "math_defs.h"
-#include "debug.h"
-
-///
-typedef MathParInset * MathParInsetP;
-///
-typedef LyxArrayBase * LyxArrayBaseP;
+#include <vector>
+#include "math_parinset.h"
 
 class MathMacroTemplate;
 
 
-/// This class contains the data for a macro
+/** This class contains the data for a macro
+    \author Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
+    \version November 1996
+ */
 class MathMacro : public MathParInset
 {
- public:
-    /// A macro can only be builded from an existing template
-    MathMacro(MathMacroTemplate *);
-    /// or from another macro.
-    MathMacro(MathMacro *);
+public:
+       /// A macro can only be builded from an existing template
+       explicit
+       MathMacro(MathMacroTemplate *);
+       /// or from another macro.
+       explicit
+       MathMacro(MathMacro *);
        ///
-    ~MathMacro();
-    ///
-    void draw(Painter &, int, int);
-    ///
-    void Metrics();
+       ~MathMacro();
        ///
-    MathedInset * Clone();
+       void draw(Painter &, int, int);
        ///
-    void Write(ostream &);
+       void Metrics();
        ///
-    void Write(string &);
+       MathedInset * Clone();
        ///
-    bool setArgumentIdx(int);
+       void Write(std::ostream &, bool fragile);
        ///
-    int  getArgumentIdx();
+       bool setArgumentIdx(int);
        ///
-    int  getMaxArgumentIdx();
+       int getArgumentIdx() const;
        ///
-    int GetColumns();
+       int getMaxArgumentIdx() const;
        ///
-    void GetXY(int &, int &) const;
+       int GetColumns() const;
        ///
-    void SetFocus(int, int);
+       void GetXY(int &, int &) const;
        ///
-    LyxArrayBase * GetData();
+       void SetFocus(int, int);
        ///
-    MathedRowSt * getRowSt() const { return args[idx].row; }
+       MathedArray * GetData();
        ///
-    void SetData(LyxArrayBase *);
+       MathedRowSt * getRowSt() const;
        ///
-    MathedTextCodes getTCode() { return tcode; }
+       void setData(MathedArray *);
        ///
-    bool Permit(short);
-    
- private:
+       MathedTextCodes getTCode() const;
        ///
-       MathMacroTemplate * tmplate;
+       bool Permit(short) const;
+private:
+       ///
+       MathMacroTemplate * tmplate_;
        ///
        struct MacroArgumentBase {
                /// Position of the macro
-               int x, y;
+               int x;
+               ///
+               int y;
                ///
                MathedRowSt * row;
                ///
-               LyxArrayBase * array;
+               MathedArray * array;
                ///
-               MacroArgumentBase() { x = y = 0;  array = 0; row = 0; }
+               MacroArgumentBase()
+                       : x(0), y(0), row(0), array(0)
+                       {}
        };
-       MacroArgumentBase * args;
-       ///
-       int idx;
-       ///
-       int nargs;
-       ///
-       MathedTextCodes tcode;
-       ///
-       friend class MathMacroTemplate;
-};
-
-
-/// An argument
-class MathMacroArgument: public MathParInset
-{
- public:
-    ///
-    MathMacroArgument() { expnd_mode = false; number = 1;  SetType(LM_OT_MACRO_ARG); }
-    ///
-    MathMacroArgument(int);
-    ///
-       ~MathMacroArgument() { lyxerr << "help, destroyme!" << endl; }
-    ///
-    MathedInset * Clone() { return this; }
-       ///
-    void Metrics();
-       ///
-    void draw(Painter &, int x, int baseline);
-       ///
-    void Write(ostream &);
+       std::vector<MacroArgumentBase> args_;
        ///
-    void Write(string &);
-    ///
-    void setNumber(int n) { number = n; }
-    /// Is expanded or not
-    void setExpand(bool e) { expnd_mode = e; }
-    /// Is expanded or not
-    bool getExpand() { return expnd_mode; }
-    
- private:
+       int idx_;
        ///
-    bool expnd_mode;
+       int nargs_;
        ///
-    int number;
+       MathedTextCodes tcode_;
 };
-
-
-/// This class contains the macro definition
-class MathMacroTemplate: public MathParInset
-{
- public:
-    /// A template constructor needs all the data
-    MathMacroTemplate(char const *, int na = 0, int f = 0);
-       ///
-    ~MathMacroTemplate();
-       ///
-    void draw(Painter &, int, int);
-       ///
-    void Metrics();
-       ///
-    void WriteDef(ostream &);
-       ///
-    void WriteDef(string &); 
-    /// useful for special insets
-    void  setTCode(MathedTextCodes t) { tcode = t; }
-    ///
-    MathedTextCodes getTCode() { return tcode; }
-    /// 
-    void setArgument(LyxArrayBase *, int i= 0);
-    /// Number of arguments
-    int getNoArgs() { return nargs; }
-    ///
-    void GetMacroXY(int, int &, int &) const;
-    ///
-    MathParInset * getMacroPar(int) const;
-    ///
-    void SetMacroFocus(int &, int, int);
-       ///
-    void setEditMode(bool);
-
-    /// Replace the appropriate arguments with a specific macro's data
-    void update(MathMacro * m = 0);
-      
- private:
-    ///
-    short flags;
-    ///
-    MathedTextCodes tcode;
-    ///
-    MathMacroArgument * args;
-    ///
-    int nargs;
-    ///
-    friend class MathMacro;
-};
-     
-
-///
-typedef MathMacro * MathMacroP;
-///
-typedef MathMacroTemplate * MathMacroTemplateP;
-
-///
-class MathMacroTable 
-{
- public:
-       ///
-    MathMacroTable(int);
-       ///
-    ~MathMacroTable();
-       ///
-    void addTemplate(MathMacroTemplate *);
-       ///
-    MathMacro * getMacro(char const *) const;
-       ///
-    MathMacroTemplate * getTemplate(char const *) const;
-       ///
-    void builtinMacros();
-       ///
-    static MathMacroTable mathMTable;
-       ///
-    static bool built;
-    
- private:
-       ///
-    const int max_macros;
-       ///
-    int num_macros;
-       ///
-    MathMacroTemplateP * macro_table;
-};
-
-
-
-/*-----------------------  inlines  -------------------------*/
-
-inline
-bool MathMacro::setArgumentIdx(int i)
-{
-    if (i >= 0 && i < nargs) {
-       idx = i;
-       return true;
-    } else
-      return false;
-}
-
-inline
-int  MathMacro::getArgumentIdx() 
-{ 
-    return idx; 
-}
-
-inline
-int  MathMacro::getMaxArgumentIdx() 
-{ 
-    return nargs - 1; 
-} 
-
-
-inline
-LyxArrayBase * MathMacro::GetData() 
-{ 
-    return args[idx].array; 
-} 
-
-
-inline
-void MathMacro::SetData(LyxArrayBase * a)
-{
-   args[idx].array = a;
-}
-
-
-inline 
-MathMacro * MathMacroTable::getMacro(char const * name) const
- {
-     MathMacroTemplate * mt = getTemplate(name);
-     return (mt) ? new MathMacro(mt): 0;
- }
-
-
 #endif