#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.
{
// 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.
* @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.
* @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
/**
* @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;
/**
* @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.
* @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
// 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
{
}
/**
- * @copydoc BitSet::operator[](IndexType)
+ * @copydoc Dali::Accessibility::BitSet::operator[]()
*/
ReferenceType operator[](Enum index)
{
}
private:
+ // For operators '~|&^'
+ EnumBitSet(BitSet<N>&& bitSet)
+ : BitSet<N>(bitSet)
+ {
+ }
+
// No data members (non-virtual destructor)
};