File indexing completed on 2024-05-19 05:05:20

0001 /***************************************************************************
0002  *   SPDX-License-Identifier: GPL-2.0-or-later
0003  *                                                                         *
0004  *   SPDX-FileCopyrightText: 2004-2019 Thomas Fischer <fischer@unix-ag.uni-kl.de>
0005  *                                                                         *
0006  *   This program is free software; you can redistribute it and/or modify  *
0007  *   it under the terms of the GNU General Public License as published by  *
0008  *   the Free Software Foundation; either version 2 of the License, or     *
0009  *   (at your option) any later version.                                   *
0010  *                                                                         *
0011  *   This program is distributed in the hope that it will be useful,       *
0012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0014  *   GNU General Public License for more details.                          *
0015  *                                                                         *
0016  *   You should have received a copy of the GNU General Public License     *
0017  *   along with this program; if not, see <https://www.gnu.org/licenses/>. *
0018  ***************************************************************************/
0019 
0020 #ifndef KBIBTEX_DATA_MACRO_H
0021 #define KBIBTEX_DATA_MACRO_H
0022 
0023 #include <Element>
0024 #include <Value>
0025 
0026 class QString;
0027 
0028 #ifdef HAVE_KF
0029 #include "kbibtexdata_export.h"
0030 #endif // HAVE_KF
0031 
0032 /**
0033  * This class represents a macro in a BibTeX file. Macros in BibTeX
0034  * are similar to variables, allowing to use the same value such as
0035  * journal titles in several entries.
0036  * @author Thomas Fischer <fischer@unix-ag.uni-kl.de>
0037  */
0038 class KBIBTEXDATA_EXPORT Macro : public Element
0039 {
0040 public:
0041     /**
0042      * Create a new macro with a given key-value pair.
0043      * @param key macro's key
0044      * @param value macro's value
0045      */
0046     explicit Macro(const QString &key = QString(), const Value &value = Value());
0047 
0048     /**
0049      * Copy constructor cloning another macro object.
0050      * @param other macro object to clone
0051      */
0052     Macro(const Macro &other);
0053 
0054     ~Macro() override;
0055 
0056     bool operator==(const Macro &other) const;
0057     bool operator!=(const Macro &other) const;
0058 
0059     /**
0060      * Assignment operator, working similar to a copy constructor,
0061      * but overwrites the current object's values.
0062      */
0063     Macro &operator= (const Macro &other);
0064 
0065     /**
0066      * Set the key of this macro.
0067      * @param key new key of this macro
0068      */
0069     void setKey(const QString &key);
0070 
0071     /**
0072      * Retrieve the key of this macro.
0073      * @return key of this macro
0074      */
0075     QString key() const;
0076 
0077     /**
0078      * Retrieve the key of this macro. Returns a reference which may not be modified.
0079      * @return key of this macro
0080      */
0081     const Value &value() const;
0082 
0083     /**
0084      * Retrieve the key of this macro. Returns a reference which may be modified.
0085      * @return key of this macro
0086      */
0087     Value &value();
0088 
0089     /**
0090      * Set the value of this macro.
0091      * @param value new value of this macro
0092      */
0093     void setValue(const Value &value);
0094 
0095     /**
0096      * Cheap and fast test if another Element is a Macro object.
0097      * @param other another Element object to test
0098      * @return true if Element is actually a Macro
0099      */
0100     static bool isMacro(const Element &other);
0101 
0102 private:
0103     class MacroPrivate;
0104     MacroPrivate *const d;
0105 };
0106 
0107 KBIBTEXDATA_EXPORT QDebug operator<<(QDebug dbg, const Macro &macro);
0108 
0109 #endif