SQLite3PluginCommon.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. #include "SQLite3PluginCommon.h"
  11. SQLite3Table::SQLite3Table()
  12. {
  13. }
  14. SQLite3Table::~SQLite3Table()
  15. {
  16. for (unsigned int i=0; i < rows.Size(); i++)
  17. RakNet::OP_DELETE(rows[i],_FILE_AND_LINE_);
  18. }
  19. void SQLite3Table::Serialize(RakNet::BitStream *bitStream)
  20. {
  21. bitStream->Write(columnNames.Size());
  22. unsigned int idx1, idx2;
  23. for (idx1=0; idx1 < columnNames.Size(); idx1++)
  24. bitStream->Write(columnNames[idx1]);
  25. bitStream->Write(rows.Size());
  26. for (idx1=0; idx1 < rows.Size(); idx1++)
  27. {
  28. for (idx2=0; idx2 < rows[idx1]->entries.Size(); idx2++)
  29. {
  30. bitStream->Write(rows[idx1]->entries[idx2]);
  31. }
  32. }
  33. }
  34. void SQLite3Table::Deserialize(RakNet::BitStream *bitStream)
  35. {
  36. for (unsigned int i=0; i < rows.Size(); i++)
  37. RakNet::OP_DELETE(rows[i],_FILE_AND_LINE_);
  38. rows.Clear(true,_FILE_AND_LINE_);
  39. columnNames.Clear(true , _FILE_AND_LINE_ );
  40. unsigned int numColumns, numRows;
  41. bitStream->Read(numColumns);
  42. unsigned int idx1,idx2;
  43. RakNet::RakString inputStr;
  44. for (idx1=0; idx1 < numColumns; idx1++)
  45. {
  46. bitStream->Read(inputStr);
  47. columnNames.Push(inputStr, _FILE_AND_LINE_ );
  48. }
  49. bitStream->Read(numRows);
  50. for (idx1=0; idx1 < numRows; idx1++)
  51. {
  52. SQLite3Row *row = RakNet::OP_NEW<SQLite3Row>(_FILE_AND_LINE_);
  53. rows.Push(row,_FILE_AND_LINE_);
  54. for (idx2=0; idx2 < numColumns; idx2++)
  55. {
  56. bitStream->Read(inputStr);
  57. row->entries.Push(inputStr, _FILE_AND_LINE_ );
  58. }
  59. }
  60. }
粤ICP备19079148号