From ea6a5fe92db34116130c64ca0ab72e40df80fe16 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Fri, 14 May 2004 13:13:20 +0000 Subject: [PATCH] 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 --- src/ChangeLog | 7 +++++ src/bufferparams.h | 21 ++++++++++++-- src/frontends/controllers/ChangeLog | 10 +++++++ src/frontends/controllers/ControlCitation.C | 3 +- src/frontends/controllers/ControlCitation.h | 4 +-- src/frontends/controllers/biblio.C | 32 ++++++++++----------- src/frontends/controllers/biblio.h | 31 +++++++------------- src/frontends/qt2/ChangeLog | 4 +++ src/frontends/qt2/QCitation.C | 6 ++-- src/frontends/xforms/ChangeLog | 4 +++ src/frontends/xforms/FormCitation.C | 9 ++++-- src/insets/insetcite.C | 2 ++ src/insets/insetcite.h | 3 +- 13 files changed, 88 insertions(+), 48 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 0e1e715b8e..717f3e20a7 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2004-05-14 Angus Leeming + + * 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 * buffer.C: up LYX_FORMAT to 234. diff --git a/src/bufferparams.h b/src/bufferparams.h index 40e82290ac..8951147114 100644 --- a/src/bufferparams.h +++ b/src/bufferparams.h @@ -20,8 +20,6 @@ #include "insets/insetquotes.h" -#include "frontends/controllers/biblio.h" - #include "support/copied_ptr.h" #include "support/types.h" @@ -39,6 +37,25 @@ class VSpace; 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. * 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 diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index e5eedaa636..3544d44e27 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,13 @@ +2004-05-14 Angus Leeming + + * 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 * biblio.C (getEngine): reduced to the trivial. diff --git a/src/frontends/controllers/ControlCitation.C b/src/frontends/controllers/ControlCitation.C index 950478db1d..2770d992fe 100644 --- a/src/frontends/controllers/ControlCitation.C +++ b/src/frontends/controllers/ControlCitation.C @@ -13,6 +13,7 @@ #include "ControlCitation.h" #include "buffer.h" +#include "bufferparams.h" 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()); } diff --git a/src/frontends/controllers/ControlCitation.h b/src/frontends/controllers/ControlCitation.h index 6d8b9e9bd6..260707fb08 100644 --- a/src/frontends/controllers/ControlCitation.h +++ b/src/frontends/controllers/ControlCitation.h @@ -14,7 +14,7 @@ #include "ControlCommand.h" -#include "biblio.h" // biblio::InfoMap +#include "biblio.h" /** A controller for Citation dialogs. */ @@ -37,7 +37,7 @@ public: biblio::InfoMap const & bibkeysInfo() const; /// - biblio::CiteEngine getEngine() const; + biblio::CiteEngine_enum getEngine() const; /// Possible citations based on this key std::vector const getCiteStrings(std::string const & key) const; diff --git a/src/frontends/controllers/biblio.C b/src/frontends/controllers/biblio.C index a6992eb957..8fdc33bd2d 100644 --- a/src/frontends/controllers/biblio.C +++ b/src/frontends/controllers/biblio.C @@ -513,21 +513,21 @@ unsigned int const nCiteStylesUCase = } // 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; - if (cmd[0] == 'C') { - cs.forceUCase = true; + forceUCase = true; cmd[0] = 'c'; } - size_t n = cmd.size() - 1; - if (cmd[n] == '*') { - cs.full = true; + string::size_type const n = cmd.size() - 1; + if (cmd != "cite" && cmd[n] == '*') { + full = true; cmd = cmd.substr(0,n); } @@ -536,25 +536,23 @@ CitationStyle const getCitationStyle(string const & command) if (ptr != last) { 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) { CiteStyle const * last = citeStylesFull + nCiteStylesFull; - if (std::find(citeStylesFull, last, command) != last) + if (std::find(citeStylesFull, last, style) != last) cite += '*'; } if (forceUCase) { CiteStyle const * last = citeStylesUCase + nCiteStylesUCase; - if (std::find(citeStylesUCase, last, command) != last) + if (std::find(citeStylesUCase, last, style) != last) 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; } -vector const getCiteStyles(CiteEngine engine) +vector const getCiteStyles(CiteEngine_enum const & engine) { unsigned int nStyles = 0; unsigned int start = 0; diff --git a/src/frontends/controllers/biblio.h b/src/frontends/controllers/biblio.h index e079c66e01..602ad6b2fc 100644 --- a/src/frontends/controllers/biblio.h +++ b/src/frontends/controllers/biblio.h @@ -21,14 +21,9 @@ class Buffer; /** Functions of use to citation and bibtex GUI controllers and views */ namespace biblio { -enum CiteEngine { - ENGINE_BASIC, - ENGINE_NATBIB_AUTHORYEAR, - ENGINE_NATBIB_NUMERICAL, - ENGINE_JURABIB -}; +class CiteEngine_enum; -CiteEngine getEngine(Buffer const &); +CiteEngine_enum getEngine(Buffer const &); enum CiteStyle { @@ -98,10 +93,15 @@ searchKeys(InfoMap const & map, Direction, bool caseSensitive=false); -/// Type returned by getCitationStyle, below + 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; /// @@ -110,20 +110,9 @@ struct CitationStyle { 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. -std::vector const getCiteStyles(CiteEngine); +std::vector const getCiteStyles(CiteEngine_enum const &); /** "Translates" the available Citation Styles into strings for this key. diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index e0c7819acb..b112b29158 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,7 @@ +2004-05-14 Angus Leeming + + * QCitation.C: small changes due to the changes in biblio.h. + 2004-05-12 Angus Leeming * QDocument.C (apply, update): get, set data with diff --git a/src/frontends/qt2/QCitation.C b/src/frontends/qt2/QCitation.C index 87e0b569cf..0cb80c675e 100644 --- a/src/frontends/qt2/QCitation.C +++ b/src/frontends/qt2/QCitation.C @@ -11,6 +11,7 @@ #include +#include "bufferparams.h" #include "debug.h" #include "ui/QCitationFindDialogBase.h" #include "QCitationDialog.h" @@ -55,7 +56,8 @@ void QCitation::apply() bool const force = dialog_->forceuppercaseCB->isChecked(); string const command = - biblio::getCiteCommand(styles[choice], full, force); + biblio::CitationStyle(styles[choice], full, force) + .asLatexStr(); controller().params().setCmdName(command); controller().params().setContents(getStringFromVector(citekeys)); @@ -158,7 +160,7 @@ void QCitation::updateStyle() // Find the style of the citekeys vector const & styles = ControlCitation::getCiteStyles(); - biblio::CitationStyle cs = biblio::getCitationStyle(command); + biblio::CitationStyle const cs(command); vector::const_iterator cit = find(styles.begin(), styles.end(), cs.style); diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index f02cb5e440..df23702bc7 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,7 @@ +2004-05-14 Angus Leeming + + * FormCitation.C: small changes due to the changes in biblio.h. + 2004-05-12 Angus Leeming * FormDocument.[Ch], forms/form_document.fd: get, set data with diff --git a/src/frontends/xforms/FormCitation.C b/src/frontends/xforms/FormCitation.C index 10c855ac75..f0dc375f0c 100644 --- a/src/frontends/xforms/FormCitation.C +++ b/src/frontends/xforms/FormCitation.C @@ -19,6 +19,8 @@ #include "xforms_helpers.h" #include "xformsBC.h" +#include "bufferparams.h" + #include "support/lstrings.h" #include "lyx_forms.h" @@ -69,7 +71,7 @@ void updateStyle(FD_citation * dialog, string command) // Find the style of the citekeys vector const & styles = ControlCitation::getCiteStyles(); - biblio::CitationStyle cs = biblio::getCitationStyle(command); + biblio::CitationStyle const cs(command); vector::const_iterator cit = find(styles.begin(), styles.end(), cs.style); @@ -109,7 +111,10 @@ void FormCitation::apply() bool const force = 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); diff --git a/src/insets/insetcite.C b/src/insets/insetcite.C index 5d09732bec..203b96b8d1 100644 --- a/src/insets/insetcite.C +++ b/src/insets/insetcite.C @@ -20,6 +20,8 @@ #include "funcrequest.h" #include "LaTeXFeatures.h" +#include "frontends/controllers/biblio.h" + #include "support/lstrings.h" using lyx::support::ascii_lowercase; diff --git a/src/insets/insetcite.h b/src/insets/insetcite.h index 6025d8ecfe..12b8b1d3bb 100644 --- a/src/insets/insetcite.h +++ b/src/insets/insetcite.h @@ -15,7 +15,8 @@ #include "insetcommand.h" -#include "frontends/controllers/biblio.h" +#include "bufferparams.h" + /** Used to insert citations */