Move the biblio::CiteEngine enum into bufferparams.h to minimize

dependencies on frontends/controllers/biblio.h.
Small clean up of the existing biblio.h interfaces.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8753 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2004-05-14 13:13:20 +00:00
parent 8424214209
commit ea6a5fe92d
13 changed files with 88 additions and 48 deletions

View File

@ -1,3 +1,10 @@
2004-05-14 Angus Leeming <leeming@lyx.org>
* bufferparams.h: move biblio::CiteEngine enum here to minimize
dependencies on src/frontends/controllers/biblio.h. Define a
CiteEngine_enum wrapper class to enable the enum to be forward
declared.
2004-05-12 Angus Leeming <leeming@lyx.org> 2004-05-12 Angus Leeming <leeming@lyx.org>
* buffer.C: up LYX_FORMAT to 234. * buffer.C: up LYX_FORMAT to 234.

View File

@ -20,8 +20,6 @@
#include "insets/insetquotes.h" #include "insets/insetquotes.h"
#include "frontends/controllers/biblio.h"
#include "support/copied_ptr.h" #include "support/copied_ptr.h"
#include "support/types.h" #include "support/types.h"
@ -39,6 +37,25 @@ class VSpace;
struct Language; struct Language;
namespace biblio {
enum CiteEngine {
ENGINE_BASIC,
ENGINE_NATBIB_AUTHORYEAR,
ENGINE_NATBIB_NUMERICAL,
ENGINE_JURABIB
};
class CiteEngine_enum {
CiteEngine val_;
public:
CiteEngine_enum(CiteEngine val) : val_(val) {}
operator CiteEngine() const{ return val_; }
};
} // namespace biblio
/** Buffer parameters. /** Buffer parameters.
* This class contains all the parameters for this a buffer uses. Some * This class contains all the parameters for this a buffer uses. Some
* work needs to be done on this class to make it nice. Now everything * work needs to be done on this class to make it nice. Now everything

View File

@ -1,3 +1,13 @@
2004-05-14 Angus Leeming <leeming@lyx.org>
* ControlCitation.[Ch]: small changes to use the CiteEngine_enum
wrapper class.
* biblio.[Ch]: move the CiteEngine enum into bufferparams.h to
minimize dependencies on this file.
(getCitationStyle, getCiteCommand): removed. Functionality moved
into the CitationStyle struct.
2004-05-12 Angus Leeming <leeming@lyx.org> 2004-05-12 Angus Leeming <leeming@lyx.org>
* biblio.C (getEngine): reduced to the trivial. * biblio.C (getEngine): reduced to the trivial.

View File

@ -13,6 +13,7 @@
#include "ControlCitation.h" #include "ControlCitation.h"
#include "buffer.h" #include "buffer.h"
#include "bufferparams.h"
using std::string; using std::string;
@ -73,7 +74,7 @@ biblio::InfoMap const & ControlCitation::bibkeysInfo() const
} }
biblio::CiteEngine ControlCitation::getEngine() const biblio::CiteEngine_enum ControlCitation::getEngine() const
{ {
return biblio::getEngine(kernel().buffer()); return biblio::getEngine(kernel().buffer());
} }

View File

@ -14,7 +14,7 @@
#include "ControlCommand.h" #include "ControlCommand.h"
#include "biblio.h" // biblio::InfoMap #include "biblio.h"
/** A controller for Citation dialogs. /** A controller for Citation dialogs.
*/ */
@ -37,7 +37,7 @@ public:
biblio::InfoMap const & bibkeysInfo() const; biblio::InfoMap const & bibkeysInfo() const;
/// ///
biblio::CiteEngine getEngine() const; biblio::CiteEngine_enum getEngine() const;
/// Possible citations based on this key /// Possible citations based on this key
std::vector<std::string> const getCiteStrings(std::string const & key) const; std::vector<std::string> const getCiteStrings(std::string const & key) const;

View File

