49 std::string filename(
"");
50 std::string idx(
"idx");
51 std::string dat(
"dat");
67 std::ostringstream os;
69 os << filename <<
"."<<dat;
70 std::string data_name = os.str();
71 ret = stat(data_name.c_str(), &stats);
73 if (ret == 0) bExists =
true;
76 os << filename <<
"."<<idx;
77 std::string index_name = os.str();
78 ret = stat(index_name.c_str(), &stats);
80 if ((ret == 0) && (bExists ==
true)) bExists =
true;
101 var.
m_val.
pcVal =
const_cast<char*
>(baseName.c_str());
121 var.
m_val.
pcVal =
const_cast<char*
>(baseName.c_str());
133 bool bOverwrite =
false;
134 bool bFileExists =
false;
135 std::streamoff length = 0;
155 std::string idx(
"idx");
156 std::string dat(
"dat");
164 std::string sIndexFile = std::string(var.
m_val.
pcVal) +
"." + idx;
165 std::string sDataFile = std::string(var.
m_val.
pcVal) +
"." + dat;
171 if (bFileExists ==
true && bOverwrite ==
false)
173 std::ios_base::openmode mode = std::ios::in | std::ios::out | std::ios::binary;
182 std::ios_base::openmode mode = std::ios::in | std::ios::out | std::ios::binary | std::ios::trunc;
202 if ((bOverwrite ==
true) || (length == 0) || (bFileExists ==
false))
233 if ((bOverwrite ==
false) && (length > 0))
239 m_indexFile.read(reinterpret_cast<char*>(&count),
sizeof(uint32_t));
243 for (uint32_t cCount = 0; cCount < count; ++cCount)
252 m_indexFile.read(reinterpret_cast<char*>(&count),
sizeof(uint32_t));
256 for (uint32_t cCount = 0; cCount < count; ++cCount)
258 Entry* e =
new Entry();
264 m_indexFile.read(reinterpret_cast<char*>(&(e->m_length)),
sizeof(uint32_t));
269 m_indexFile.read(reinterpret_cast<char*>(&count2),
sizeof(uint32_t));
273 for (uint32_t cCount2 = 0; cCount2 < count2; ++cCount2)
278 e->m_pages.push_back(page);
280 m_pageIndex.insert(std::pair<id_type, Entry* >(
id, e));
310 uint32_t count =
static_cast<uint32_t
>(
m_emptyPages.size());
311 m_indexFile.write(reinterpret_cast<const char*>(&count),
sizeof(uint32_t));
323 m_indexFile.write(reinterpret_cast<const char*>(&count),
sizeof(uint32_t));
333 m_indexFile.write(reinterpret_cast<const char*>(&((*it).second->m_length)),
sizeof(uint32_t));
337 count =
static_cast<uint32_t
>((*it).second->m_pages.size());
338 m_indexFile.write(reinterpret_cast<const char*>(&count),
sizeof(uint32_t));
342 for (uint32_t cIndex = 0; cIndex < count; ++cIndex)
344 m_indexFile.write(reinterpret_cast<const char*>(&((*it).second->m_pages[cIndex])),
sizeof(
id_type));
356 std::map<id_type, Entry*>::iterator it =
m_pageIndex.find(page);
361 std::vector<id_type>& pages = (*it).second->m_pages;
363 uint32_t cTotal =
static_cast<uint32_t
>(pages.size());
365 len = (*it).second->m_length;
366 *data =
new uint8_t[len];
368 uint8_t* ptr = *data;
382 cLen = (cRem >
m_pageSize) ? m_pageSize : cRem;
389 while (cNext < cTotal);
396 Entry* e =
new Entry();
399 const uint8_t* ptr = data;
430 e->m_pages.push_back(cPage);
433 page = e->m_pages[0];
434 m_pageIndex.insert(std::pair<id_type, Entry*>(page, e));
439 std::map<id_type, Entry*>::iterator it =
m_pageIndex.find(page);
445 Entry* oldEntry = (*it).second;
449 Entry* e =
new Entry();
452 const uint8_t* ptr = data;
455 uint32_t cLen, cNext = 0;
459 if (cNext < oldEntry->m_pages.size())
461 cPage = oldEntry->m_pages[cNext];
488 e->m_pages.push_back(cPage);
491 while (cNext < oldEntry->m_pages.size())
497 m_pageIndex.insert(std::pair<id_type, Entry*>(page, e));
504 std::map<id_type, Entry*>::iterator it =
m_pageIndex.find(page);
509 for (uint32_t cIndex = 0; cIndex < (*it).second->m_pages.size(); ++cIndex)
void storeByteArray(id_type &page, const uint32_t len, const uint8_t *const data) override
std::set< id_type > m_emptyPages
DiskStorageManager(Tools::PropertySet &)
SIDX_DLL IStorageManager * returnDiskStorageManager(Tools::PropertySet &in)
bool CheckFilesExists(Tools::PropertySet &ps)
~DiskStorageManager() override
SIDX_DLL IStorageManager * loadDiskStorageManager(std::string &baseName)
void loadByteArray(const id_type page, uint32_t &len, uint8_t **data) override
std::map< id_type, Entry * > m_pageIndex
void deleteByteArray(const id_type page) override
SIDX_DLL IStorageManager * createNewDiskStorageManager(std::string &baseName, uint32_t pageSize)