libpqxx  4.0.1
binarystring.hxx
1 /*-------------------------------------------------------------------------
2  *
3  * FILE
4  * pqxx/binarystring.hxx
5  *
6  * DESCRIPTION
7  * Representation for raw, binary data.
8  * DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/binarystring instead.
9  *
10  * Copyright (c) 2003-2013, 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 
59 class PQXX_LIBEXPORT binarystring :
61  unsigned char,
62  pqxx::internal::freemallocmem_templated<unsigned char> >
63 {
64 public:
66  typedef PGSTD::char_traits<char_type>::char_type value_type;
67  typedef size_t size_type;
68  typedef long difference_type;
69  typedef const value_type &const_reference;
70  typedef const value_type *const_pointer;
72 
73 #ifdef PQXX_HAVE_REVERSE_ITERATOR
74  typedef PGSTD::reverse_iterator<const_iterator> const_reverse_iterator;
75 #endif
76 
77 private:
78  typedef internal::PQAlloc<
79  value_type,
80  pqxx::internal::freemallocmem_templated<unsigned char> >
81  super;
82 
83 public:
85 
88  explicit binarystring(const field &); //[t62]
89 
91  explicit binarystring(const PGSTD::string &);
92 
94  binarystring(const void *, size_t);
95 
97  size_type size() const throw () { return m_size; } //[t62]
99  size_type length() const throw () { return size(); } //[t62]
100  bool empty() const throw () { return size()==0; } //[t62]
101 
102  const_iterator begin() const throw () { return data(); } //[t62]
103  const_iterator end() const throw () { return data()+m_size; } //[t62]
104 
105  const_reference front() const throw () { return *begin(); } //[t62]
106  const_reference back() const throw () { return *(data()+m_size-1); } //[t62]
107 
108 #ifdef PQXX_HAVE_REVERSE_ITERATOR
109  const_reverse_iterator rbegin() const //[t62]
110  { return const_reverse_iterator(end()); }
111  const_reverse_iterator rend() const //[t62]
112  { return const_reverse_iterator(begin()); }
113 #endif
114 
116  const value_type *data() const throw () {return super::get();} //[t62]
117 
118  const_reference operator[](size_type i) const throw () //[t62]
119  { return data()[i]; }
120 
121  bool PQXX_PURE operator==(const binarystring &) const throw (); //[t62]
122  bool operator!=(const binarystring &rhs) const throw () //[t62]
123  { return !operator==(rhs); }
124 
126  const_reference at(size_type) const; //[t62]
127 
129  void swap(binarystring &); //[t62]
130 
132 
135  const char *get() const throw () //[t62]
136  {
137  return reinterpret_cast<const char *>(super::get());
138  }
139 
141 
147  PGSTD::string str() const; //[t62]
148 
149 private:
150  size_type m_size;
151 };
152 
153 
160 
161 
165 PGSTD::string PQXX_LIBEXPORT escape_binary(const PGSTD::string &bin);
167 
171 PGSTD::string PQXX_LIBEXPORT escape_binary(const char bin[]);
173 
177 PGSTD::string PQXX_LIBEXPORT escape_binary(const char bin[], size_t len);
179 
183 PGSTD::string PQXX_LIBEXPORT escape_binary(const unsigned char bin[]);
185 
189 PGSTD::string PQXX_LIBEXPORT escape_binary(const unsigned char bin[], size_t len);
190 
196 }
197 
198 #include "pqxx/compiler-internal-post.hxx"
199 
200 #endif
201