libpqxx 4.0
|
00001 /*------------------------------------------------------------------------- 00002 * 00003 * FILE 00004 * pqxx/binarystring.hxx 00005 * 00006 * DESCRIPTION 00007 * Representation for raw, binary data. 00008 * DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/binarystring instead. 00009 * 00010 * Copyright (c) 2003-2011, Jeroen T. Vermeulen <jtv@xs4all.nl> 00011 * 00012 * See COPYING for copyright license. If you did not receive a file called 00013 * COPYING with this source code, please notify the distributor of this mistake, 00014 * or contact the author. 00015 * 00016 *------------------------------------------------------------------------- 00017 */ 00018 #ifndef PQXX_H_BINARYSTRING 00019 #define PQXX_H_BINARYSTRING 00020 00021 #include "pqxx/compiler-public.hxx" 00022 #include "pqxx/compiler-internal-pre.hxx" 00023 00024 #include <string> 00025 00026 #include "pqxx/result" 00027 00028 00029 namespace pqxx 00030 { 00031 00033 00059 class PQXX_LIBEXPORT binarystring : 00060 internal::PQAlloc< 00061 const unsigned char, 00062 pqxx::internal::freemallocmem_templated<const unsigned char> > 00063 { 00064 public: 00065 typedef content_type char_type; 00066 typedef PGSTD::char_traits<char_type>::char_type value_type; 00067 typedef size_t size_type; 00068 typedef long difference_type; 00069 typedef const value_type &const_reference; 00070 typedef const value_type *const_pointer; 00071 typedef const_pointer const_iterator; 00072 00073 #ifdef PQXX_HAVE_REVERSE_ITERATOR 00074 typedef PGSTD::reverse_iterator<const_iterator> const_reverse_iterator; 00075 #endif 00076 00077 private: 00078 typedef internal::PQAlloc< 00079 value_type, 00080 pqxx::internal::freemallocmem_templated<const unsigned char> > 00081 super; 00082 00083 public: 00085 00088 explicit binarystring(const field &); //[t62] 00089 00091 explicit binarystring(const PGSTD::string &); 00092 00094 binarystring(const void *, size_t); 00095 00097 size_type size() const throw () { return m_size; } //[t62] 00099 size_type length() const throw () { return size(); } //[t62] 00100 bool empty() const throw () { return size()==0; } //[t62] 00101 00102 const_iterator begin() const throw () { return data(); } //[t62] 00103 const_iterator end() const throw () { return data()+m_size; } //[t62] 00104 00105 const_reference front() const throw () { return *begin(); } //[t62] 00106 const_reference back() const throw () { return *(data()+m_size-1); } //[t62] 00107 00108 #ifdef PQXX_HAVE_REVERSE_ITERATOR 00109 const_reverse_iterator rbegin() const //[t62] 00110 { return const_reverse_iterator(end()); } 00111 const_reverse_iterator rend() const //[t62] 00112 { return const_reverse_iterator(begin()); } 00113 #endif 00114 00116 const value_type *data() const throw () {return super::get();} //[t62] 00117 00118 const_reference operator[](size_type i) const throw () //[t62] 00119 { return data()[i]; } 00120 00121 bool PQXX_PURE operator==(const binarystring &) const throw (); //[t62] 00122 bool operator!=(const binarystring &rhs) const throw () //[t62] 00123 { return !operator==(rhs); } 00124 00126 const_reference at(size_type) const; //[t62] 00127 00129 void swap(binarystring &); //[t62] 00130 00132 00135 const char *get() const throw () //[t62] 00136 { 00137 return reinterpret_cast<const char *>(super::get()); 00138 } 00139 00141 00147 PGSTD::string str() const; //[t62] 00148 00149 private: 00150 size_type m_size; 00151 }; 00152 00153 00160 00161 00165 PGSTD::string PQXX_LIBEXPORT escape_binary(const PGSTD::string &bin); 00167 00171 PGSTD::string PQXX_LIBEXPORT escape_binary(const char bin[]); 00173 00177 PGSTD::string PQXX_LIBEXPORT escape_binary(const char bin[], size_t len); 00179 00183 PGSTD::string PQXX_LIBEXPORT escape_binary(const unsigned char bin[]); 00185 00189 PGSTD::string PQXX_LIBEXPORT escape_binary(const unsigned char bin[], size_t len); 00190 00196 } 00197 00198 #include "pqxx/compiler-internal-post.hxx" 00199 00200 #endif 00201