2000-07-17 18:27:53 +00:00
|
|
|
|
// -*- C++ -*-
|
2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
|
* \file Counters.h
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
|
* \author John Levon
|
|
|
|
|
* \author Martin Vermeer
|
2000-07-24 13:53:19 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
2000-07-17 18:27:53 +00:00
|
|
|
|
|
|
|
|
|
#ifndef COUNTERS_H
|
2001-02-12 14:09:09 +00:00
|
|
|
|
#define COUNTERS_H
|
2000-07-17 18:27:53 +00:00
|
|
|
|
|
2006-10-20 20:30:00 +00:00
|
|
|
|
#include "support/docstring.h"
|
|
|
|
|
|
2002-05-29 16:21:03 +00:00
|
|
|
|
#include <map>
|
2008-02-23 20:38:57 +00:00
|
|
|
|
#include <set>
|
2002-09-05 12:58:10 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2002-08-07 14:15:06 +00:00
|
|
|
|
/// This represents a single counter.
|
2002-08-06 22:40:59 +00:00
|
|
|
|
class Counter {
|
2000-07-17 18:27:53 +00:00
|
|
|
|
public:
|
|
|
|
|
///
|
|
|
|
|
Counter();
|
|
|
|
|
///
|
2007-08-16 11:07:00 +00:00
|
|
|
|
Counter(docstring const & mc, docstring const & ls,
|
|
|
|
|
docstring const & lsa);
|
|
|
|
|
///
|
2000-07-17 18:27:53 +00:00
|
|
|
|
void set(int v);
|
|
|
|
|
///
|
|
|
|
|
void addto(int v);
|
|
|
|
|
///
|
|
|
|
|
int value() const;
|
|
|
|
|
///
|
|
|
|
|
void step();
|
|
|
|
|
///
|
|
|
|
|
void reset();
|
2007-08-16 14:44:22 +00:00
|
|
|
|
/// Returns the master counter of this counter.
|
2007-08-11 18:23:30 +00:00
|
|
|
|
docstring const & master() const;
|
2007-08-16 14:44:22 +00:00
|
|
|
|
/// Returns a LaTeX-like string to format the counter.
|
|
|
|
|
/* This is similar to what one gets in LaTeX when using
|
|
|
|
|
* "\the<counter>".
|
|
|
|
|
*/
|
2007-08-16 11:07:00 +00:00
|
|
|
|
docstring const & labelString() const;
|
2007-08-16 14:44:22 +00:00
|
|
|
|
/// Returns a LaTeX-like string to format the counter in appendix.
|
|
|
|
|
/* This is similar to what one gets in LaTeX when using
|
|
|
|
|
* "\the<counter>" in an appendix.
|
|
|
|
|
*/
|
2007-08-16 11:07:00 +00:00
|
|
|
|
docstring const & labelStringAppendix() const;
|
2002-08-06 22:40:59 +00:00
|
|
|
|
private:
|
2002-09-05 12:58:10 +00:00
|
|
|
|
///
|
2000-07-17 18:27:53 +00:00
|
|
|
|
int value_;
|
2007-08-16 14:44:22 +00:00
|
|
|
|
/// contains master counter name.
|
|
|
|
|
/* The master counter is the counter that, if stepped
|
|
|
|
|
* (incremented) zeroes this counter. E.g. "subsection"'s
|
|
|
|
|
* master is "section".
|
|
|
|
|
*/
|
2007-08-11 18:23:30 +00:00
|
|
|
|
docstring master_;
|
2007-08-16 14:44:22 +00:00
|
|
|
|
// Contains a LaTeX-like string to format the counter.
|
2007-08-16 11:07:00 +00:00
|
|
|
|
docstring labelstring_;
|
|
|
|
|
// The same as labelstring_, but in appendices.
|
|
|
|
|
docstring labelstringappendix_;
|
2000-07-17 18:27:53 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2002-08-11 20:34:20 +00:00
|
|
|
|
/// This is a class of (La)TeX type counters.
|
2002-08-07 14:15:06 +00:00
|
|
|
|
/// Every instantiation is an array of counters of type Counter.
|
2000-07-17 18:27:53 +00:00
|
|
|
|
class Counters {
|
|
|
|
|
public:
|
2002-08-07 14:15:06 +00:00
|
|
|
|
/// Add a new counter to array.
|
2007-08-11 18:23:30 +00:00
|
|
|
|
void newCounter(docstring const & newc);
|
2007-08-16 11:07:00 +00:00
|
|
|
|
/// Add new counter having oldc as its master and ls as its label.
|
2007-08-11 18:23:30 +00:00
|
|
|
|
void newCounter(docstring const & newc,
|
2007-08-16 11:07:00 +00:00
|
|
|
|
docstring const & masterc,
|
|
|
|
|
docstring const & ls,
|
|
|
|
|
docstring const & lsa);
|
2007-08-16 14:44:22 +00:00
|
|
|
|
/// Checks whether the given counter exists.
|
2007-08-11 18:23:30 +00:00
|
|
|
|
bool hasCounter(docstring const & c) const;
|
2000-07-17 18:27:53 +00:00
|
|
|
|
///
|
2007-08-11 18:23:30 +00:00
|
|
|
|
void set(docstring const & ctr, int val);
|
2000-07-17 18:27:53 +00:00
|
|
|
|
///
|
2007-08-11 18:23:30 +00:00
|
|
|
|
void addto(docstring const & ctr, int val);
|
|
|
|
|
///
|
|
|
|
|
int value(docstring const & ctr) const;
|
2007-08-16 14:44:22 +00:00
|
|
|
|
/// Increment by one counter named by arg, and zeroes slave
|
|
|
|
|
/// counter(s) for which it is the master.
|
|
|
|
|
/* Sub-slaves not zeroed! That happens at slave's first step
|
|
|
|
|
* 0->1. Seems to be sufficient.
|
|
|
|
|
*/
|
2007-08-11 18:23:30 +00:00
|
|
|
|
void step(docstring const & ctr);
|
2002-08-11 20:34:20 +00:00
|
|
|
|
/// Reset all counters.
|
|
|
|
|
void reset();
|
|
|
|
|
/// Reset counters matched by match string.
|
2007-08-11 18:23:30 +00:00
|
|
|
|
void reset(docstring const & match);
|
2002-08-11 20:34:20 +00:00
|
|
|
|
/// Copy counters whose name matches match from the &from to
|
2002-08-07 14:15:06 +00:00
|
|
|
|
/// the &to array of counters. Empty string matches all.
|
2006-10-20 20:30:00 +00:00
|
|
|
|
void copy(Counters & from, Counters & to,
|
2007-08-11 18:23:30 +00:00
|
|
|
|
docstring const & match = docstring());
|
2007-08-16 14:44:22 +00:00
|
|
|
|
/// returns the expanded string representation of the counter.
|
2007-08-16 11:07:00 +00:00
|
|
|
|
docstring theCounter(docstring const & c);
|
2007-08-16 14:44:22 +00:00
|
|
|
|
/// Replace om format all the LaTeX-like macros that depend on
|
|
|
|
|
/// counters.
|
2008-02-23 20:38:57 +00:00
|
|
|
|
docstring counterLabel(docstring const & format,
|
|
|
|
|
std::set<docstring> * callers = 0);
|
2007-08-16 14:44:22 +00:00
|
|
|
|
/// Are we in apendix?
|
2007-07-11 12:52:50 +00:00
|
|
|
|
bool appendix() const { return appendix_; };
|
2007-08-16 14:44:22 +00:00
|
|
|
|
/// Set the state variable indicating whether we are in appendix.
|
2007-07-11 12:52:50 +00:00
|
|
|
|
void appendix(bool a) { appendix_ = a; };
|
2007-08-16 14:44:22 +00:00
|
|
|
|
/// Returns the current enclosing float.
|
2007-08-11 18:23:30 +00:00
|
|
|
|
std::string const & current_float() const { return current_float_; }
|
2007-08-16 14:44:22 +00:00
|
|
|
|
/// Sets the current enclosing float.
|
2007-08-11 18:23:30 +00:00
|
|
|
|
void current_float(std::string const & f) { current_float_ = f; }
|
2008-03-02 11:30:50 +00:00
|
|
|
|
/// Are we in a subfloat?
|
|
|
|
|
bool isSubfloat() const { return subfloat_; }
|
|
|
|
|
/// Set the state variable indicating whether we are in a subfloat.
|
|
|
|
|
void isSubfloat(bool s) { subfloat_ = s; };
|
2000-07-17 18:27:53 +00:00
|
|
|
|
private:
|
2008-02-23 20:38:57 +00:00
|
|
|
|
/// returns the expanded string representation of the counter
|
|
|
|
|
/// with recursion protection through callers.
|
|
|
|
|
docstring theCounter(docstring const & c,
|
|
|
|
|
std::set<docstring> & callers);
|
2007-08-16 14:44:22 +00:00
|
|
|
|
/// Returns the value of the counter according to the
|
|
|
|
|
/// numbering scheme numbertype.
|
|
|
|
|
/* Available numbering schemes are arabic (1, 2,...), roman
|
|
|
|
|
* (i, ii,...), Roman (I, II,...), alph (a, b,...), Alpha (A,
|
|
|
|
|
* B,...) and hebrew.
|
|
|
|
|
*/
|
2007-08-11 18:23:30 +00:00
|
|
|
|
docstring labelItem(docstring const & ctr,
|
2007-08-16 11:07:00 +00:00
|
|
|
|
docstring const & numbertype);
|
2002-08-07 14:15:06 +00:00
|
|
|
|
/// Maps counter (layout) names to actual counters.
|
2007-08-11 18:23:30 +00:00
|
|
|
|
typedef std::map<docstring, Counter> CounterList;
|
2002-08-07 14:15:06 +00:00
|
|
|
|
/// Instantiate.
|
2000-07-17 18:27:53 +00:00
|
|
|
|
CounterList counterList;
|
2007-08-16 14:44:22 +00:00
|
|
|
|
/// Are we in an appendix?
|
2007-07-11 12:52:50 +00:00
|
|
|
|
bool appendix_;
|
2007-08-16 14:44:22 +00:00
|
|
|
|
/// The current enclosing float.
|
2007-08-11 18:23:30 +00:00
|
|
|
|
std::string current_float_;
|
2008-03-02 11:30:50 +00:00
|
|
|
|
/// Are we in a subfloat?
|
|
|
|
|
bool subfloat_;
|
2000-07-17 18:27:53 +00:00
|
|
|
|
};
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
2000-07-17 18:27:53 +00:00
|
|
|
|
#endif
|