00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #pragma once
00037
00038 #include <utility>
00039 #include <string>
00040 #include <vector>
00041
00042 #include <boost/algorithm/string/predicate.hpp>
00043 #include <boost/foreach.hpp>
00044 #include <boost/functional/hash.hpp>
00045 #include <boost/shared_ptr.hpp>
00046
00047 #define drizzle_literal_parameter(X) (X), size_t((sizeof(X) - 1))
00048
00049 namespace drizzled {
00050 namespace util {
00051
00052 struct insensitive_equal_to : std::binary_function<std::string, std::string, bool>
00053 {
00054 bool operator()(std::string const& x, std::string const& y) const
00055 {
00056 return boost::algorithm::iequals(x, y);
00057 }
00058 };
00059
00060 struct insensitive_hash : std::unary_function<std::string, std::size_t>
00061 {
00062 std::size_t operator()(std::string const& x) const
00063 {
00064 std::size_t seed = 0;
00065 BOOST_FOREACH(std::string::const_reference it, x)
00066 boost::hash_combine(seed, std::toupper(it));
00067 return seed;
00068 }
00069 };
00070
00071 struct sensitive_hash : std::unary_function< std::vector<char>, std::size_t>
00072 {
00073 std::size_t operator()(std::vector<char> const& x) const
00074 {
00075 std::size_t seed = 0;
00076 BOOST_FOREACH(std::vector<char>::const_reference it, x)
00077 boost::hash_combine(seed, it);
00078 return seed;
00079 }
00080 };
00081
00082 class String
00083 {
00084 public:
00085
00086 String()
00087 {
00088 _bytes.resize(1);
00089 }
00090
00091 const char* data() const
00092 {
00093 return &_bytes[0];
00094 }
00095
00096 char* data()
00097 {
00098 return &_bytes[0];
00099 }
00100
00101 void assign(const size_t repeat, const char arg)
00102 {
00103 _bytes.resize(repeat + 1);
00104 memset(&_bytes[0], arg, repeat);
00105 _bytes[repeat]= 0;
00106 }
00107
00108 void assign(const char *arg, const size_t arg_size)
00109 {
00110 _bytes.resize(arg_size + 1);
00111 memcpy(&_bytes[0], arg, arg_size);
00112 _bytes[arg_size]= 0;
00113 }
00114
00115 void append(const char *arg, const size_t arg_size)
00116 {
00117 if (not arg or not arg_size)
00118 return;
00119
00120 size_t original_size= size();
00121 if (original_size)
00122 {
00123 _bytes.resize(original_size + arg_size + 1);
00124 memcpy(&_bytes[original_size], arg, arg_size);
00125 _bytes[original_size + arg_size]= 0;
00126 }
00127 else
00128 {
00129 assign(arg, arg_size);
00130 }
00131 }
00132
00133 const char& operator[] (size_t arg) const
00134 {
00135 return _bytes[arg];
00136 }
00137
00138 char& operator[] (size_t arg)
00139 {
00140 return _bytes[arg];
00141 }
00142
00143 void clear()
00144 {
00145 _bytes.resize(1);
00146 _bytes[0]= 0;
00147 }
00148
00149 size_t size() const
00150 {
00151 return _bytes.size() -1;
00152 }
00153
00154 private:
00155 std::vector<char> _bytes;
00156 };
00157
00158 }
00159 }
00160