-
Notifications
You must be signed in to change notification settings - Fork 28
/
TagAtts.h
80 lines (69 loc) · 2.56 KB
/
TagAtts.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/************************************************************************
**
** Copyright (C) 2024 Kevin B. Hendricks, Stratford Ontario Canada
**
** This file is part of PageEdit.
**
** PageEdit is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** PageEdit is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with PageEdit. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#pragma once
#ifndef TAGATTS_H
#define TAGATTS_H
#include <QObject>
#include <QString>
#include <QHash>
// implement a very simple ordered hash for tag attributes by using a qhash to store
// key to node mappings where each node (see struct TAttribute) is a key/value pair in
// a circular doubly-linked list.
// both key and value are QStrings
class TagAtts : public QObject
{
Q_OBJECT
public:
/**
* Constructor.
*/
TagAtts();
TagAtts(const TagAtts &other);
TagAtts& operator=(const TagAtts &other);
bool operator==(const TagAtts &other);
bool operator!=(const TagAtts &other);
QString& operator[](const QString &key);
const QString operator[](const QString &key) const noexcept;
~TagAtts();
struct TAttribute {
QString key;
QString value;
struct TAttribute * prev;
struct TAttribute * next;
TAttribute(const QString &akey, const QString &avalue): key(akey), value(avalue) { prev = nullptr; next=nullptr; };
~TAttribute() { prev=nullptr; next=nullptr; }
};
void insert(const QString &key, const QString &value);
void remove(const QString &key);
QString value(const QString &key, const QString &altvalue="") const;
bool contains(const QString &key) { return m_mapping.contains(key); }
bool isEmpty() { return m_n == 0; }
unsigned int size() const { return m_n; }
QStringList keys() const;
QStringList values() const;
QList< std::pair< QString,QString > > pairs() const;
private:
unsigned int m_n;
QHash<QString, TAttribute*> m_mapping;
// anchor for the circular doubly linked list
TAttribute* m_anchor;
};
#endif // TAGATTS_H