~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/util/data_ref.h

  • Committer: Olaf van der Spek
  • Date: 2011-10-18 13:52:19 UTC
  • mto: This revision was merged to the branch mainline in revision 2443.
  • Revision ID: olafvdspek@gmail.com-20111018135219-vn5xhy8pvumotthk
Refactor

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include <cstddef>
21
21
#include <cstring>
22
22
#include <ostream>
 
23
#include <string>
23
24
 
24
25
template <class T>
25
26
class data_ref_basic
27
28
public:
28
29
  data_ref_basic()
29
30
  {
 
31
    clear();
30
32
  }
31
33
 
32
34
  template <class U>
53
55
    assign(b, strlen(b));
54
56
  }
55
57
 
56
 
  const data_ref_basic& clear()
 
58
  void clear()
57
59
  {
58
60
    begin_ = NULL;
59
61
    end_ = NULL;
60
 
    return *this;
61
62
  }
62
63
 
63
64
  void assign(const void* b, const void* e)
96
97
  {
97
98
    return begin() == end();
98
99
  }
99
 
 
100
 
  friend std::ostream& operator<<(std::ostream& os, data_ref_basic<T> v)
101
 
  {
102
 
    os.write(v.data(), v.size());
103
 
    return os;
104
 
  }
105
100
private:
106
101
  T begin_;
107
102
  T end_;
109
104
 
110
105
typedef data_ref_basic<const unsigned char*> data_ref;
111
106
typedef data_ref_basic<const char*> str_ref;
 
107
 
 
108
inline std::ostream& operator<<(std::ostream& os, str_ref v)
 
109
{
 
110
  return os.write(v.data(), v.size());
 
111
}
 
112
 
 
113
inline std::string to_string(str_ref v)
 
114
{
 
115
  return std::string(v.data(), v.size());
 
116
}