keyword.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // This file is part of BOINC.
  2. // http://boinc.berkeley.edu
  3. // Copyright (C) 2017 University of California
  4. //
  5. // BOINC is free software; you can redistribute it and/or modify it
  6. // under the terms of the GNU Lesser General Public License
  7. // as published by the Free Software Foundation,
  8. // either version 3 of the License, or (at your option) any later version.
  9. //
  10. // BOINC is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. // See the GNU Lesser General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Lesser General Public License
  16. // along with BOINC. If not, see <http://www.gnu.org/licenses/>.
  17. // utility classes for keywords
  18. #ifndef BOINC_KEYWORD_H
  19. #define BOINC_KEYWORD_H
  20. #include <vector>
  21. #include <map>
  22. #include "parse.h"
  23. // a keyword
  24. //
  25. struct KEYWORD {
  26. int id;
  27. std::string name;
  28. std::string description;
  29. int parent;
  30. int level;
  31. int category;
  32. void write_xml(MIOFILE&);
  33. int parse(XML_PARSER&);
  34. };
  35. // the set of all keywords
  36. //
  37. struct KEYWORDS {
  38. std::map<int, KEYWORD> keywords;
  39. bool present;
  40. KEYWORDS() {
  41. present = false;
  42. }
  43. int parse(XML_PARSER&);
  44. inline KEYWORD& get(int id) {return keywords[id];}
  45. };
  46. // a user's keyword preferences
  47. //
  48. struct USER_KEYWORDS {
  49. std::vector<int> yes;
  50. std::vector<int> no;
  51. int parse(XML_PARSER&);
  52. inline void clear() {
  53. yes.clear();
  54. no.clear();
  55. }
  56. void write(FILE*);
  57. inline bool empty() {
  58. return yes.empty() && no.empty();
  59. }
  60. };
  61. // the keywords IDs associated with a job (workunit)
  62. //
  63. struct JOB_KEYWORD_IDS {
  64. std::vector<int> ids;
  65. void parse_str(char*);
  66. // parse space-separated list
  67. inline bool empty() {
  68. return ids.empty();
  69. }
  70. inline void clear() {
  71. ids.clear();
  72. }
  73. void write_xml_text(MIOFILE&, KEYWORDS&);
  74. void write_xml_num(MIOFILE&);
  75. };
  76. // same, but the entire keyword objects (for GUI RPC client)
  77. //
  78. struct JOB_KEYWORDS {
  79. std::vector<KEYWORD> keywords;
  80. inline bool empty() {
  81. return keywords.empty();
  82. }
  83. inline void clear() {
  84. keywords.clear();
  85. }
  86. int parse(XML_PARSER&);
  87. };
  88. #endif