00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "pqxx/libcompiler.h"
00019
00020 #include <string>
00021
00022 #include "pqxx/result"
00023
00024
00025 namespace pqxx
00026 {
00027
00029
00049 class PQXX_LIBEXPORT binarystring : internal::PQAlloc<unsigned char>
00050 {
00051
00052 public:
00053 typedef content_type char_type;
00054 typedef PGSTD::char_traits<char_type>::char_type value_type;
00055 typedef size_t size_type;
00056 typedef long difference_type;
00057 typedef const value_type &const_reference;
00058 typedef const value_type *const_pointer;
00059 typedef const_pointer const_iterator;
00060
00061 #ifdef PQXX_HAVE_REVERSE_ITERATOR
00062 typedef PGSTD::reverse_iterator<const_iterator> const_reverse_iterator;
00063 #endif
00064
00065 private:
00066 typedef internal::PQAlloc<value_type> super;
00067
00068 public:
00070
00073 explicit binarystring(const result::field &F);
00074
00076 size_type size() const throw () { return m_size; }
00078 size_type length() const throw () { return size(); }
00079 bool empty() const throw () { return size()==0; }
00080
00081 const_iterator begin() const throw () { return data(); }
00082 const_iterator end() const throw () { return data()+m_size; }
00083
00084 const_reference front() const throw () { return *begin(); }
00085 const_reference back() const throw () { return *(data()+m_size-1); }
00086
00087 #ifdef PQXX_HAVE_REVERSE_ITERATOR
00088 const_reverse_iterator rbegin() const
00089 { return const_reverse_iterator(end()); }
00090 const_reverse_iterator rend() const
00091 { return const_reverse_iterator(begin()); }
00092 #endif
00093
00095 const value_type *data() const throw () {return super::c_ptr();}
00096
00097 const_reference operator[](size_type i) const throw ()
00098 { return data()[i]; }
00099
00100 bool operator==(const binarystring &) const throw ();
00101 bool operator!=(const binarystring &rhs) const throw ()
00102 { return !operator==(rhs); }
00103
00105 const_reference at(size_type) const;
00106
00108 void swap(binarystring &);
00109
00111
00114 const char *c_ptr() const throw ()
00115 {
00116 return reinterpret_cast<char *>(super::c_ptr());
00117 }
00118
00120
00127 const PGSTD::string &str() const;
00128
00129 private:
00130 size_type m_size;
00131 mutable PGSTD::string m_str;
00132 };
00133
00134
00139
00140 PGSTD::string PQXX_LIBEXPORT escape_binary(const PGSTD::string &bin);
00142 PGSTD::string PQXX_LIBEXPORT escape_binary(const char bin[]);
00144 PGSTD::string PQXX_LIBEXPORT escape_binary(const char bin[], size_t len);
00146 PGSTD::string PQXX_LIBEXPORT escape_binary(const unsigned char bin[]);
00148 PGSTD::string PQXX_LIBEXPORT escape_binary(const unsigned char bin[], size_t len);
00150
00151
00152 }
00153