"Fossies" - the Fresh Open Source Software Archive

Member "cb2bib-2.0.1/src/c2b/documentContents.h" (12 Feb 2021, 2170 Bytes) of package /linux/privat/cb2bib-2.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "documentContents.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.0.0_vs_2.0.1.

    1 /***************************************************************************
    2  *   Copyright (C) 2004-2021 by Pere Constans
    3  *   constans@molspaces.com
    4  *   cb2Bib version 2.0.1. Licensed under the GNU GPL version 3.
    5  *   See the LICENSE file that comes with this distribution.
    6  ***************************************************************************/
    7 #ifndef DOCUMENTCONTENTS_H
    8 #define DOCUMENTCONTENTS_H
    9 
   10 #include "cb2bib_utilities.h"
   11 
   12 #include <QHash>
   13 #include <QString>
   14 
   15 
   16 class documentContents
   17 {
   18 
   19 public:
   20     enum Type
   21     {
   22         Simplified,
   23         Complete
   24     };
   25 
   26     inline const QString& signature() const
   27     {
   28         if (!_is_signature_loaded)
   29         {
   30             _signature = c2bUtils::byteArrayToString(_cache.value(_signature_key));
   31             _is_signature_loaded = true;
   32         }
   33         return _signature;
   34     }
   35 
   36     inline const QString& text() const
   37     {
   38         if (!_is_text_loaded)
   39         {
   40             if (_type == Simplified)
   41                 _text = c2bUtils::toAscii(c2bUtils::decompressString(_cache.value(_text_key)), c2bUtils::KeepWords);
   42             else
   43                 _text = c2bUtils::decompressString(_cache.value(_text_key));
   44             _is_text_loaded = true;
   45         }
   46         return _text;
   47     }
   48 
   49 
   50 private:
   51     inline explicit documentContents(const QHash<QString, QByteArray>& cache)
   52         : _type(Complete), _cache(cache), _is_signature_loaded(false), _is_text_loaded(false) {}
   53     inline ~documentContents() {}
   54 
   55 
   56     inline void clear()
   57     {
   58         _is_signature_loaded = false;
   59         _is_text_loaded = false;
   60         _signature.clear();
   61         _signature_key.clear();
   62         _text.clear();
   63         _text_key.clear();
   64     }
   65 
   66     inline void preload(const QString& skey, const QString& tkey, const Type type)
   67     {
   68         clear();
   69         _signature_key = skey;
   70         _text_key = tkey;
   71         _type = type;
   72     }
   73 
   74     QString _signature_key;
   75     QString _text_key;
   76     Type _type;
   77     const QHash<QString, QByteArray>& _cache;
   78     mutable QString _signature;
   79     mutable QString _text;
   80     mutable bool _is_signature_loaded;
   81     mutable bool _is_text_loaded;
   82 
   83     friend class documentCache;
   84 };
   85 
   86 #endif