Token.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /*!
  15. * @file Token.h
  16. */
  17. #ifndef _FASTDDS_RTPS_COMMON_TOKEN_H_
  18. #define _FASTDDS_RTPS_COMMON_TOKEN_H_
  19. #include <fastrtps/fastrtps_dll.h>
  20. #include <fastdds/rtps/common/Property.h>
  21. #include <fastdds/rtps/common/BinaryProperty.h>
  22. namespace eprosima {
  23. namespace fastrtps {
  24. namespace rtps {
  25. class DataHolder
  26. {
  27. public:
  28. DataHolder() {}
  29. DataHolder(const DataHolder& data_holder) :
  30. class_id_(data_holder.class_id_),
  31. properties_(data_holder.properties_),
  32. binary_properties_(data_holder.binary_properties_) {}
  33. DataHolder(DataHolder&& data_holder) :
  34. class_id_(data_holder.class_id_),
  35. properties_(data_holder.properties_),
  36. binary_properties_(data_holder.binary_properties_) {}
  37. DataHolder& operator=(const DataHolder& data_holder)
  38. {
  39. class_id_ = data_holder.class_id_;
  40. properties_ = data_holder.properties_;
  41. binary_properties_ = data_holder.binary_properties_;
  42. return *this;
  43. }
  44. DataHolder& operator=(DataHolder&& data_holder)
  45. {
  46. class_id_ = std::move(data_holder.class_id_);
  47. properties_ = std::move(data_holder.properties_);
  48. binary_properties_ = std::move(data_holder.binary_properties_);
  49. return *this;
  50. }
  51. bool is_nil() const
  52. {
  53. return class_id_.empty();
  54. }
  55. void class_id(const std::string& class_id)
  56. {
  57. class_id_ = class_id;
  58. }
  59. void class_id(std::string&& class_id)
  60. {
  61. class_id_ = std::move(class_id);
  62. }
  63. std::string& class_id()
  64. {
  65. return class_id_;
  66. }
  67. const std::string& class_id() const
  68. {
  69. return class_id_;
  70. }
  71. const PropertySeq& properties() const
  72. {
  73. return properties_;
  74. }
  75. PropertySeq& properties()
  76. {
  77. return properties_;
  78. }
  79. const BinaryPropertySeq& binary_properties() const
  80. {
  81. return binary_properties_;
  82. }
  83. BinaryPropertySeq& binary_properties()
  84. {
  85. return binary_properties_;
  86. }
  87. private:
  88. std::string class_id_;
  89. PropertySeq properties_;
  90. BinaryPropertySeq binary_properties_;
  91. };
  92. typedef std::vector<DataHolder> DataHolderSeq;
  93. typedef DataHolder Token;
  94. typedef Token IdentityToken;
  95. typedef Token IdentityStatusToken;
  96. typedef Token PermissionsToken;
  97. typedef Token AuthenticatedPeerCredentialToken;
  98. typedef Token PermissionsCredentialToken;
  99. class DataHolderHelper
  100. {
  101. public:
  102. static std::string* find_property_value(DataHolder& data_holder, const std::string& name);
  103. static const std::string* find_property_value(const DataHolder& data_holder, const std::string& name);
  104. static Property* find_property(DataHolder& data_holder, const std::string& name);
  105. static const Property* find_property(const DataHolder& data_holder, const std::string& name);
  106. static std::vector<uint8_t>* find_binary_property_value(DataHolder& data_holder, const std::string& name);
  107. static const std::vector<uint8_t>* find_binary_property_value(const DataHolder& data_holder, const std::string& name);
  108. static BinaryProperty* find_binary_property(DataHolder& data_holder, const std::string& name);
  109. static const BinaryProperty* find_binary_property(const DataHolder& data_holder, const std::string& name);
  110. static size_t serialized_size(const DataHolder& data_holder, size_t current_alignment = 0);
  111. static size_t serialized_size(const DataHolderSeq& data_holders, size_t current_alignment = 0);
  112. private:
  113. inline static size_t alignment(size_t current_alignment, size_t dataSize) { return (dataSize - (current_alignment % dataSize)) & (dataSize-1);}
  114. };
  115. } //namespace rtps
  116. } //namespace fastrtps
  117. } //namespace eprosima
  118. #endif // _FASTDDS_RTPS_COMMON_TOKEN_H_