commore  1.0.6-SNAPSHOT
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Blob.h
Go to the documentation of this file.
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 
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 
172 
173 
174 #endif
bool operator==(const Blob &b) const
Definition: Blob.h:147
char * get_content()
Definition: Blob.h:53
Definition: AString.h:39
long CMREXD write_xml(const AString &sIn, OBStream &o)
Definition: AString.cpp:27
Definition: Blob.h:18
bool read(IBStream &str, int &num)
Definition: Time.cpp:200
CMREXD commore::IBStream & operator>>(commore::IBStream &i, commore::Blob &blob)
Definition: Blob.cpp:245
size_t get_allocated_size() const
Definition: Blob.h:77
AString to_string(long number, int width=0, char pad= '0')
Definition: Time.cpp:1405
#define CMREXD
Definition: Compiler.h:22
CMREXD commore::OBStream & operator<<(commore::OBStream &o, const commore::Blob &blob)
Definition: Blob.cpp:238
size_t get_size() const
Definition: Blob.h:68
Definition: Path.h:19
Definition: CommBuffer.h:28
long CMREXD read_xml(AString &sOut, IBStream &i)
Definition: AString.cpp:65
bool operator<(const pair< T1, T2 > &x, const pair< T1, T2 > &y)
Definition: HMap.h:155
bool from_string(TimeDate &value, const char *text, bool utc)
Definition: Time.cpp:221
Definition: IOBStream.h:166
Definition: IOBStream.h:29
const char * get_content() const
Definition: Blob.h:60