File indexing completed on 2025-03-09 03:57:05

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2009-09-14
0007  * Description : a parse results map for token management
0008  *
0009  * SPDX-FileCopyrightText: 2009-2012 by Andi Clemens <andi dot clemens at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #ifndef DIGIKAM_PARSE_RESULTS_H
0016 #define DIGIKAM_PARSE_RESULTS_H
0017 
0018 // Qt includes
0019 
0020 #include <QPair>
0021 #include <QString>
0022 #include <QMultiMap>
0023 
0024 namespace Digikam
0025 {
0026 
0027 class ParseResults
0028 {
0029 public:
0030 
0031     typedef QPair<int, int>                     ResultsKey;
0032     typedef QPair<QString, QString>             ResultsValue;
0033     typedef QMultiMap<ResultsKey, ResultsValue> ResultsMap;
0034 
0035 public:
0036 
0037     explicit ParseResults()
0038     {
0039     };
0040 
0041     ~ParseResults()
0042     {
0043     };
0044 
0045     void addEntry(const ResultsKey& key, const ResultsValue& value);
0046     void deleteEntry(const ResultsKey& key);
0047 
0048     QList<ResultsKey>   keys()                              const;
0049     QList<ResultsValue> values()                            const;
0050 
0051     bool       hasKey(const ResultsKey& key);
0052 
0053     QString    result(const ResultsKey& key)                const;
0054     QString    token(const ResultsKey& key)                 const;
0055 
0056     int        offset(const ResultsKey& key)                const;
0057 
0058     ResultsKey keyAtPosition(int pos)                       const;
0059     bool       hasKeyAtPosition(int pos)                    const;
0060 
0061     ResultsKey keyAtApproximatePosition(int pos)            const;
0062     bool       hasKeyAtApproximatePosition(int pos)         const;
0063 
0064     bool       isEmpty()                                    const;
0065 
0066     void       append(const ParseResults &results);
0067     void       clear();
0068 
0069     QString    replaceTokens(const QString& markedString)   const;
0070 
0071     QString    resultValuesAsString()                       const;
0072 
0073     void       debug()                                      const;
0074 
0075 private:
0076 
0077     ResultsKey createInvalidKey()                           const;
0078     bool       keyIsValid(const ResultsKey& key)            const;
0079 
0080 private:
0081 
0082     ResultsMap  m_results;
0083 };
0084 
0085 } // namespace Digikam
0086 
0087 #endif // DIGIKAM_PARSE_RESULTS_H