query_test.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #ifndef QUERY_TEST_H
  2. #define QUERY_TEST_H
  3. #include "libbinom/include/binom.h"
  4. using namespace binom;
  5. /*
  6. { // Query Initer
  7. {QProp::..., ?{path...}, QOper::..., QValue(...), QRel::...}, // Expression lvl#0
  8. {{ // Expression lvl#0
  9. {QProp::..., ?{path...}, QOper::..., QValue(...), QRel::...}, // SubExpression lvl#1
  10. {QProp::..., ?{path...}, QOper::..., QValue(...), QRel::...}, // SubExpression lvl#1
  11. {QProp::..., ?{path...}, QOper::..., QValue(...), QRel::...}, // SubExpression lvl#1
  12. {{ // SubExpression lvl#1
  13. {QProp::..., ?{path...}, QOper::..., QValue(...), QRel::...}, // SubExpression lvl#2
  14. {QProp::..., ?{path...}, QOper::..., QValue(...), QRel::...}, // SubExpression lvl#2
  15. {QProp::..., ?{path...}, QOper::..., QValue(...), QRel::...}, // SubExpression lvl#2
  16. }, QRel::...}
  17. }, QRel::...}
  18. }
  19. // Data model
  20. [flag][path][value]
  21. [flag][value:
  22. [size]
  23. [flag][path][value]
  24. [flag][path][value]
  25. [flag][path][value]
  26. [flag][value:
  27. [size]
  28. [flag][path][value]
  29. [flag][path][value]
  30. [flag][path][value]
  31. ]
  32. ]
  33. */
  34. void query_test() {
  35. Variable var = vobj {
  36. {"usr", varr{
  37. vobj{
  38. {"login", "root"},
  39. {"password", "root"},
  40. {"access_lvl", 0xFF_ui8},
  41. {"user_data", vobj{}},
  42. {"attributes", varr{"full_access", "unchangeable"}}
  43. },
  44. vobj{
  45. {"login", "guest"},
  46. {"password", "guest"},
  47. {"access_lvl", 0x00_ui8},
  48. {"user_data", vobj{}},
  49. {"attributes", varr{"ro_access", "unchangeable"}}
  50. },
  51. vobj{
  52. {"login", "admin"},
  53. {"password", "admin"},
  54. {"access_lvl", 0x7f_ui8},
  55. {"user_data", vobj{}},
  56. {"attributes", varr{"unchangeable"}}
  57. }
  58. }},
  59. {"grp", varr{
  60. vobj{
  61. {"name", "system"},
  62. {"attributes", varr{"unremovable"}},
  63. {"users", varr{"root", "guest", "admin"}}
  64. }
  65. }}
  66. };
  67. FileStorage storage("query_test.binomdb", var, true);
  68. std::clog << "Structure RAM:\n" << var << '\n';
  69. NodeVisitor root = var;
  70. FileNodeVisitor froot = storage;
  71. std::clog << "Structure File:\n" << froot.getVariable() << '\n';
  72. Query query = {
  73. {QProp::value, {"access_lvl"}, QOper::highter_equal, 0x00}
  74. };
  75. std::clog << "Finded in RAM container:\n";
  76. for(std::unique_ptr<NodeVisitorBase>& node : root["usr"].findAll(query)) {
  77. std::clog << node->toRAMVisitor().getVariable() << "\n\n";
  78. }
  79. std::clog << "\nFinded in file container:\n";
  80. for(std::unique_ptr<NodeVisitorBase>& node : froot["usr"].findAll(query)) {
  81. std::clog << node->toFileVisitor().getVariable() << "\n\n";
  82. }
  83. }
  84. #endif // QUERY_TEST_H