PropertyPolicy.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 PropertyPolicy.h
  16. */
  17. #ifndef _FASTDDS_RTPS_ATTRIBUTES_PROPERTYPOLICY_H_
  18. #define _FASTDDS_RTPS_ATTRIBUTES_PROPERTYPOLICY_H_
  19. #include <fastdds/rtps/common/Property.h>
  20. #include <fastdds/rtps/common/BinaryProperty.h>
  21. #include <fastrtps/fastrtps_dll.h>
  22. namespace eprosima {
  23. namespace fastrtps {
  24. namespace rtps {
  25. class PropertyPolicy
  26. {
  27. public:
  28. RTPS_DllAPI PropertyPolicy() {}
  29. RTPS_DllAPI PropertyPolicy(const PropertyPolicy& property_policy) :
  30. properties_(property_policy.properties_),
  31. binary_properties_(property_policy.binary_properties_) {}
  32. RTPS_DllAPI PropertyPolicy(PropertyPolicy&& property_policy) :
  33. properties_(std::move(property_policy.properties_)),
  34. binary_properties_(std::move(property_policy.binary_properties_)) {}
  35. RTPS_DllAPI PropertyPolicy& operator=(const PropertyPolicy& property_policy)
  36. {
  37. properties_ = property_policy.properties_;
  38. binary_properties_ = property_policy.binary_properties_;
  39. return *this;
  40. }
  41. RTPS_DllAPI PropertyPolicy& operator=(PropertyPolicy&& property_policy)
  42. {
  43. properties_ = std::move(property_policy.properties_);
  44. binary_properties_= std::move(property_policy.binary_properties_);
  45. return *this;
  46. }
  47. RTPS_DllAPI bool operator==(const PropertyPolicy& b) const
  48. {
  49. return (this->properties_ == b.properties_) &&
  50. (this->binary_properties_ == b.binary_properties_);
  51. }
  52. //!Get properties
  53. RTPS_DllAPI const PropertySeq& properties() const
  54. {
  55. return properties_;
  56. }
  57. //!Set properties
  58. RTPS_DllAPI PropertySeq& properties()
  59. {
  60. return properties_;
  61. }
  62. //!Get binary_properties
  63. RTPS_DllAPI const BinaryPropertySeq& binary_properties() const
  64. {
  65. return binary_properties_;
  66. }
  67. //!Set binary_properties
  68. RTPS_DllAPI BinaryPropertySeq& binary_properties()
  69. {
  70. return binary_properties_;
  71. }
  72. private:
  73. PropertySeq properties_;
  74. BinaryPropertySeq binary_properties_;
  75. };
  76. class PropertyPolicyHelper
  77. {
  78. public:
  79. /*!
  80. * @brief Returns only the properties whose name starts with the prefix.
  81. * Prefix is removed in returned properties.
  82. * @param property_policy PropertyPolicy where properties will be searched.
  83. * @param prefix Prefix used to search properties.
  84. * @return A copy of properties whose name starts with the prefix.
  85. */
  86. RTPS_DllAPI static PropertyPolicy get_properties_with_prefix(
  87. const PropertyPolicy& property_policy,
  88. const std::string& prefix);
  89. //!Get the length of the property_policy
  90. RTPS_DllAPI static size_t length(const PropertyPolicy& property_policy);
  91. //!Look for a property_policy by name
  92. RTPS_DllAPI static std::string* find_property(
  93. PropertyPolicy& property_policy,
  94. const std::string& name);
  95. //!Retrieves a property_policy by name
  96. RTPS_DllAPI static const std::string* find_property(
  97. const PropertyPolicy& property_policy,
  98. const std::string& name);
  99. };
  100. } //namespace rtps
  101. } //namespace fastrtps
  102. } //namespace eprosima
  103. #endif // _FASTDDS_RTPS_ATTRIBUTES_PROPERTYPOLICY_H_