Qpid Proton C++ API  0.36.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 
33 namespace proton {
34 
35 namespace codec {
36 class decoder;
37 class encoder;
38 }
39 
40 template <class K, class T>
41 class map_type_impl;
42 
43 template <class K, class T>
44 class map;
45 
47 template <class K, class T>
50 template <class K, class T>
53 template <class K, class T>
54 PN_CPP_EXTERN void swap(map<K,T>&, map<K,T>&);
55 
66 template <class K, class T>
67 class 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 
83  PN_CPP_EXTERN map(map&&);
84 
86  PN_CPP_EXTERN map& operator=(map&&);
87  PN_CPP_EXTERN ~map();
88 
91  template <class M>
92  typename assignable_map<M, map&>::type operator=(const M& x) { value(x); return *this; }
93 
98  PN_CPP_EXTERN void value(const value& x);
99 
101  PN_CPP_EXTERN proton::value& value();
102 
104  PN_CPP_EXTERN const proton::value& value() const;
105 
108  PN_CPP_EXTERN T get(const K& k) const;
109 
111  PN_CPP_EXTERN void put(const K& k, const T& v);
112 
114  PN_CPP_EXTERN size_t erase(const K& k);
115 
117  PN_CPP_EXTERN bool exists(const K& k) const;
118 
120  PN_CPP_EXTERN size_t size() const;
121 
123  PN_CPP_EXTERN void clear();
124 
126  PN_CPP_EXTERN bool empty() const;
127 
129  explicit map(pn_data_t*);
130  void reset(pn_data_t*);
132 
133  private:
134  typedef map_type_impl<K,T> map_type;
135  mutable internal::pn_unique_ptr<map_type> map_;
136  mutable proton::value value_;
137 
138  map_type& cache() const;
139  proton::value& flush() const;
140 
142  friend PN_CPP_EXTERN proton::codec::decoder& operator>> <>(proton::codec::decoder&, map&);
143  friend PN_CPP_EXTERN proton::codec::encoder& operator<< <>(proton::codec::encoder&, const map&);
144  friend PN_CPP_EXTERN void swap<>(map&, map&);
146 };
147 
148 } // proton
149 
150 #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
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.
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 & 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:92
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
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.