diff --git a/common/UpdateType.cc b/common/UpdateType.cc index 8950a21e01cadbf9dd1d1a24212df3936c2ac154..d4cbb5964ca976d3707469b7510a4e7cb95456f8 100644 --- a/common/UpdateType.cc +++ b/common/UpdateType.cc @@ -61,13 +61,14 @@ static std::map< UpdateType , size_t > updateTypeToTypeInfo; */ static UpdateType firstFreeID_(UPDATE_UNUSED); + + UpdateType::UpdateType() :type_(0) { } - UpdateType::UpdateType(const UpdateTypeSet& _set) : type_(_set) { @@ -75,13 +76,13 @@ UpdateType::UpdateType(const UpdateTypeSet& _set) } bool UpdateType::operator==(const UpdateType& _type) const { - return ((type_ & _type.type_).any()); + return ( (type_ & _type.type_) != 0); }; UpdateType UpdateType::operator|(const UpdateType& _type) const { - return (type_ | _type.type_); + return UpdateType(type_|_type.type_); } @@ -106,11 +107,19 @@ bool UpdateType::contains( const UpdateType& _type ) const { return true; } - return ((type_ & _type.type_).any()); + return ( (type_ & _type.type_) != 0 ); } UpdateType& UpdateType::operator++() { - if ( type_.count() != 1 ) { + + UpdateTypeSet check = type_; // count the number of bits set in type_ + unsigned int count; // c accumulates the total bits set in v + for (count = 0; check; count++) + { + check &= check - 1; // clear the least significant bit set + } + + if ( count != 1 ) { std::cerr << "Operator ++ for UpdateType which is not atomic!!" << std::endl; } @@ -120,7 +129,7 @@ UpdateType& UpdateType::operator++() { } bool UpdateType::operator<( const UpdateType& _i ) const { - return (type_.to_ulong() < _i.type_.to_ulong()); + return (type_ < _i.type_); } class UpdateTypeInfo { diff --git a/common/UpdateType.hh b/common/UpdateType.hh index 2778cc7d71b317449100f2ac7c2a8dd48f92798d..ecb9fea052b9361a02cab203e0c1fde74a5b77e6 100644 --- a/common/UpdateType.hh +++ b/common/UpdateType.hh @@ -41,19 +41,10 @@ #pragma once -// Workaround compiler bug in VS2017 and earlier with colliding Qt operators and bitset -#ifdef _MSC_VER - #if (_MSC_VER <= 1916) - #define QT_NO_FLOAT16_OPERATORS - #endif -#endif - - #include <OpenFlipper/common/GlobalDefines.hh> -#include <bitset> #include <QString> -typedef std::bitset<64> UpdateTypeSet; +typedef uint64_t UpdateTypeSet; /** \brief Update type class * @@ -71,7 +62,7 @@ class DLLEXPORT UpdateType { UpdateType(const UpdateType& _type) = default; - UpdateType(const UpdateTypeSet& _set); + explicit UpdateType(const UpdateTypeSet& _set); /// Exact compare operator bool operator==(const UpdateType& _type) const; @@ -109,7 +100,7 @@ const UpdateType UPDATE_NONE( UpdateTypeSet(0) ); const UpdateType UPDATE_ALL( UpdateTypeSet(1) ); /// This is the update identifier for global Object visibility ( show/hide ) -const UpdateType UPDATE_VISIBILITY( UpdateTypeSet(1) << 1 ); +const UpdateType UPDATE_VISIBILITY( UpdateTypeSet(2) ); /** \brief Geometry updated @@ -117,14 +108,14 @@ const UpdateType UPDATE_VISIBILITY( UpdateTypeSet(1) << 1 ); * Updated Geometry ( This update type has to be used if you only modify vertex positions of * an object. Everything else has to stay as before the update. */ -const UpdateType UPDATE_GEOMETRY( UpdateTypeSet(1) << 2 ); +const UpdateType UPDATE_GEOMETRY( UpdateTypeSet(4) ); /** \brief Topology updated * * Updated Topology ( This update type has to be used if you modify the topology * of an object. This includes adding vertices or removing them! ) */ -const UpdateType UPDATE_TOPOLOGY( UpdateTypeSet(1) << 3 ); +const UpdateType UPDATE_TOPOLOGY( UpdateTypeSet(8) ); /** \brief Selection updated @@ -132,60 +123,60 @@ const UpdateType UPDATE_TOPOLOGY( UpdateTypeSet(1) << 3 ); * Updated Selection ( This update type has to be used if you modify the internal * selection of an object. Like selecting a single vertex or a set of faces. ). */ -const UpdateType UPDATE_SELECTION( UpdateTypeSet(1) << 4 ); +const UpdateType UPDATE_SELECTION( UpdateTypeSet(16) ); /** \brief Vertex selection has changed * * This is a more fine grained selection update. UPDATE_SELECTION will also match this update type. */ -const UpdateType UPDATE_SELECTION_VERTICES( UpdateTypeSet(1) << 5 ); +const UpdateType UPDATE_SELECTION_VERTICES( UpdateTypeSet(32) ); /** \brief Edge selection has changed * * This is a more fine grained selection update. UPDATE_SELECTION will also match this update type. */ -const UpdateType UPDATE_SELECTION_EDGES( UpdateTypeSet(1) << 6 ); +const UpdateType UPDATE_SELECTION_EDGES( UpdateTypeSet(64) ); /** \brief Halfedge selection has changed * * This is a more fine grained selection update. UPDATE_SELECTION will also match this update type. */ -const UpdateType UPDATE_SELECTION_HALFEDGES( UpdateTypeSet(1) << 7 ); +const UpdateType UPDATE_SELECTION_HALFEDGES( UpdateTypeSet(128) ); /** \brief Face selection has changed * * This is a more fine grained selection update. UPDATE_SELECTION will also match this update type. */ -const UpdateType UPDATE_SELECTION_FACES( UpdateTypeSet(1) << 8 ); +const UpdateType UPDATE_SELECTION_FACES( UpdateTypeSet(256) ); /** \brief Knot selection has changed * * This is a more fine grained selection update. UPDATE_SELECTION will also match this update type. */ -const UpdateType UPDATE_SELECTION_KNOTS( UpdateTypeSet(1) << 9 ); +const UpdateType UPDATE_SELECTION_KNOTS( UpdateTypeSet(512) ); /** \brief Colors have changed * * Update the colors. This does not have to be called when topology is also updated */ -const UpdateType UPDATE_COLOR( UpdateTypeSet(1) << 10 ); +const UpdateType UPDATE_COLOR( UpdateTypeSet(1024) ); /** \brief Textures have changed * * Update the Textures. */ -const UpdateType UPDATE_TEXTURE( UpdateTypeSet(1) << 11 ); +const UpdateType UPDATE_TEXTURE( UpdateTypeSet(2048) ); /** \brief State has changed * * The object's state (target, source) has changed */ -const UpdateType UPDATE_STATE( UpdateTypeSet(1) << 12 ); +const UpdateType UPDATE_STATE( UpdateTypeSet(4096) ); /// marks the last used ID -const UpdateType UPDATE_UNUSED ( UpdateTypeSet(1) << 13 ); +const UpdateType UPDATE_UNUSED ( UpdateTypeSet(8192) ); /**@}*/