2001-02-13 17:08:51 +00:00
|
|
|
// -*- C++ -*-
|
2003-08-19 13:00:56 +00:00
|
|
|
/**
|
2006-09-17 09:14:18 +00:00
|
|
|
* \file MathMacroTable.h
|
2003-08-19 13:00:56 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2007-04-17 16:58:59 +00:00
|
|
|
* \author André Pönitz
|
2003-08-19 13:00:56 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
#ifndef MATH_MACROTABLE_H
|
|
|
|
#define MATH_MACROTABLE_H
|
2001-02-13 17:08:51 +00:00
|
|
|
|
2007-04-17 16:52:43 +00:00
|
|
|
#include "support/docstring.h"
|
|
|
|
|
|
|
|
#include <boost/assert.hpp>
|
|
|
|
|
2007-04-17 16:35:13 +00:00
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2004-04-13 06:27:29 +00:00
|
|
|
class MathArray;
|
2001-03-01 14:07:43 +00:00
|
|
|
|
2004-04-13 06:27:29 +00:00
|
|
|
///
|
|
|
|
class MacroData {
|
2001-02-13 17:08:51 +00:00
|
|
|
public:
|
2001-03-01 14:07:43 +00:00
|
|
|
///
|
2004-04-13 06:27:29 +00:00
|
|
|
MacroData();
|
|
|
|
///
|
2006-11-13 17:35:18 +00:00
|
|
|
MacroData(docstring const & def, int nargs, docstring const & disp, std::string const &);
|
2004-04-13 06:27:29 +00:00
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring def() const { return def_; }
|
2004-04-13 06:27:29 +00:00
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring disp() const { return disp_; }
|
2004-04-13 06:27:29 +00:00
|
|
|
///
|
|
|
|
int numargs() const { return numargs_; }
|
|
|
|
/// replace #1,#2,... by given MathAtom 0,1,..
|
2004-04-13 13:54:58 +00:00
|
|
|
void expand(std::vector<MathArray> const & from, MathArray & to) const;
|
2006-11-13 17:35:18 +00:00
|
|
|
///
|
|
|
|
std::string requires() const { return requires_; }
|
|
|
|
///
|
|
|
|
std::string & requires() { return requires_; }
|
2007-04-17 16:52:43 +00:00
|
|
|
/// lock while being drawn
|
|
|
|
int lock() const { return ++lockCount_; }
|
|
|
|
/// is it being drawn?
|
|
|
|
bool locked() const { return lockCount_ != 0; }
|
|
|
|
///
|
|
|
|
void unlock() const { --lockCount_; BOOST_ASSERT(lockCount_ >= 0); }
|
2007-04-17 16:49:17 +00:00
|
|
|
|
2004-04-13 06:27:29 +00:00
|
|
|
private:
|
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring def_;
|
2004-04-13 06:27:29 +00:00
|
|
|
///
|
|
|
|
int numargs_;
|
2001-03-01 14:07:43 +00:00
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring disp_;
|
2006-11-13 17:35:18 +00:00
|
|
|
///
|
|
|
|
std::string requires_;
|
2007-04-17 16:52:43 +00:00
|
|
|
///
|
|
|
|
mutable int lockCount_;
|
2004-04-13 06:27:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// This contains a table of "global" macros that are always accessible,
|
|
|
|
// either because they implement a feature of standard LaTeX or some
|
|
|
|
// hack to display certain contents nicely.
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
class MacroTable : public std::map<docstring, MacroData>
|
2004-04-13 13:54:58 +00:00
|
|
|
{
|
2004-04-13 06:27:29 +00:00
|
|
|
public:
|
2006-11-13 17:35:18 +00:00
|
|
|
/// Parse full "\\def..." or "\\newcommand..." or ...
|
|
|
|
void insert(docstring const & definition, std::string const &);
|
2004-04-13 06:27:29 +00:00
|
|
|
/// Insert pre-digested macro definition
|
2006-10-22 10:15:23 +00:00
|
|
|
void insert(docstring const & name, MacroData const & data);
|
2004-04-13 06:27:29 +00:00
|
|
|
/// Do we have a macro by that name?
|
2006-10-22 10:15:23 +00:00
|
|
|
bool has(docstring const & name) const;
|
2001-03-01 14:07:43 +00:00
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
MacroData const & get(docstring const & name) const;
|
2002-03-27 11:02:56 +00:00
|
|
|
///
|
2004-04-13 06:27:29 +00:00
|
|
|
void dump();
|
|
|
|
|
|
|
|
/// the global list
|
|
|
|
static MacroTable & globalMacros();
|
2004-04-13 13:54:58 +00:00
|
|
|
/// the local list hack
|
|
|
|
//static MacroTable & localMacros();
|
2001-02-13 17:08:51 +00:00
|
|
|
};
|
2002-07-12 14:24:47 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
2001-02-13 17:08:51 +00:00
|
|
|
#endif
|