Line data Source code
1 : // Copyright (c) 2011-2022 Made to Order Software Corp. All Rights Reserved
2 : //
3 : // https://snapwebsites.org/project/edhttp
4 : // contact@m2osw.com
5 : //
6 : // This program is free software: you can redistribute it and/or modify
7 : // it under the terms of the GNU General Public License as published by
8 : // the Free Software Foundation, either version 3 of the License, or
9 : // (at your option) any later version.
10 : //
11 : // This program is distributed in the hope that it will be useful,
12 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : // GNU General Public License for more details.
15 : //
16 : // You should have received a copy of the GNU General Public License
17 : // along with this program. If not, see <https://www.gnu.org/licenses/>.
18 : #pragma once
19 :
20 : // C++
21 : //
22 : #include <map>
23 : #include <string>
24 : #include <vector>
25 :
26 :
27 :
28 : namespace edhttp
29 : {
30 :
31 :
32 420 : class string_part
33 : {
34 : public:
35 : typedef float level_t;
36 : typedef std::vector<string_part> vector_t; // do NOT use a map, we want to keep them in order!
37 :
38 : // an authoritative document at the IANA clearly says that
39 : // the default level (quality value) is 1.0f.
40 : //
41 110 : static level_t constexpr DEFAULT_LEVEL() { return 1.0f; }
42 :
43 28 : static level_t constexpr UNDEFINED_LEVEL() { return -1.0f; }
44 :
45 : string_part();
46 : string_part(std::string const & name);
47 :
48 : std::string const & get_name() const;
49 : std::string const & get_value() const; // in case the first name has a "name=value" part
50 : void set_value(std::string const & value);
51 : level_t get_level() const;
52 : void set_level(level_t const level);
53 : std::string get_parameter(std::string const & name) const;
54 : void add_parameter(std::string const & name, std::string const & value);
55 : std::string to_string() const;
56 :
57 : bool operator < (string_part const & rhs) const;
58 :
59 : private:
60 : typedef std::map<std::string, std::string> parameters_t;
61 :
62 : std::string f_name = std::string();
63 : std::string f_value = std::string();
64 70 : level_t f_level = DEFAULT_LEVEL(); // i.e. q=0.8
65 : // TODO add support for any other parameter
66 : parameters_t f_param = parameters_t();
67 : };
68 :
69 :
70 : } // namespace edhttp
71 : // vim: ts=4 sw=4 et
|