Qpid Proton C++ API  0.18.1
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>
51 PN_CPP_EXTERN proton::codec::encoder& operator<<(proton::codec::encoder& e, const map<K,T>& m);
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 
82 #if PN_CPP_HAS_RVALUE_REFERENCES
83  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
void swap(map< K, T > &, map< K, T > &)
Swap proton::map instances.
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:44
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
A holder for any AMQP value, simple or complex.
Definition: value.hpp:57
internal::enable_if< internal::is_unknown_integer< T >::value, decoder & >::type operator>>(decoder &d, T &i)
operator>> for integer types that are not covered by the standard overrides.
Definition: decoder.hpp:206
The main Proton namespace.
Definition: annotation_key.hpp:33
Unsettled API - A stream-like decoder from AMQP bytes to C++ values.
Definition: decoder.hpp:56
A holder for any AMQP value, simple or complex.