commore  1.0.6-SNAPSHOT
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
Blob.h
1 //
2 // Copyright (c) 2006-2014 Raphael David / CANTOR
3 //
4 
5 #ifndef CMR_BLOB_INCLUDED
6 #define CMR_BLOB_INCLUDED
7 
8 #include "Commore.h"
9 
10 namespace commore
11 {
18  class CMREXD Blob
19  {
20  public:
21  Blob();
22  Blob(const Blob& blob);
28  Blob(size_t size, size_t allocated_size = 0);
36  Blob(const char* content, size_t size, size_t allocated_size = 0);
37  Blob& operator=(const Blob& blob);
41  ~Blob();
42 
43  public:
48  void splice(Blob& blob);
49 
53  char* get_content()
54  {
55  return content_;
56  }
60  const char* get_content() const
61  {
62  return content_;
63  }
64 
68  size_t get_size() const
69  {
70  return size_;
71  }
72 
77  size_t get_allocated_size() const
78  {
79  return allocated_size_;
80  }
81 
86  char* set(const char* content, size_t size, size_t allocated_size = 0);
87 
93  char* set(size_t size, size_t allocated_size = 0);
94  char* set_allocated_size(size_t allocated_size);
95 
100  void clear();
101 
106  long write_xml(OBStream&) const;
107  long read_xml(IBStream&);
108 
113  AString& to_string(AString& s);
118  bool from_string(const char* s);
119 
123  long write(OBStream&, int tab) const;
124  long read(IBStream&);
130  int write(const Path& file) const;
135  int read(const Path& file);
136 
140  long write(CommBuffer& buffer) const;
141  long read(const CommBuffer& buffer);
142 
146  int compare(const Blob& b) const;
147  bool operator==(const Blob& b) const
148  {
149  return compare(b) == 0;
150  }
151  bool operator< (const Blob& b) const
152  {
153  return compare(b) < 0;
154  }
155  bool operator> (const Blob& b) const
156  {
157  return compare(b) > 0;
158  }
159  public:
160  enum { DEFAULT_BLOB_SIZE = 4096, NOT_OWNED_DATA = 0xFFFFFFFF};
161 
162  private:
163  size_t allocated_size_;
164  size_t size_;
165  char* content_;
166 
167  };
168 };
169 
170 CMREXD commore::OBStream& operator << (commore::OBStream& o, const commore::Blob& blob);
171 CMREXD commore::IBStream& operator >> (commore::IBStream& i, commore::Blob& blob);
172 
173 
174 #endif
char * get_content()
Definition: Blob.h:53
Definition: AString.h:39
Definition: Blob.h:18
size_t get_allocated_size() const
Definition: Blob.h:77
size_t get_size() const
Definition: Blob.h:68
Definition: Path.h:19
Definition: CommBuffer.h:28
Definition: IOBStream.h:166
Definition: IOBStream.h:29
const char * get_content() const
Definition: Blob.h:60