00001 /*------------------------------------------------------------------------- 00002 * 00003 * FILE 00004 * pqxx/binarystring.hxx 00005 * 00006 * DESCRIPTION 00007 * declarations for bytea (binary string) conversions 00008 * DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/binarystring instead. 00009 * 00010 * Copyright (c) 2003, 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 #include "pqxx/libcompiler.h" 00019 00020 #include <string> 00021 00022 #include "pqxx/result" 00023 00024 00025 namespace pqxx 00026 { 00027 00029 00041 class PQXX_LIBEXPORT binarystring : PQAlloc<unsigned char> 00042 { 00043 // TODO: Templatize on character type? 00044 public: 00045 typedef content_type char_type; 00046 typedef PGSTD::char_traits<char_type>::char_type value_type; 00047 typedef size_t size_type; 00048 typedef ptrdiff_t difference_type; 00049 typedef const value_type &const_reference; 00050 typedef const value_type *const_pointer; 00051 typedef const_pointer const_iterator; 00052 00053 #ifndef PQXX_WORKAROUND_VC7 00054 typedef PGSTD::reverse_iterator<const_iterator> const_reverse_iterator; 00055 #endif 00056 00057 private: 00058 typedef PQAlloc<value_type> super; 00059 00060 public: 00062 00065 explicit binarystring(const result::field &F); //[t62] 00066 00068 size_type size() const throw () { return m_size; } //[t62] 00069 size_type length() const throw () { return size(); } //[t62] 00070 bool empty() const throw () { return size()==0; } //[t62] 00071 00072 const_iterator begin() const throw () { return data(); } //[t62] 00073 const_iterator end() const throw () { return data()+m_size; } //[t62] 00074 00075 #ifndef PQXX_WORKAROUND_VC7 00076 const_reverse_iterator rbegin() const //[t62] 00077 { return const_reverse_iterator(end()); } 00078 const_reverse_iterator rend() const //[t62] 00079 { return const_reverse_iterator(begin()); } 00080 #endif 00081 00083 const value_type *data() const throw () {return super::c_ptr();} //[t62] 00084 00085 const_reference operator[](size_type i) const throw () //[t62] 00086 { return data()[i]; } 00087 00088 const_reference at(size_type n) const; //[t62] 00089 00091 00094 const char *c_ptr() const throw () //[t62] 00095 { 00096 return reinterpret_cast<char *>(super::c_ptr()); 00097 } 00098 00100 00102 const PGSTD::string &str() const; //[t62] 00103 00104 private: 00105 size_type m_size; 00106 mutable PGSTD::string m_str; 00107 }; 00108 00109 00111 PGSTD::string PQXX_LIBEXPORT escape_binary(const PGSTD::string &bin); 00113 PGSTD::string PQXX_LIBEXPORT escape_binary(const char bin[]); 00115 PGSTD::string PQXX_LIBEXPORT escape_binary(const char bin[], size_t len); 00117 PGSTD::string PQXX_LIBEXPORT escape_binary(const unsigned char bin[]); 00119 PGSTD::string PQXX_LIBEXPORT escape_binary(const unsigned char bin[], size_t len); 00120 00121 00122 } 00123