Qpid Proton C++ 0.33.0
map.hpp
Go to the documentation of this file.
1#ifndef PROTON_MAP_HPP
2#define PROTON_MAP_HPP
3
4/*
5 *
6 * Licensed to the Apache Software Foundation (ASF) under one
7 * or more contributor license agreements. See the NOTICE file
8 * distributed with this work for additional information
9 * regarding copyright ownership. The ASF licenses this file
10 * to you under the Apache License, Version 2.0 (the
11 * "License"); you may not use this file except in compliance
12 * with the License. You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing,
17 * software distributed under the License is distributed on an
18 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 * KIND, either express or implied. See the License for the
20 * specific language governing permissions and limitations
21 * under the License.
22 *
23 */
24
25#include "./value.hpp"
26#include "./internal/pn_unique_ptr.hpp"
27
28#include <cstddef>
29
32
33namespace proton {
34
35namespace codec {
36class decoder;
37class encoder;
38}
39
40template <class K, class T>
41class map_type_impl;
42
43template <class K, class T>
44class map;
45
47template <class K, class T>
50template <class K, class T>
53template <class K, class T>
54PN_CPP_EXTERN void swap(map<K,T>&, map<K,T>&);
55
66template <class K, class T>
67class PN_CPP_CLASS_EXTERN map {
68 template <class M, class U=void>
69 struct assignable_map :
70 public internal::enable_if<codec::is_encodable_map<M,K,T>::value, U> {};
71
72 public:
74 PN_CPP_EXTERN map();
75
77 PN_CPP_EXTERN map(const map&);
78
80 PN_CPP_EXTERN map& operator=(const map&);
81
82#if PN_CPP_HAS_RVALUE_REFERENCES
84 PN_CPP_EXTERN map(map&&);
85
87 PN_CPP_EXTERN map& operator=(map&&);
88#endif
89 PN_CPP_EXTERN ~map();
90
93 template <class M>
94 typename assignable_map<M, map&>::type operator=(const M& x) { value(x); return *this; }
95
100 PN_CPP_EXTERN void value(const value& x);
101
103 PN_CPP_EXTERN proton::value& value();
104
106 PN_CPP_EXTERN const proton::value& value() const;
107
110 PN_CPP_EXTERN T get(const K& k) const;
111
113 PN_CPP_EXTERN void put(const K& k, const T& v);
114
116 PN_CPP_EXTERN size_t erase(const K& k);
117
119 PN_CPP_EXTERN bool exists(const K& k) const;
120
122 PN_CPP_EXTERN size_t size() const;
123
125 PN_CPP_EXTERN void clear();
126
128 PN_CPP_EXTERN bool empty() const;
129
131 explicit map(pn_data_t*);
132 void reset(pn_data_t*);
134
135 private:
136 typedef map_type_impl<K,T> map_type;
137 mutable internal::pn_unique_ptr<map_type> map_;
138 mutable proton::value value_;
139
140 map_type& cache() const;
141 proton::value& flush() const;
142
144 friend PN_CPP_EXTERN proton::codec::decoder& operator>> <>(proton::codec::decoder&, map&);
145 friend PN_CPP_EXTERN proton::codec::encoder& operator<< <>(proton::codec::encoder&, const map&);
146 friend PN_CPP_EXTERN void swap<>(map&, map&);
148};
149
150} // proton
151
152#endif // PROTON_MAP_HPP
Unsettled API - A stream-like decoder from AMQP bytes to C++ values.
Definition: decoder.hpp:56
Unsettled API - A stream-like encoder from C++ values to AMQP bytes.
Definition: encoder.hpp:50
A collection of key-value pairs.
Definition: map.hpp:67
size_t size() const
Get the number of map entries.
const proton::value & value() const
Access as a proton::value containing an AMQP map.
proton::value & value()
Access as a proton::value containing an AMQP map.
assignable_map< M, map & >::type operator=(const M &x)
Type-safe assign from a compatible map, for instance std::map<K,T>.
Definition: map.hpp:94
map & operator=(map &&)
Move a map.
bool empty() const
True if the map has no entries.
map()
Construct an empty map.
map(map &&)
Move a map.
size_t erase(const K &k)
Erase the map entry at k.
T get(const K &k) const
Get the map entry for key k.
map(const map &)
Copy a map.
map & operator=(const map &)
Copy a map.
void put(const K &k, const T &v)
Put a map entry for key k.
void clear()
Remove all map entries.
void value(const value &x)
Copy from a proton::value.
bool exists(const K &k) const
True if the map has an entry for k.
A holder for any AMQP value, simple or complex.
Definition: value.hpp:57
The main Proton namespace.
Definition: annotation_key.hpp:33
std::ostream & operator<<(std::ostream &, const binary &)
Print a binary value.
void swap(map< K, T > &, map< K, T > &)
Swap proton::map instances.
proton::codec::decoder & operator>>(proton::codec::decoder &d, map< K, T > &m)
Decode from a proton::map.
A holder for any AMQP value, simple or complex.