Merge branch 'master' into jgrpp-beta
# Conflicts: # src/economy.cpp # src/elrail.cpp # src/graph_gui.cpp # src/linkgraph/linkgraph_gui.cpp # src/network/core/game_info.cpp # src/newgrf_station.cpp # src/saveload/saveload.cpp # src/settings.cpp # src/station_cmd.cpp # src/station_gui.cpp # src/strings_func.h # src/table/settings/network_settings.ini # src/table/settings/settings.ini
This commit is contained in:
@@ -356,45 +356,55 @@ static inline T ROR(const T x, const uint8 n)
|
||||
return (T)(x >> n | x << (sizeof(x) * 8 - n));
|
||||
}
|
||||
|
||||
/**
|
||||
* Do an operation for each set bit in a value.
|
||||
*
|
||||
* This macros is used to do an operation for each set
|
||||
* bit in a variable. The second parameter is a
|
||||
* variable that is used as the bit position counter.
|
||||
* The fourth parameter is an expression of the bits
|
||||
* we need to iterate over. This expression will be
|
||||
* evaluated once.
|
||||
*
|
||||
* @param Tbitpos_type Type of the position counter variable.
|
||||
* @param bitpos_var The position counter variable.
|
||||
* @param Tbitset_type Type of the bitset value.
|
||||
* @param bitset_value The bitset value which we check for bits.
|
||||
*
|
||||
* @see FOR_EACH_SET_BIT
|
||||
*/
|
||||
#define FOR_EACH_SET_BIT_EX(Tbitpos_type, bitpos_var, Tbitset_type, bitset_value) \
|
||||
for ( \
|
||||
Tbitset_type ___FESBE_bits = (bitpos_var = (Tbitpos_type)0, bitset_value); \
|
||||
___FESBE_bits != (Tbitset_type)0; \
|
||||
___FESBE_bits = (Tbitset_type)(___FESBE_bits >> 1), bitpos_var++ \
|
||||
) \
|
||||
if ((___FESBE_bits & 1) != 0)
|
||||
/**
|
||||
* Iterable ensemble of each set bit in a value.
|
||||
* @tparam Tbitpos Type of the position variable.
|
||||
* @tparam Tbitset Type of the bitset value.
|
||||
*/
|
||||
template <typename Tbitpos = uint, typename Tbitset = uint>
|
||||
struct SetBitIterator {
|
||||
struct Iterator {
|
||||
typedef Tbitpos value_type;
|
||||
typedef value_type *pointer;
|
||||
typedef value_type &reference;
|
||||
typedef size_t difference_type;
|
||||
typedef std::forward_iterator_tag iterator_category;
|
||||
|
||||
/**
|
||||
* Do an operation for each set set bit in a value.
|
||||
*
|
||||
* This macros is used to do an operation for each set
|
||||
* bit in a variable. The first parameter is a variable
|
||||
* that is used as the bit position counter.
|
||||
* The second parameter is an expression of the bits
|
||||
* we need to iterate over. This expression will be
|
||||
* evaluated once.
|
||||
*
|
||||
* @param bitpos_var The position counter variable.
|
||||
* @param bitset_value The value which we check for set bits.
|
||||
*/
|
||||
#define FOR_EACH_SET_BIT(bitpos_var, bitset_value) FOR_EACH_SET_BIT_EX(uint, bitpos_var, uint, bitset_value)
|
||||
explicit Iterator(Tbitset bitset) : bitset(bitset), bitpos(static_cast<Tbitpos>(0))
|
||||
{
|
||||
this->Validate();
|
||||
}
|
||||
|
||||
bool operator==(const Iterator &other) const
|
||||
{
|
||||
return this->bitset == other.bitset && (this->bitset == 0 || this->bitpos == other.bitpos);
|
||||
}
|
||||
bool operator!=(const Iterator &other) const { return !(*this == other); }
|
||||
Tbitpos operator*() const { return this->bitpos; }
|
||||
Iterator & operator++() { this->Next(); this->Validate(); return *this; }
|
||||
|
||||
private:
|
||||
Tbitset bitset;
|
||||
Tbitpos bitpos;
|
||||
void Validate()
|
||||
{
|
||||
while (this->bitset != 0 && (this->bitset & 1) == 0) this->Next();
|
||||
}
|
||||
void Next()
|
||||
{
|
||||
this->bitset = static_cast<Tbitset>(this->bitset >> 1);
|
||||
this->bitpos++;
|
||||
}
|
||||
};
|
||||
|
||||
SetBitIterator(Tbitset bitset) : bitset(bitset) {}
|
||||
Iterator begin() { return Iterator(this->bitset); }
|
||||
Iterator end() { return Iterator(static_cast<Tbitset>(0)); }
|
||||
bool empty() { return this->begin() == this->end(); }
|
||||
|
||||
private:
|
||||
Tbitset bitset;
|
||||
};
|
||||
|
||||
#if defined(__APPLE__)
|
||||
/* Make endian swapping use Apple's macros to increase speed
|
||||
|
Reference in New Issue
Block a user