@ -513,21 +513,21 @@ unsigned int const nCiteStylesUCase =
} // namespace anon } // namespace anon
CitationStyle const getCitationStyle(string const & command) CitationStyle::CitationStyle(string const & command)
: style(CITE), full(false), forceUCase(false)
{ {
if (command.empty()) return CitationStyle(); if (command.empty())
return;
CitationStyle cs;
string cmd = command; string cmd = command;
if (cmd[0] == 'C') { if (cmd[0] == 'C') {
cs.forceUCase = true; forceUCase = true;
cmd[0] = 'c'; cmd[0] = 'c';
} }
size_t n = cmd.size() - 1; string::size_type const n = cmd.size() - 1;
if (cmd[n] == '*') { if (cmd != "cite" && cmd[n] == '*') {
cs.full = true; full = true;
cmd = cmd.substr(0,n); cmd = cmd.substr(0,n);
} }
@ -536,25 +536,23 @@ CitationStyle const getCitationStyle(string const & command)
if (ptr != last) { if (ptr != last) {
size_t idx = ptr - citeCommands; size_t idx = ptr - citeCommands;
cs.style = citeStyles[idx]; style = citeStyles[idx];
} }
return cs;
} }
string const getCiteCommand(CiteStyle command, bool full, bool forceUCase) string const CitationStyle::asLatexStr() const
{ {
string cite = citeCommands[command]; string cite = citeCommands[style];
if (full) { if (full) {
CiteStyle const * last = citeStylesFull + nCiteStylesFull; CiteStyle const * last = citeStylesFull + nCiteStylesFull;
if (std::find(citeStylesFull, last, command) != last) if (std::find(citeStylesFull, last, style) != last)
cite += '*'; cite += '*';
} }
if (forceUCase) { if (forceUCase) {
CiteStyle const * last = citeStylesUCase + nCiteStylesUCase; CiteStyle const * last = citeStylesUCase + nCiteStylesUCase;
if (std::find(citeStylesUCase, last, command) != last) if (std::find(citeStylesUCase, last, style) != last)
cite[0] = 'C'; cite[0] = 'C';
} }
@ -562,13 +560,13 @@ string const getCiteCommand(CiteStyle command, bool full, bool forceUCase)
} }
CiteEngine getEngine(Buffer const & buffer) CiteEngine_enum getEngine(Buffer const & buffer)
{ {
return buffer.params().cite_engine; return buffer.params().cite_engine;
} }
vector<CiteStyle> const getCiteStyles(CiteEngine engine) vector<CiteStyle> const getCiteStyles(CiteEngine_enum const & engine)
{ {
unsigned int nStyles = 0; unsigned int nStyles = 0;
unsigned int start = 0; unsigned int start = 0;

View File

@ -21,14 +21,9 @@ class Buffer;
/** Functions of use to citation and bibtex GUI controllers and views */ /** Functions of use to citation and bibtex GUI controllers and views */
namespace biblio { namespace biblio {
enum CiteEngine { class CiteEngine_enum;
ENGINE_BASIC,
ENGINE_NATBIB_AUTHORYEAR,
ENGINE_NATBIB_NUMERICAL,
ENGINE_JURABIB
};
CiteEngine getEngine(Buffer const &); CiteEngine_enum getEngine(Buffer const &);
enum CiteStyle { enum CiteStyle {
@ -98,10 +93,15 @@ searchKeys(InfoMap const & map,
Direction, Direction,
bool caseSensitive=false); bool caseSensitive=false);
/// Type returned by getCitationStyle, below
struct CitationStyle { struct CitationStyle {
/// ///
CitationStyle() : style(CITE), full(false), forceUCase(false) {} CitationStyle(CiteStyle s = CITE, bool f = false, bool force = false)
: style(s), full(f), forceUCase(force) {}
/// \param latex_str a LaTeX command, "cite", "Citep*", etc
CitationStyle(std::string const & latex_str);
///
std::string const asLatexStr() const;
/// ///
CiteStyle style; CiteStyle style;
/// ///
@ -110,20 +110,9 @@ struct CitationStyle {
bool forceUCase; bool forceUCase;
}; };
/// Given the LaTeX command, return the appropriate CitationStyle
CitationStyle const getCitationStyle(std::string const & command);
/** Returns the LaTeX citation command
User supplies :
The CiteStyle enum,
a flag forcing the full author list,
a flag forcing upper case, e.g. "della Casa" becomes "Della Case"
*/
std::string const getCiteCommand(CiteStyle, bool full, bool forceUCase);
/// Returns a vector of available Citation styles. /// Returns a vector of available Citation styles.
std::vector<CiteStyle> const getCiteStyles(CiteEngine); std::vector<CiteStyle> const getCiteStyles(CiteEngine_enum const &);
/** /**
"Translates" the available Citation Styles into strings for this key. "Translates" the available Citation Styles into strings for this key.

View File

@ -1,3 +1,7 @@
2004-05-14 Angus Leeming <leeming@lyx.org>
* QCitation.C: small changes due to the changes in biblio.h.
2004-05-12 Angus Leeming <leeming@lyx.org> 2004-05-12 Angus Leeming <leeming@lyx.org>
* QDocument.C (apply, update): get, set data with * QDocument.C (apply, update): get, set data with

View File

@ -11,6 +11,7 @@
#include <config.h> #include <config.h>
#include "bufferparams.h"
#include "debug.h" #include "debug.h"
#include "ui/QCitationFindDialogBase.h" #include "ui/QCitationFindDialogBase.h"
#include "QCitationDialog.h" #include "QCitationDialog.h"
@ -55,7 +56,8 @@ void QCitation::apply()
bool const force = dialog_->forceuppercaseCB->isChecked(); bool const force = dialog_->forceuppercaseCB->isChecked();
string const command = string const command =
biblio::getCiteCommand(styles[choice], full, force); biblio::CitationStyle(styles[choice], full, force)
.asLatexStr();
controller().params().setCmdName(command); controller().params().setCmdName(command);
controller().params().setContents(getStringFromVector(citekeys)); controller().params().setContents(getStringFromVector(citekeys));
@ -158,7 +160,7 @@ void QCitation::updateStyle()
// Find the style of the citekeys // Find the style of the citekeys
vector<biblio::CiteStyle> const & styles = vector<biblio::CiteStyle> const & styles =
ControlCitation::getCiteStyles(); ControlCitation::getCiteStyles();
biblio::CitationStyle cs = biblio::getCitationStyle(command); biblio::CitationStyle const cs(command);
vector<biblio::CiteStyle>::const_iterator cit = vector<biblio::CiteStyle>::const_iterator cit =
find(styles.begin(), styles.end(), cs.style); find(styles.begin(), styles.end(), cs.style);

View File

@ -1,3 +1,7 @@
2004-05-14 Angus Leeming <leeming@lyx.org>
* FormCitation.C: small changes due to the changes in biblio.h.
2004-05-12 Angus Leeming <leeming@lyx.org> 2004-05-12 Angus Leeming <leeming@lyx.org>
* FormDocument.[Ch], forms/form_document.fd: get, set data with * FormDocument.[Ch], forms/form_document.fd: get, set data with

View File

@ -19,6 +19,8 @@
#include "xforms_helpers.h" #include "xforms_helpers.h"
#include "xformsBC.h" #include "xformsBC.h"
#include "bufferparams.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include "lyx_forms.h" #include "lyx_forms.h"
@ -69,7 +71,7 @@ void updateStyle(FD_citation * dialog, string command)
// Find the style of the citekeys // Find the style of the citekeys
vector<biblio::CiteStyle> const & styles = vector<biblio::CiteStyle> const & styles =
ControlCitation::getCiteStyles(); ControlCitation::getCiteStyles();
biblio::CitationStyle cs = biblio::getCitationStyle(command); biblio::CitationStyle const cs(command);
vector<biblio::CiteStyle>::const_iterator cit = vector<biblio::CiteStyle>::const_iterator cit =
find(styles.begin(), styles.end(), cs.style); find(styles.begin(), styles.end(), cs.style);
@ -109,7 +111,10 @@ void FormCitation::apply()
bool const force = bool const force =
fl_get_button(dialog_->check_force_uppercase); fl_get_button(dialog_->check_force_uppercase);
command = biblio::getCiteCommand(styles[choice], full, force); command =
biblio::CitationStyle(styles[choice], full, force)
.asLatexStr();
} }
controller().params().setCmdName(command); controller().params().setCmdName(command);

View File

@ -20,6 +20,8 @@
#include "funcrequest.h" #include "funcrequest.h"
#include "LaTeXFeatures.h" #include "LaTeXFeatures.h"
#include "frontends/controllers/biblio.h"
#include "support/lstrings.h" #include "support/lstrings.h"
using lyx::support::ascii_lowercase; using lyx::support::ascii_lowercase;

View File

@ -15,7 +15,8 @@
#include "insetcommand.h" #include "insetcommand.h"
#include "frontends/controllers/biblio.h" #include "bufferparams.h"
/** Used to insert citations /** Used to insert citations
*/ */