FieldRepeated_GetSet.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. {#
  2. Copyright (C) 2020 Embedded AMS B.V. - All Rights Reserved
  3. This file is part of Embedded Proto.
  4. Embedded Proto is open source software: you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation, version 3 of the license.
  7. Embedded Proto is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with Embedded Proto. If not, see <https://www.gnu.org/licenses/>.
  13. For commercial and closed source application please visit:
  14. <https://EmbeddedProto.com/license/>.
  15. Embedded AMS B.V.
  16. Info:
  17. info at EmbeddedProto dot com
  18. Postal address:
  19. Johan Huizingalaan 763a
  20. 1066 VH, Amsterdam
  21. the Netherlands
  22. #}
  23. {% if field.oneof is not none %}
  24. inline void clear_{{field.get_name()}}()
  25. {
  26. if(id::{{field.get_variable_id_name()}} == {{field.get_which_oneof()}})
  27. {
  28. {{field.get_which_oneof}} = id::NOT_SET;
  29. {{field.get_variable_name()}}.~{{field.get_short_type()}}();
  30. }
  31. }
  32. inline void set_{{field.get_name()}}(uint32_t index, const {{field.get_type()}}& value)
  33. {
  34. if(id::{{field.get_variable_id_name()}} != {{field.get_which_oneof()}})
  35. {
  36. init_{{field.get_oneof_name()}}(id::{{field.get_variable_id_name()}});
  37. }
  38. {{field.get_variable_name()}}.set(index, value);
  39. }
  40. inline void set_{{field.get_name()}}(uint32_t index, const {{field.get_type()}}&& value)
  41. {
  42. if(id::{{field.get_variable_id_name()}} != {{field.get_which_oneof()}})
  43. {
  44. init_{{field.get_oneof_name()}}(id::{{field.get_variable_id_name()}});
  45. }
  46. {{field.get_variable_name()}}.set(index, value);
  47. }
  48. inline void set_{{field.get_name()}}(const {{field.repeated_type}}& values)
  49. {
  50. if(id::{{field.get_variable_id_name()}} != {{field.get_which_oneof()}})
  51. {
  52. init_{{field.get_oneof_name()}}(id::{{field.get_variable_id_name()}});
  53. }
  54. {{field.get_variable_name()}} = values;
  55. }
  56. inline void add_{{field.get_name()}}(const {{field.get_type()}}& value)
  57. {
  58. if(id::{{field.get_variable_id_name()}} != {{field.get_which_oneof()}})
  59. {
  60. init_{{field.get_oneof_name()}}(id::{{field.get_variable_id_name()}});
  61. }
  62. {{field.get_variable_name()}}.add(value);
  63. }
  64. inline {{field.repeated_type}}& mutable_{{field.get_name()}}()
  65. {
  66. if(id::{{field.get_variable_id_name()}} != {{field.get_which_oneof()}})
  67. {
  68. init_{{field.get_oneof_name()}}(id::{{field.get_variable_id_name()}});
  69. }
  70. return {{field.get_variable_name()}};
  71. }
  72. {% else %}
  73. inline const {{field.get_base_type()}}& {{field.get_name()}}(uint32_t index) const { return {{field.get_variable_name()}}[index]; }
  74. inline void clear_{{field.get_name()}}() { {{field.get_variable_name()}}.clear(); }
  75. inline void set_{{field.get_name()}}(uint32_t index, const {{field.get_base_type()}}& value) { {{field.get_variable_name()}}.set(index, value); }
  76. inline void set_{{field.get_name()}}(uint32_t index, const {{field.get_base_type()}}&& value) { {{field.get_variable_name()}}.set(index, value); }
  77. inline void set_{{field.get_name()}}(const {{field.get_type()}}& values) { {{field.get_variable_name()}} = values; }
  78. inline void add_{{field.get_name()}}(const {{field.get_base_type()}}& value) { {{field.get_variable_name()}}.add(value); }
  79. inline {{field.get_type()}}& mutable_{{field.get_name()}}() { return {{field.get_variable_name()}}; }
  80. inline {{field.get_base_type()}}& mutable_{{field.get_name()}}(uint32_t index) { return {{field.get_variable_name()}}[index]; }
  81. {% endif %}
  82. inline const {{field.get_type()}}& get_{{field.get_name()}}() const { return {{field.get_variable_name()}}; }
  83. inline const {{field.get_type()}}& {{field.get_name()}}() const { return {{field.get_variable_name()}}; }