CPPMyth
Library to interoperate with MythTV server
Loading...
Searching...
No Matches
wsheader.h
1/*
2 * Copyright (C) 2026 Jean-Luc Barriere
3 *
4 * This library is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published
6 * by the Free Software Foundation; either version 3, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; see the file COPYING. If not, write to
16 * the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 */
21
22#ifndef WSHEADER_H
23#define WSHEADER_H
24
25#include "local_config.h"
26
27#include <string>
28#include <vector>
29#include <cctype>
30#include <algorithm>
31
32namespace NSROOT
33{
34
35class WSHeader
36{
37public:
38 typedef std::vector<std::string> container_t;
39 typedef container_t::iterator iterator;
40 typedef container_t::const_iterator const_iterator;
41
42 WSHeader()
43 : m_name()
44 {
45 m_values.emplace_back(std::string());
46 }
47
48 explicit WSHeader(const std::string& name)
49 : m_name(name)
50 {
51 m_values.emplace_back(std::string());
52 }
53
54 WSHeader(const std::string& name, const std::string& value)
55 : m_name(name)
56 {
57 m_values.emplace_back(value);
58 }
59
60 explicit WSHeader(const WSHeader& o)
61 : m_name(o.m_name), m_values(o.m_values)
62 { }
63
64 virtual ~WSHeader() { }
65
66 void SetName(const std::string& name) { m_name.assign(name); }
67 void SetName(const char * buf, size_t n) { m_name.assign(buf, n); }
68
69 std::string Key() const
70 {
71 std::string key(m_name);
72 std::transform(key.begin(), key.end(), key.begin(), ::toupper);
73 return key;
74 }
75
76 const std::string& Name() const { return m_name; }
77 const std::string& Last() const { return m_values.back(); }
78 std::string& Back() { return m_values.back(); }
79
80 iterator begin() { return m_values.begin(); }
81 iterator end() { return m_values.end(); }
82 const_iterator cbegin() { return m_values.cbegin(); }
83 const_iterator cend() { return m_values.cend(); }
84
85 void AddValue(const std::string& value)
86 {
87 if (m_values.back().empty())
88 m_values.back().assign(value);
89 else
90 m_values.emplace_back(value);
91 }
92
93 void SetValue(const std::string& value)
94 {
95 m_values.clear();
96 m_values.emplace_back(value);
97 }
98
99 void MergeValue(const std::string& value)
100 {
101 if (m_values.back().empty())
102 m_values.back().assign(value);
103 else
104 m_values.back().append(",").append(value);
105 }
106
107private:
108 std::string m_name;
109 container_t m_values;
110};
111
112}
113
114#endif /* WSHEADER_H */
115