+ --lockCount_;
+ LASSERT(lockCount_ >= 0, /**/);
+}
+
+
+void MacroData::queryData(MathMacroTemplate const & macro) const
+{
+ if (queried_)
+ return;
+
+ queried_ = true;
+ definition_ = macro.definition();
+ numargs_ = macro.numArgs();
+ display_ = macro.displayDefinition();
+ redefinition_ = macro.redefinition();
+ type_ = macro.type();
+ optionals_ = macro.numOptionals();
+
+ macro.getDefaults(defaults_);
+}
+
+
+void MacroData::updateData() const
+{
+ if (queried_)
+ return;
+
+ LASSERT(buffer_ != 0, /**/);
+
+ // Try to fix position DocIterator. Should not do anything in theory.
+ pos_.fixIfBroken();
+
+ // find macro template
+ Inset * inset = pos_.nextInset();
+ if (inset == 0 || inset->lyxCode() != MATHMACRO_CODE) {
+ lyxerr << "BUG: No macro template found by MacroData" << endl;
+ return;
+ }
+
+ // query the data from the macro template
+ queryData(static_cast<MathMacroTemplate const &>(*inset));
+}
+
+
+void MacroData::write(odocstream & os, bool overwriteRedefinition) const
+{
+ updateData();
+
+ // find macro template
+ Inset * inset = pos_.nextInset();
+ if (inset == 0 || inset->lyxCode() != MATHMACRO_CODE) {
+ lyxerr << "BUG: No macro template found by MacroData" << endl;
+ return;
+ }
+
+ // output template
+ MathMacroTemplate const & tmpl =
+ static_cast<MathMacroTemplate const &>(*inset);
+ WriteStream wi(os, false, true, false);
+ tmpl.write(wi, overwriteRedefinition);