Qpid Proton C++ API  0.37.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 
27 #include <cstddef>
28 #include <initializer_list>
29 #include <map>
30 #include <memory>
31 
34 
35 namespace proton {
36 
37 namespace codec {
38 class decoder;
39 class encoder;
40 }
41 
42 template <class K, class T>
43 class map_type_impl;
44 
45 template <class K, class T>
46 class map;
47 
49 template <class K, class T>
52 template <class K, class T>
55 template <class K, class T>
56 PN_CPP_EXTERN void swap(map<K,T>&, map<K,T>&);
57 
68 template <class K, class T>
69 class PN_CPP_CLASS_EXTERN map {
70  template <class M, class U=void>
71  struct assignable_map :
72  public std::enable_if<codec::is_encodable_map<M,K,T>::value, U> {};
73 
74  public:
76  PN_CPP_EXTERN map();
77 
79  PN_CPP_EXTERN map(const map&);
80 
82  PN_CPP_EXTERN map& operator=(const map&);
83 
85  PN_CPP_EXTERN map(const std::map<K, T>&);
86 
88  PN_CPP_EXTERN map& operator=(const std::map<K, T>&);
89 
91  PN_CPP_EXTERN map(const std::initializer_list<std::pair<const K, T>>&);
92 
94  PN_CPP_EXTERN map(map&&);
95 
97  PN_CPP_EXTERN map& operator=(map&&);
98  PN_CPP_EXTERN ~map();
99 
102  template <class M>
103  typename assignable_map<M, map&>::type operator=(const M& x) { value(x); return *this; }
104 
109  PN_CPP_EXTERN void value(const value& x);
110 
112  PN_CPP_EXTERN proton::value& value();
113 
115  PN_CPP_EXTERN const proton::value& value() const;
116 
119  PN_CPP_EXTERN T get(const K& k) const;
120 
122  PN_CPP_EXTERN void put(const K& k, const T& v);
123 
125  PN_CPP_EXTERN size_t erase(const K& k);
126 
128  PN_CPP_EXTERN bool exists(const K& k) const;
129 
131  PN_CPP_EXTERN size_t size() const;
132 
134  PN_CPP_EXTERN void clear();
135 
137  PN_CPP_EXTERN bool empty() const;
138 
140  explicit map(pn_data_t*);
141  void reset(pn_data_t*);
143 
144  private:
145  typedef map_type_impl<K,T> map_type;
146  mutable std::unique_ptr<map_type> map_;
147  mutable proton::value value_;
148 
149  map_type& cache() const;
150  proton::value& flush() const;
151 
153  friend PN_CPP_EXTERN proton::codec::decoder& operator>> <>(proton::codec::decoder&, map&);
154  friend PN_CPP_EXTERN proton::codec::encoder& operator<< <>(proton::codec::encoder&, const map&);
155  friend PN_CPP_EXTERN void swap<>(map&, map&);
157 };
158 
159 } // proton
160 
161 #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:69
map & operator=(const map &)
Copy a map.
size_t size() const
Get the number of map entries.
bool empty() const
True if the map has no entries.
map & operator=(const std::map< K, T > &)
Copy a std::map.
const proton::value & value() const
Access as a proton::value containing an AMQP map.
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 std::map< K, T > &)
Copy a std::map.
map & operator=(map &&)
Move a map.
map(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.
proton::value & value()
Access as a proton::value containing an AMQP map.
void value(const value &x)
Copy from a proton::value.
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:103
bool exists(const K &k) const
True if the map has an entry for k.
map(const std::initializer_list< std::pair< const K, T >> &)
Initializer_list constructor.
A holder for any AMQP value, simple or complex.
Definition: value.hpp:57
The main Proton namespace.
Definition: annotation_key.hpp:33
proton::codec::decoder & operator>>(proton::codec::decoder &d, map< K, T > &m)
Decode from a proton::map.
void swap(map< K, T > &, map< K, T > &)
Swap proton::map instances.
std::ostream & operator<<(std::ostream &, const binary &)
Print a binary value.
A holder for any AMQP value, simple or complex.