sptk2 logo
SPTK Home Page
FieldList.h
1/*
2╔══════════════════════════════════════════════════════════════════════════════╗
3║ SIMPLY POWERFUL TOOLKIT (SPTK) ║
4╟──────────────────────────────────────────────────────────────────────────────╢
5║ copyright © 1999-2022 Alexey Parshin. All rights reserved. ║
6║ email alexeyp@gmail.com ║
7╚══════════════════════════════════════════════════════════════════════════════╝
8┌──────────────────────────────────────────────────────────────────────────────┐
9│ This library is free software; you can redistribute it and/or modify it │
10│ under the terms of the GNU Library General Public License as published by │
11│ the Free Software Foundation; either version 2 of the License, or (at your │
12│ option) any later version. │
13│ │
14│ This library is distributed in the hope that it will be useful, but │
15│ WITHOUT ANY WARRANTY; without even the implied warranty of │
16│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library │
17│ General Public License for more details. │
18│ │
19│ You should have received a copy of the GNU Library General Public License │
20│ along with this library; if not, write to the Free Software Foundation, │
21│ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. │
22│ │
23│ Please report all bugs and problems to alexeyp@gmail.com. │
24└──────────────────────────────────────────────────────────────────────────────┘
25*/
26
27#pragma once
28
29#include <map>
30#include <sptk5/CaseInsensitiveCompare.h>
31#include <sptk5/Field.h>
32#include <sptk5/xdoc/Node.h>
33#include <vector>
34
35namespace sptk {
36
49class SP_EXPORT FieldList
50{
51public:
55 using iterator = std::vector<SField>::iterator;
56
60 using const_iterator = std::vector<SField>::const_iterator;
61
62
69 explicit FieldList(bool indexed);
70
76 FieldList(const FieldList& other) = delete;
77
83 FieldList(FieldList&& other) noexcept = default;
84
90 FieldList& operator=(const FieldList& other) = delete;
91
97 FieldList& operator=(FieldList&& other) noexcept = default;
98
102 void clear();
103
107 size_t size() const
108 {
109 return m_list.size();
110 }
111
116 {
117 return m_list.begin();
118 }
119
124 {
125 return m_list.begin();
126 }
127
132 {
133 return m_list.end();
134 }
135
140 {
141 return m_list.end();
142 }
143
152 Field& push_back(const String& fname, bool checkDuplicates);
153
162 Field& push_back(const SField& fld);
163
171 SField findField(const String& fname) const;
172
180 SField fieldByName(const String& fname) const
181 {
182 auto field = findField(fname);
183 if (!field)
184 {
185 throw Exception("Field name '" + String(fname) + "' not found");
186 }
187 return field;
188 }
189
196 Field& operator[](int index)
197 {
198 return *m_list[index];
199 }
200
207 const Field& operator[](int index) const
208 {
209 return *m_list[index];
210 }
211
217 Field& operator[](const String& fname)
218 {
219 return *fieldByName(fname);
220 }
221
227 const Field& operator[](const String& fname) const
228 {
229 return *fieldByName(fname.c_str());
230 }
231
241 void exportTo(const xdoc::SNode& node, bool compactMode, bool nullLargeData = false) const;
242
243private:
247 using Vector = std::vector<SField>;
248
252 using Map = std::map<String, SField, CaseInsensitiveCompare>;
253
254 Vector m_list;
255 std::shared_ptr<Map> m_index;
256
262 void assign(const FieldList& other);
263};
264
265} // namespace sptk
266
SPTK generic exception class.
Definition: Exception.h:56
Definition: FieldList.h:50
Definition: Field.h:54
Definition: String.h:49
SField fieldByName(const String &fname) const
Definition: FieldList.h:180
FieldList & operator=(const FieldList &other)=delete
SField findField(const String &fname) const
std::vector< SField >::iterator iterator
Definition: FieldList.h:55
std::vector< SField >::const_iterator const_iterator
Definition: FieldList.h:60
const_iterator end() const
Definition: FieldList.h:139
const Field & operator[](int index) const
Definition: FieldList.h:207
const_iterator begin() const
Definition: FieldList.h:123
iterator end()
Definition: FieldList.h:131
FieldList(const FieldList &other)=delete
FieldList & operator=(FieldList &&other) noexcept=default
FieldList(bool indexed)
size_t size() const
Definition: FieldList.h:107
Field & operator[](int index)
Definition: FieldList.h:196
FieldList(FieldList &&other) noexcept=default
Field & push_back(const String &fname, bool checkDuplicates)
void exportTo(const xdoc::SNode &node, bool compactMode, bool nullLargeData=false) const
Field & operator[](const String &fname)
Definition: FieldList.h:217
Field & push_back(const SField &fld)
iterator begin()
Definition: FieldList.h:115
const Field & operator[](const String &fname) const
Definition: FieldList.h:227

Fri Oct 14 2022 09:58:31: SPTK 5.4.1