00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _SUPPORT_MEMORYSTORE_H
00014 #define _SUPPORT_MEMORYSTORE_H
00015
00027 #include <support/IStorage.h>
00028 #include <support/ByteStream.h>
00029 #include <support/Locker.h>
00030 #include <support/Value.h>
00031
00032 #if _SUPPORTS_NAMESPACE
00033 namespace palmos {
00034 namespace support {
00035 #endif
00036
00041
00042
00044
00050 class BMemoryStore : public BnStorage, public BByteStream
00051 {
00052 public:
00053
00054 BMemoryStore();
00055 BMemoryStore(const BMemoryStore &);
00056 BMemoryStore(void *data, size_t size);
00057 BMemoryStore(const void *data, size_t size);
00058
00059 BMemoryStore&operator=(const BMemoryStore &);
00060
00061 bool operator<(const BMemoryStore &) const;
00062 bool operator<=(const BMemoryStore &) const;
00063 bool operator==(const BMemoryStore &) const;
00064 bool operator!=(const BMemoryStore &) const;
00065 bool operator>=(const BMemoryStore &) const;
00066 bool operator>(const BMemoryStore &) const;
00067
00069
00072 size_t BufferSize() const;
00074 const void *Buffer() const;
00075
00076 status_t AssertSpace(size_t newSize);
00077 status_t Copy(const BMemoryStore &);
00078 int32_t Compare(const BMemoryStore &) const;
00079
00080 virtual SValue Inspect(const sptr<IBinder>& caller, const SValue &which, uint32_t flags = 0);
00081
00082 virtual off_t Size() const;
00083 virtual status_t SetSize(off_t position);
00084
00085 virtual ssize_t ReadAtV(off_t position, const struct iovec *vector, ssize_t count);
00086 virtual ssize_t WriteAtV(off_t position, const struct iovec *vector, ssize_t count);
00087 virtual status_t Sync();
00088
00089 void SetBlockSize(size_t blocksize);
00090
00091 protected:
00092 virtual ~BMemoryStore();
00093 void Reset();
00094
00095
00096 private:
00097 virtual void * MoreCore(void *oldBuf, size_t newSize);
00098 virtual void FreeCore(void *oldBuf);
00099
00100 size_t m_length;
00101 char* m_data;
00102 bool m_readOnly;
00103 };
00104
00105
00106
00108
00110 class BMallocStore : public BMemoryStore
00111 {
00112 public:
00113
00114 BMallocStore();
00115 BMallocStore(const BMemoryStore &);
00116
00117 void SetBlockSize(size_t blocksize);
00118
00119 protected:
00120 virtual ~BMallocStore();
00121
00122 private:
00123 BMallocStore(const BMallocStore& o);
00124
00125 virtual void * MoreCore(void *oldBuf, size_t newSize);
00126 virtual void FreeCore(void *oldBuf);
00127
00128 size_t m_blockSize;
00129 size_t m_mallocSize;
00130 };
00131
00132
00133
00135
00138 class BValueStorage : public BMemoryStore
00139 {
00140 public:
00141 BValueStorage(SValue* value, SLocker* lock, const sptr<SAtom>& object);
00142
00143 SValue Value() const;
00144
00145 virtual status_t SetSize(off_t position);
00146
00147 virtual ssize_t ReadAtV(off_t position, const struct iovec *vector, ssize_t count);
00148 virtual ssize_t WriteAtV(off_t position, const struct iovec *vector, ssize_t count);
00149 virtual status_t Sync();
00150
00151 protected:
00152 virtual ~BValueStorage();
00153
00154 private:
00155 virtual void* MoreCore(void *oldBuf, size_t newSize);
00156 virtual void FreeCore(void *oldBuf);
00157
00158 SValue* m_value;
00159 SLocker* m_lock;
00160 sptr<SAtom> m_atom;
00161 bool m_editing;
00162 };
00163
00166
00167
00168
00169 inline bool BMemoryStore::operator<(const BMemoryStore &o) const
00170 {
00171 return Compare(o) < 0;
00172 }
00173
00174 inline bool BMemoryStore::operator<=(const BMemoryStore &o) const
00175 {
00176 return Compare(o) <= 0;
00177 }
00178
00179 inline bool BMemoryStore::operator==(const BMemoryStore &o) const
00180 {
00181 return Compare(o) == 0;
00182 }
00183
00184 inline bool BMemoryStore::operator!=(const BMemoryStore &o) const
00185 {
00186 return Compare(o) != 0;
00187 }
00188
00189 inline bool BMemoryStore::operator>=(const BMemoryStore &o) const
00190 {
00191 return Compare(o) >= 0;
00192 }
00193
00194 inline bool BMemoryStore::operator>(const BMemoryStore &o) const
00195 {
00196 return Compare(o) > 0;
00197 }
00198
00199
00200
00201
00202 #if _SUPPORTS_NAMESPACE
00203 } }
00204 #endif
00205
00206 #endif