[dali_2.3.42] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / accessibility-bitset.h
index cdb5410..55d9b82 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_ADAPTOR_ACCESSIBILITY_BITSET_H
 
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -36,7 +36,7 @@ namespace Internal
 {
 // Number of 32-bit chunks required to hold N bits
 template<typename Enum, Enum EnumMax, typename = std::enable_if_t<std::is_enum_v<Enum>>>
-inline constexpr std::size_t BitSetSize = (static_cast<std::size_t>(EnumMax) + 31u) / 32u;
+constexpr std::size_t BitSetSize = (static_cast<std::size_t>(EnumMax) + 31u) / 32u;
 
 /**
  * @brief A writable reference to a single bit.
@@ -45,12 +45,12 @@ inline constexpr std::size_t BitSetSize = (static_cast<std::size_t>(EnumMax) + 3
  * @code std::uint32_t x = 0; x[5] = true; @endcode is not possible. The BitSet type uses this proxy
  * class to make such operations possible.
  *
- * @see Accessibility::BitSet
+ * @see Dali::Accessibility::BitSet
  */
-class DALI_ADAPTOR_API BitReference
+class BitReference
 {
   template<std::size_t>
-  friend class Accessibility::BitSet;
+  friend class Dali::Accessibility::BitSet;
 
 public:
   using ElementType = std::uint32_t; ///< Integral type used for storing bits.
@@ -121,14 +121,14 @@ private:
  * @tparam N Number of 32-bit chunks (the capacity of this BitSet is 32*N).
  */
 template<std::size_t N>
-class DALI_ADAPTOR_API BitSet
+class BitSet
 {
 public:
   // Types
 
-  using ReferenceType = Internal::BitReference;     ///< @copybrief Dali::Accessibility::Internal::BitReference
-  using ElementType   = ReferenceType::ElementType; ///< @copydoc Dali::Accessibility::Internal::BitReference::ElementType
-  using IndexType     = ReferenceType::IndexType;   ///< @copydoc Dali::Accessibility::Internal::BitReference::IndexType
+  using ReferenceType = Internal::BitReference;     ///< Dali::Accessibility::Internal::BitReference
+  using ElementType   = ReferenceType::ElementType; ///< Dali::Accessibility::Internal::BitReference::ElementType
+  using IndexType     = ReferenceType::IndexType;   ///< Dali::Accessibility::Internal::BitReference::IndexType
   using ArrayType     = std::array<ElementType, N>; ///< An array of N integers that can store 32*N bits.
 
   // Constructors
@@ -169,6 +169,22 @@ public:
   /**
    * @brief Constructs a new BitSet with all bits initialized with bits from the specified integer.
    *
+   * This constructor is only available for BitSets with 32-bit capacity. Equivalent to the pseudocode:
+   * @code
+   * for(i = 0; i < 32; ++i) bits[i] = (data >> i) & 0x1;
+   * @endcode
+   *
+   * @param data 32-bit integer with the initial values.
+   */
+  template<std::size_t I = N, typename = std::enable_if_t<(I == N && N == 1u)>>
+  explicit BitSet(std::uint32_t data)
+  {
+    mData[0] = data;
+  }
+
+  /**
+   * @brief Constructs a new BitSet with all bits initialized with bits from the specified integer.
+   *
    * This constructor is only available for BitSets with 64-bit capacity. Equivalent to the pseudocode:
    * @code
    * for(i = 0; i < 64; ++i) bits[i] = (data >> i) & 0x1;
@@ -360,6 +376,21 @@ public:
   /**
    * @brief Obtains a copy of the internal storage serialized as a single integer.
    *
+   * This method is only available for BitSets with 32-bit capacity.
+   *
+   * @return A copy of the internal storage.
+   *
+   * @see BitSet::BitSet(std::uint32_t)
+   */
+  template<std::size_t I = N, typename = std::enable_if_t<(I == N && N == 1u)>>
+  std::uint32_t GetRawData32() const
+  {
+    return mData[0];
+  }
+
+  /**
+   * @brief Obtains a copy of the internal storage serialized as a single integer.
+   *
    * This method is only available for BitSets with 64-bit capacity.
    *
    * @return A copy of the internal storage.
@@ -406,16 +437,14 @@ private:
  * @see Dali::Accessibility::Accessible::GetStates
  * @see Dali::Accessibility::Accessible::GetRoles
  */
-template<typename Enum, Enum EnumMax>
-class DALI_ADAPTOR_API EnumBitSet : public BitSet<Internal::BitSetSize<Enum, EnumMax>>
+template<typename Enum, Enum EnumMax, std::size_t N = Internal::BitSetSize<Enum, EnumMax>>
+class EnumBitSet : public BitSet<N>
 {
-  static constexpr std::size_t N = Internal::BitSetSize<Enum, EnumMax>;
-
 public:
   // Types
 
-  using IndexType     = typename BitSet<N>::IndexType;     ///< @copydoc BitSet::IndexType
-  using ReferenceType = typename BitSet<N>::ReferenceType; ///< @copydoc BitSet::ReferenceType
+  using IndexType     = typename BitSet<N>::IndexType;     ///< Dali::Accessibility::BitSet<N>::IndexType
+  using ReferenceType = typename BitSet<N>::ReferenceType; ///< Dali::Accessibility::BitSet<N>::ReferenceType
 
   // Constructors
 
@@ -424,7 +453,46 @@ public:
   // Operators
 
   /**
-   * @copydoc BitSet::operator[](IndexType) const
+   * @copydoc Dali::Accessibility::BitSet::operator~() const
+   */
+  EnumBitSet operator~() const
+  {
+    return BitSet<N>::operator~();
+  }
+
+  /**
+   * @copydoc Dali::Accessibility::BitSet::operator|(const BitSet&) const
+   */
+  EnumBitSet operator|(const EnumBitSet& other) const
+  {
+    return BitSet<N>::operator|(other);
+  }
+
+  /**
+   * @copydoc Dali::Accessibility::BitSet::operator&(const BitSet&) const
+   */
+  EnumBitSet operator&(const EnumBitSet& other) const
+  {
+    return BitSet<N>::operator&(other);
+  }
+
+  /**
+   * @copydoc Dali::Accessibility::BitSet::operator^(const BitSet&) const
+   */
+  EnumBitSet operator^(const EnumBitSet& other) const
+  {
+    return BitSet<N>::operator^(other);
+  }
+
+  /**
+   * @brief Queries the value of the specified bit.
+   *
+   * This operator is used in expressions like @code bool b = bitset[i]; @endcode
+   *
+   * @note Since doxygen version 1.9.8 (Which is default of Ubuntu24.04) have some bug, copydoc not working.
+   *
+   * @param index Index of the bit to query.
+   * @return true if the specified bit is set to 1, false if it is set to 0.
    */
   bool operator[](Enum index) const
   {
@@ -432,7 +500,7 @@ public:
   }
 
   /**
-   * @copydoc BitSet::operator[](IndexType)
+   * @copydoc Dali::Accessibility::BitSet::operator[]()
    */
   ReferenceType operator[](Enum index)
   {
@@ -440,6 +508,12 @@ public:
   }
 
 private:
+  // For operators '~|&^'
+  EnumBitSet(BitSet<N>&& bitSet)
+  : BitSet<N>(bitSet)
+  {
+  }
+
   // No data members (non-virtual destructor)
 };