libpqxx 3.1.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

binarystring.hxx
1 /*-------------------------------------------------------------------------
2 *
3 * FILE
4 * pqxx/binarystring.hxx
5 *
6 * DESCRIPTION
7 * declarations for bytea (binary string) conversions
8 * DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/binarystring instead.
9 *
10 * Copyright (c) 2003-2009, Jeroen T. Vermeulen <jtv@xs4all.nl>
11 *
12 * See COPYING for copyright license. If you did not receive a file called
13 * COPYING with this source code, please notify the distributor of this mistake,
14 * or contact the author.
15 *
16 *-------------------------------------------------------------------------
17 */
18 #ifndef PQXX_H_BINARYSTRING
19 #define PQXX_H_BINARYSTRING
20
21 #include "pqxx/compiler-public.hxx"
22 #include "pqxx/compiler-internal-pre.hxx"
23
24 #include <string>
25
26 #include "pqxx/result"
27
28
29 namespace pqxx
30 {
31
33
60 class PQXX_LIBEXPORT binarystring : internal::PQAlloc<const unsigned char>
61 {
62 // TODO: Templatize on character type?
63 public:
64 typedef content_type char_type;
65 typedef PGSTD::char_traits<char_type>::char_type value_type;
66 typedef size_t size_type;
67 typedef long difference_type;
68 typedef const value_type &const_reference;
69 typedef const value_type *const_pointer;
70 typedef const_pointer const_iterator;
71
72 #ifdef PQXX_HAVE_REVERSE_ITERATOR
73 typedef PGSTD::reverse_iterator<const_iterator> const_reverse_iterator;
74 #endif
75
76 private:
77 typedef internal::PQAlloc<value_type> super;
78
79 public:
81
84 explicit binarystring(const result::field &F); //[t62]
85
87 size_type size() const throw () { return m_size; } //[t62]
89 size_type length() const throw () { return size(); } //[t62]
90 bool empty() const throw () { return size()==0; } //[t62]
91
92 const_iterator begin() const throw () { return data(); } //[t62]
93 const_iterator end() const throw () { return data()+m_size; } //[t62]
94
95 const_reference front() const throw () { return *begin(); } //[t62]
96 const_reference back() const throw () { return *(data()+m_size-1); } //[t62]
97
98 #ifdef PQXX_HAVE_REVERSE_ITERATOR
99 const_reverse_iterator rbegin() const //[t62]
100 { return const_reverse_iterator(end()); }
101 const_reverse_iterator rend() const //[t62]
102 { return const_reverse_iterator(begin()); }
103 #endif
104
106 const value_type *data() const throw () {return super::get();} //[t62]
107
108 const_reference operator[](size_type i) const throw () //[t62]
109 { return data()[i]; }
110
111 bool operator==(const binarystring &) const throw (); //[t62]
112 bool operator!=(const binarystring &rhs) const throw () //[t62]
113 { return !operator==(rhs); }
114
116 const_reference at(size_type) const; //[t62]
117
119 void swap(binarystring &); //[t62]
120
122
125 const char *get() const throw () //[t62]
126 {
127 return reinterpret_cast<const char *>(super::get());
128 }
129
131
137 PGSTD::string str() const; //[t62]
138
139 private:
140 size_type m_size;
141 };
142
143
150
151
155 PGSTD::string PQXX_LIBEXPORT escape_binary(const PGSTD::string &bin);
157
161 PGSTD::string PQXX_LIBEXPORT escape_binary(const char bin[]);
163
167 PGSTD::string PQXX_LIBEXPORT escape_binary(const char bin[], size_t len);
169
173 PGSTD::string PQXX_LIBEXPORT escape_binary(const unsigned char bin[]);
175
179 PGSTD::string PQXX_LIBEXPORT escape_binary(const unsigned char bin[], size_t len);
180
186 }
187
188 #include "pqxx/compiler-internal-post.hxx"
189
190 #endif
191