database-dummy.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. Minetest
  3. Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 3.0 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. /*
  17. Dummy database class
  18. */
  19. #include "database-dummy.h"
  20. bool Database_Dummy::saveBlock(const v3s16 &pos, const std::string &data)
  21. {
  22. m_database[getBlockAsInteger(pos)] = data;
  23. return true;
  24. }
  25. void Database_Dummy::loadBlock(const v3s16 &pos, std::string *block)
  26. {
  27. s64 i = getBlockAsInteger(pos);
  28. std::map<s64, std::string>::iterator it = m_database.find(i);
  29. if (it == m_database.end()) {
  30. *block = "";
  31. return;
  32. }
  33. *block = it->second;
  34. }
  35. bool Database_Dummy::deleteBlock(const v3s16 &pos)
  36. {
  37. m_database.erase(getBlockAsInteger(pos));
  38. return true;
  39. }
  40. void Database_Dummy::listAllLoadableBlocks(std::vector<v3s16> &dst)
  41. {
  42. dst.reserve(m_database.size());
  43. for (std::map<s64, std::string>::const_iterator x = m_database.begin();
  44. x != m_database.end(); ++x) {
  45. dst.push_back(getIntegerAsBlock(x->first));
  46. }
  47. }