Qpid Proton C++  0.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
data.hpp
1 #ifndef DATA_H
2 #define DATA_H
3 
4 /*
5  * Licensed to the Apache Software Foundation (ASF) under one
6  * or more contributor license agreements. See the NOTICE file
7  * distributed with this work for additional information
8  * regarding copyright ownership. The ASF licenses this file
9  * to you under the Apache License, Version 2.0 (the
10  * "License"); you may not use this file except in compliance
11  * with the License. You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing,
16  * software distributed under the License is distributed on an
17  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18  * KIND, either express or implied. See the License for the
19  * specific language governing permissions and limitations
20  * under the License.
21  */
22 
25 
26 #include "proton/decoder.hpp"
27 #include "proton/encoder.hpp"
28 #include "proton/export.hpp"
29 #include "proton/object.hpp"
30 
31 #include <iosfwd>
32 
33 struct pn_data_t;
34 
35 namespace proton {
36 
37 class data;
38 
42 class data : public object<pn_data_t> {
43  public:
44  data(pn_data_t* d=0) : object<pn_data_t>(d) {}
45 
46  PN_CPP_EXTERN static data create();
47 
48  // Copy the contents of another data object t this one.
49  PN_CPP_EXTERN data& copy(const data&);
50 
51  template<class T> data& copy(T &t) { clear(); encoder() << t; return *this; }
52 
54  PN_CPP_EXTERN void clear();
55 
57  PN_CPP_EXTERN bool empty() const;
58 
60  PN_CPP_EXTERN class encoder encoder();
61 
63  PN_CPP_EXTERN class decoder decoder();
64 
66  PN_CPP_EXTERN uintptr_t point() const;
67 
69  PN_CPP_EXTERN void restore(uintptr_t h);
70 
71  PN_CPP_EXTERN void narrow();
72 
73  PN_CPP_EXTERN void widen();
74 
75  PN_CPP_EXTERN int append(data src);
76 
77  PN_CPP_EXTERN int appendn(data src, int limit);
78 
79  PN_CPP_EXTERN bool next() const;
80 
82  PN_CPP_EXTERN type_id type() const;
83 
85  template<class T> void get(T &t) const { decoder().rewind(); decoder() >> t; }
86 
87  template<class T> T get() const { T t; get(t); return t; }
88 
89  PN_CPP_EXTERN bool equal(const data& x) const;
90  PN_CPP_EXTERN bool less(const data& x) const;
91 
93  friend PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, const data&);
94  friend class value;
95  private:
96  data(pn_ptr<pn_data_t> d) : object<pn_data_t>(d) {}
97  class decoder decoder() const { return const_cast<data*>(this)->decoder(); }
98 };
99 
100 }
101 
103 
104 #endif // DATA_H