|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r62266 - in sandbox/SOC/2010/bit_masks: . boost/integer
From: bbartmanboost_at_[hidden]
Date: 2010-05-27 12:30:43
Author: bbartman
Date: 2010-05-27 12:30:42 EDT (Thu, 27 May 2010)
New Revision: 62266
URL: http://svn.boost.org/trac/boost/changeset/62266
Log:
refactoring from overloads using an implicit conversion/casting operator
Text files modified:
sandbox/SOC/2010/bit_masks/boost/integer/bit_mask.hpp | 42 --------------------
sandbox/SOC/2010/bit_masks/boost/integer/high_low_bits.hpp | 80 ----------------------------------------
sandbox/SOC/2010/bit_masks/boost/integer/integral_mask.hpp | 44 +---------------------
sandbox/SOC/2010/bit_masks/notes.txt | 58 ++++++++++++++++++++++-------
4 files changed, 47 insertions(+), 177 deletions(-)
Modified: sandbox/SOC/2010/bit_masks/boost/integer/bit_mask.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/bit_mask.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/bit_mask.hpp 2010-05-27 12:30:42 EDT (Thu, 27 May 2010)
@@ -46,51 +46,11 @@
BOOST_STATIC_CONSTANT(unsigned int, width = Width);
- T operator()() {
+ operator T() {
return type::value;
}
};
-// Runtime support functions.
-
-// Overloads for bitwise and
-template <typename T, unsigned int Offset, unsigned int Width>
-inline T operator&(T t, bit_mask<T,Offset,Width> ) {
- return t & bit_mask<T, Offset, Width>::value;
-}
-
-template <typename T, unsigned int Offset, unsigned int Width>
-inline T operator&(bit_mask<T,Offset,Width>, T t) {
- return bit_mask<T,Offset,Width>::value & t;
-}
-
-// Overloads for bitwise or
-template <typename T, unsigned int Offset, unsigned int Width>
-inline T operator|(T t, bit_mask<T,Offset,Width>) {
- return t | bit_mask<T,Offset,Width>::value;
-}
-
-template <typename T, unsigned int Offset, unsigned int Width>
-inline T operator|(bit_mask<T,Offset,Width>, T t) {
- return bit_mask<T,Offset,Width>::value | t;
-}
-
-// Overloads for bitwise xor
-template <typename T, unsigned int Offset, unsigned int Width>
-inline T operator^(T t, bit_mask<T,Offset,Width>) {
- return t ^ bit_mask<T,Offset,Width>::value;
-}
-
-template <typename T, unsigned int Offset, unsigned int Width>
-inline T operator^(bit_mask<T,Offset,Width>, T t) {
- return bit_mask<T,Offset,Width>::value ^ t;
-}
-
-template <typename T, unsigned int Offset, unsigned int Width>
-inline T operator~(bit_mask<T,Offset,Width>) {
- return ~( bit_mask<T,Offset,Width>::value );
-}
-
} // namespace boost
Modified: sandbox/SOC/2010/bit_masks/boost/integer/high_low_bits.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/high_low_bits.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/high_low_bits.hpp 2010-05-27 12:30:42 EDT (Thu, 27 May 2010)
@@ -43,86 +43,6 @@
BOOST_STATIC_CONSTANT(unsigned int, width = Width);
};
-
-// Low_bits runtime support functions.
-// Overloads for bitwise and
-template <typename T, unsigned int Width>
-inline T operator&(T t, low_bits<T,Width> ) {
- return t & low_bits<T,Width>::value;
-}
-
-template <typename T, unsigned int Width>
-inline T operator&(low_bits<T,Width>, T t) {
- return low_bits<T,Width>::value & t;
-}
-
-// Overloads for bitwise or
-template <typename T, unsigned int Width>
-inline T operator|(T t, low_bits<T,Width>) {
- return t | low_bits<T,Width>::value;
-}
-
-template <typename T, unsigned int Width>
-inline T operator|(low_bits<T,Width>, T t) {
- return low_bits<T,Width>::value | t;
-}
-
-// Overloads for bitwise xor
-template <typename T, unsigned int Width>
-inline T operator^(T t, low_bits<T,Width>) {
- return t ^ low_bits<T,Width>::value;
-}
-
-template <typename T, unsigned int Width>
-inline T operator^(low_bits<T,Width>, T t) {
- return low_bits<T,Width>::value ^ t;
-}
-
-template <typename T, unsigned int Width>
-inline T operator~(low_bits<T,Width>) {
- return ~( low_bits<T,Width>::value );
-}
-
-
-// high_bits runtime support functions.
-// Overloads for bitwise and
-template <typename T, unsigned int Width>
-inline T operator&(T t, high_bits<T,Width> ) {
- return t & high_bits<T,Width>::value;
-}
-
-template <typename T, unsigned int Width>
-inline T operator&(high_bits<T,Width>, T t) {
- return high_bits<T,Width>::value & t;
-}
-
-// Overloads for bitwise or
-template <typename T, unsigned int Width>
-inline T operator|(T t, high_bits<T,Width>) {
- return t | high_bits<T,Width>::value;
-}
-
-template <typename T, unsigned int Width>
-inline T operator|(high_bits<T,Width>, T t) {
- return high_bits<T,Width>::value | t;
-}
-
-// Overloads for bitwise xor
-template <typename T, unsigned int Width>
-inline T operator^(T t, high_bits<T,Width>) {
- return t ^ high_bits<T,Width>::value;
-}
-
-template <typename T, unsigned int Width>
-inline T operator^(high_bits<T,Width>, T t) {
- return high_bits<T,Width>::value ^ t;
-}
-
-template <typename T, unsigned int Width>
-inline T operator~(high_bits<T,Width>) {
- return ~( high_bits<T,Width>::value );
-}
-
} // namespace boost
#endif
Modified: sandbox/SOC/2010/bit_masks/boost/integer/integral_mask.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/integral_mask.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/integral_mask.hpp 2010-05-27 12:30:42 EDT (Thu, 27 May 2010)
@@ -33,51 +33,11 @@
{
typedef integral_mask<T,Value> type;
- T operator()() {
+ operator T() {
return type::value;
}
-};
-
-
-// runtime support functions.
-
-// Overloads for bitwise and
-template <typename T, unsigned int Value>
-inline T operator&(T t, integral_mask<T,Value> ) {
- return t & integral_mask<T,Value>::value;
-}
-
-template <typename T, unsigned int Value>
-inline T operator&(integral_mask<T,Value>, T t) {
- return integral_mask<T,Value>::value & t;
-}
-// Overloads for bitwise or
-template <typename T, unsigned int Value>
-inline T operator|(T t, integral_mask<T,Value>) {
- return t | integral_mask<T,Value>::value;
-}
-
-template <typename T, unsigned int Value>
-inline T operator|(integral_mask<T,Value>, T t) {
- return integral_mask<T,Value>::value | t;
-}
-
-// Overloads for bitwise xor
-template <typename T, unsigned int Value>
-inline T operator^(T t, integral_mask<T,Value>) {
- return t ^ integral_mask<T,Value>::value;
-}
-
-template <typename T, unsigned int Value>
-inline T operator^(integral_mask<T,Value>, T t) {
- return integral_mask<T,Value>::value ^ t;
-}
-
-template <typename T, unsigned int Width>
-inline T operator~(integral_mask<T,Width>) {
- return ~( integral_mask<T,Width>::value );
-}
+};
} // namespace boost
Modified: sandbox/SOC/2010/bit_masks/notes.txt
==============================================================================
--- sandbox/SOC/2010/bit_masks/notes.txt (original)
+++ sandbox/SOC/2010/bit_masks/notes.txt 2010-05-27 12:30:42 EDT (Thu, 27 May 2010)
@@ -152,18 +152,14 @@
This meta-function will evaluate to true or false if the bit is or isn't false.
template <typename T, unsigned int N>
-struct test_bit
- :integral_constant< bool, (T::value & (low_bits<T::value_type,1>::value << N) >
-{ };
+struct test_mask_bit;
Compile time flip_bit meta-function
Intent is to specify either a single bit or all bits to be fliped. This meta-function
will require one specilization as wll for std::numeric_limits<unsigned int>::max.
template <typename T, unsigned int N = std::numeric_limits<unsigned int>::max >
-struct flip_bits
- :integral_constant<T::value_type, ( ) >
-{ };
+struct flip_mask_bit;
@@ -175,14 +171,7 @@
template <typename T, unsigned int N = std::numeric_limits<unsigned int>::max>
-struct clear_bit
- :integral_constant<T::value_type,(
- ( test_bit<T,N>::value ) ?
- ( T::value ^ ( low_bits<T::value_type,1>::value << N) )
- :
- ( test_bit<T,N>::value )
- ) >
-{ };
+struct clear_mask_bit;
compile time + runtime interface.
@@ -190,7 +179,48 @@
These are functors which provide runtime support for preforming regular masking
operations with complie time composed masks.
+ Compile + run time set interface.
+All masks should be hidden unless one is supplied as a template parameter?
+however the internal mask created will be availiable always its just that the user
+may not want to actually see it or have to use it themselves.
+
+template <typename T, size_t N>
+struct set_bit
+{
+ void operator() ( T::value_type& bits );
+};
+ Compile + run time test interface.
+
+ Compile + run time flip interface.
+ Compile + run time clear interface.
+
+
+
+
runtime only interface.
+ runtime test
+This will throw a domain error if N is greater then the bit_width of T.
+template <typename T>
+bool test_bit(T bits, size_t N);
+
+
+
+ runtime set
+This will throw a domain error if N is greater then the bit_width of T.
+template <typename T>
+void set_bit(T& bits, size_t N);
+
+
+ runtime clear
+This will throw a domain error if N is greater then the bit_width of T.
+template <typename T>
+void clear_bit(T& bits, size_t N);
+
+
+ runtime flip
+This will throw a domain error if N is greater then the bit_width of T.
+template <typename T>
+void flip_bit(T& bits, size_t N);
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk