Qpid Proton C++  0.13.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
data.hpp
1 #ifndef PROTON_CODEC_DATA_HPP
2 #define PROTON_CODEC_DATA_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 "../internal/object.hpp"
26 #include "../types_fwd.hpp"
27 #include "../type_id.hpp"
28 
29 struct pn_data_t;
30 
31 namespace proton {
32 
33 class value;
34 
35 // XXX -> internal namespace
36 namespace codec {
37 
40 class data : public internal::object<pn_data_t> {
42  data(pn_data_t* d) : internal::object<pn_data_t>(d) {}
43 
44  public:
46  data() : internal::object<pn_data_t>(0) {}
47 
49  PN_CPP_EXTERN static data create();
50 
52  PN_CPP_EXTERN void copy(const data&);
53 
55  PN_CPP_EXTERN void clear();
56 
58  PN_CPP_EXTERN void rewind();
59 
61  PN_CPP_EXTERN bool empty() const;
62 
64  PN_CPP_EXTERN int append(data src);
65 
67  PN_CPP_EXTERN int appendn(data src, int limit);
68 
69  PN_CPP_EXTERN bool next();
70  PN_CPP_EXTERN void* point() const;
71  PN_CPP_EXTERN void restore(void* h);
72 
73  protected:
74  void narrow();
75  void widen();
76 
77  friend class internal::factory<data>;
78  friend struct state_guard;
79  friend PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, const data&);
80 };
82 
87 struct state_guard {
89  data& data_;
90  void* point_;
91  bool cancel_;
93 
95  state_guard(data& d) : data_(d), point_(data_.point()), cancel_(false) {}
97 
98  ~state_guard() { if (!cancel_) data_.restore(point_); }
99 
101  void cancel() { cancel_ = true; }
102 };
103 
105 struct start {
108  start(type_id type_=NULL_TYPE, type_id element_=NULL_TYPE,
109  bool described_=false, size_t size_=0) :
110  type(type_), element(element_), is_described(described_), size(size_) {}
111 
112  type_id type;
113  type_id element;
114  bool is_described;
115  size_t size;
116 
120  static start array(type_id element, bool described=false) { return start(ARRAY, element, described); }
121  static start list() { return start(LIST); }
122  static start map() { return start(MAP); }
123  static start described() { return start(DESCRIBED, NULL_TYPE, true); }
125 };
126 
128 struct finish {};
129 
130 } // codec
131 } // proton
132 
133 #endif // PROTON_CODEC_DATA_HPP
Experimental - Start encoding a complex type.
Definition: data.hpp:105
The null type, contains no data.
Definition: type_id.hpp:39
A descriptor and a value.
Definition: type_id.hpp:60
A sequence of values of the same type.
Definition: type_id.hpp:61
encoder & operator<<(encoder &e, const std::deque< T, A > &x)
std::deque&lt;T&gt; for most T is encoded as an amqp::ARRAY (same type elements)
Definition: deque.hpp:34
A sequence of key-value pairs.
Definition: type_id.hpp:63
Experimental - Save and restore codec state
Definition: data.hpp:87
type_id
An identifier for AMQP types.
Definition: type_id.hpp:38
Experimental - Finish inserting or extracting a complex type.
Definition: data.hpp:128
void cancel()
Discard the saved state.
Definition: data.hpp:101
A sequence of values of mixed types.
Definition: type_id.hpp:62