File indexing completed on 2024-05-05 03:54:29

0001 /* vi: ts=8 sts=4 sw=4
0002 
0003     This file is part of the KDE project, module kdesu.
0004     SPDX-FileCopyrightText: 1999, 2000 Geert Jansen <jansen@kde.org>
0005 */
0006 
0007 #ifndef __Repo_h_included__
0008 #define __Repo_h_included__
0009 
0010 #include <QByteArray>
0011 #include <QMap>
0012 
0013 /**
0014  * Used internally.
0015  */
0016 struct Data_entry {
0017     QByteArray value;
0018     QByteArray group;
0019     unsigned int timeout;
0020 };
0021 
0022 /**
0023  * String repository.
0024  *
0025  * This class implements a string repository with expiration.
0026  */
0027 class Repository
0028 {
0029 public:
0030     Repository();
0031     ~Repository();
0032 
0033     /** Remove data elements which are expired. */
0034     int expire();
0035 
0036     /** Add a data element */
0037     void add(const QByteArray &key, Data_entry &data);
0038 
0039     /** Delete a data element. */
0040     int remove(const QByteArray &key);
0041 
0042     /** Delete all data entries having the given group.  */
0043     int removeGroup(const QByteArray &group);
0044 
0045     /** Delete all data entries based on key. */
0046     int removeSpecialKey(const QByteArray &key);
0047 
0048     /** Checks for the existence of the specified group. */
0049     int hasGroup(const QByteArray &group) const;
0050 
0051     /** Return a data value.  */
0052     QByteArray find(const QByteArray &key) const;
0053 
0054     /** Returns the key values for the given group. */
0055     QByteArray findKeys(const QByteArray &group, const char *sep = "-") const;
0056 
0057 private:
0058     QMap<QByteArray, Data_entry> repo;
0059     typedef QMap<QByteArray, Data_entry>::Iterator RepoIterator;
0060     typedef QMap<QByteArray, Data_entry>::ConstIterator RepoCIterator;
0061     unsigned head_time;
0062 };
0063 
0064 #endif