X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FMacroTable.h;h=bc445d43974fef7f7314160a5a8f1f43ad2d4dd3;hb=5fdc577badb1cb133d6a0dc7d831bb1f82576adb;hp=281a522f9fab7d4c9f7a05059874c28ed70926df;hpb=5d48c7ef6a2e7316cda2fb656e7eb06bd7d3cdc1;p=lyx.git diff --git a/src/mathed/MacroTable.h b/src/mathed/MacroTable.h index 281a522f9f..bc445d4397 100644 --- a/src/mathed/MacroTable.h +++ b/src/mathed/MacroTable.h @@ -16,7 +16,6 @@ #include "DocIterator.h" #include "support/docstring.h" -#include "support/types.h" #include #include @@ -28,6 +27,7 @@ class Buffer; class MathData; class MathMacroTemplate; class Paragraph; +class latexkeys; enum MacroType { MacroTypeNewcommand, @@ -35,18 +35,15 @@ enum MacroType { MacroTypeDef }; -/// -class MacroNameSet : public std::set {}; - /// class MacroData { public: /// Constructor to make STL containers happy - MacroData(); + MacroData(Buffer * buf = 0); /// Create lazy MacroData which only queries the macro template when needed - MacroData(Buffer const & buf, DocIterator const & pos); + MacroData(Buffer * buf, DocIterator const & pos); /// Create non-lazy MacroData which directly queries the macro template - MacroData(MathMacroTemplate const & macro); + MacroData(Buffer * buf, MathMacroTemplate const & macro); /// docstring const & definition() const { updateData(); return definition_; } @@ -56,44 +53,51 @@ public: size_t numargs() const { updateData(); return numargs_; } /// replace #1,#2,... by given MathAtom 0,1,.., _including_ the possible /// optional argument - void expand(std::vector const & from, MathData & to) const; + /// \return whether anything was expanded + bool expand(std::vector const & from, MathData & to) const; /// number of optional arguments size_t optionals() const; /// std::vector const & defaults() const; /// - std::string const & requires() const { updateData(); return requires_; } + std::string const requires() const; + /// + bool hidden() const; + /// + docstring const xmlname() const; + /// + char const * MathMLtype() const; /// - std::string & requires() { updateData(); return requires_; } - + latexkeys const * symbol() const { return sym_; } + /// + void setSymbol(latexkeys const * sym) { sym_ = sym; } + /// + DocIterator const & pos() { return pos_; } + /// lock while being drawn to avoid recursions int lock() const { return ++lockCount_; } /// is it being drawn? bool locked() const { return lockCount_ != 0; } /// void unlock() const; - - /// - bool redefinition() const { return redefinition_; } - /// - void setRedefinition(bool redefined) { redefinition_ = redefined; } /// - MacroType type() const { return type_; } + bool redefinition() const { updateData(); return redefinition_; } + /// - MacroType & type() { return type_; } - + MacroType type() const { updateData(); return type_; } + /// output as TeX macro, only works for lazy MacroData!!! - void write(odocstream & os, bool overwriteRedefinition) const; + int write(odocstream & os, bool overwriteRedefinition) const; /// bool operator==(MacroData const & x) const { updateData(); x.updateData(); - return definition_ == x.definition_ + return definition_ == x.definition_ && numargs_ == x.numargs_ && display_ == x.display_ - && requires_ == x.requires_ + && sym_ == x.sym_ && optionals_ == x.optionals_ && defaults_ == x.defaults_; } @@ -109,10 +113,10 @@ private: Buffer const * buffer_; /// The position of the definition in the buffer. /// There is no guarantee it stays valid if the buffer - /// changes. But it (normally) exists only until the + /// changes. But it (normally) exists only until the /// next Buffer::updateMacros call where new MacroData /// objects are created for each macro definition. - /// In the worst case, it is invalidated and the MacroData + /// In the worst case, it is invalidated and the MacroData /// returns its defaults values and the user sees unfolded /// macros. mutable DocIterator pos_; @@ -125,7 +129,7 @@ private: /// mutable docstring display_; /// - mutable std::string requires_; + latexkeys const * sym_; /// mutable size_t optionals_; /// @@ -138,7 +142,13 @@ private: mutable MacroType type_; }; - + +/// +class MacroNameSet : public std::set {}; +/// +class MacroSet : public std::set {}; + + /// A lookup table of macro definitions. /** * This contains a table of "global" macros that are always accessible, @@ -150,15 +160,15 @@ class MacroTable : public std::map { public: /// Parse full "\\def..." or "\\newcommand..." or ... - void insert(docstring const & definition, std::string const &); + iterator insert(Buffer * buf, docstring const & definition); /// Insert pre-digested macro definition - void insert(docstring const & name, MacroData const & data); + iterator insert(docstring const & name, MacroData const & data); /// MacroData const * get(docstring const & name) const; /// void dump(); /// - void getMacroNames(std::set & names) const; + void getMacroNames(std::set & names, bool gethidden) const; /// the global list static MacroTable & globalMacros(); @@ -176,14 +186,14 @@ public: class MacroContext { public: /// construct context for the insets at pos - MacroContext(Buffer const & buf, DocIterator const & pos); - + MacroContext(Buffer const * buf, DocIterator const & pos); + /// Lookup macro MacroData const * get(docstring const & name) const; - + private: /// - Buffer const & buf_; + Buffer const * buf_; /// DocIterator const & pos_; };