[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Boxed types for CommonC++
From: |
Marc Boris Dürner |
Subject: |
Boxed types for CommonC++ |
Date: |
Sun, 11 Jan 2004 06:28:13 +0100 (MET) |
Hi,
Here is a proposed boxed type system for CommonC++. Comments?
regards,
Marc
----------------------------------------------------------------------
#include <stdint.h>
template <typename T>
class BoxedType {
public:
BoxedType() : value(0) {}
BoxedType(const T& x) : value(0) {value = x;}
~BoxedType() {}
const T& operator*() const {return value;}
void operator=(const T& x) {value = x;}
BoxedType<T>& operator +=(const BoxedType<T>& x) {value += *x; return
*this;}
bool operator==(const BoxedType<T>& x) const {return value == *x;}
bool operator!=(const BoxedType<T>& x) const {return value != *x;}
bool operator<(const BoxedType<T>& x) const {return value < *x;}
bool operator>(const BoxedType<T>& x) const {return value > *x;}
bool operator<=(const BoxedType<T>& x) const {return value <= *x;}
bool operator>=(const BoxedType<T>& x) const {return value >= *x;}
BoxedType<T> operator&(const BoxedType<T>& x) const {return value & *x;}
BoxedType<T>& operator++() { ++value; return *this; }
BoxedType<T> operator++(int) {BoxedType<T> x = *this; ++*this; return x;
}
BoxedType<T>& operator--() { --value; return *this; }
BoxedType<T> operator--(int) {BoxedType<T> x = *this; --*this; return x;
}
BoxedType<T> operator<<(const int& i) {return value<<i;}
BoxedType<T> operator>>(const int& i) {return value>>i;}
protected:
T value;
};
// integer
typedef BoxedType<int> Int;
typedef BoxedType<long int> LongInt;
typedef BoxedType<long long int> LongLongInt;
typedef BoxedType<int8_t> Int8;
typedef BoxedType<int16_t> Int16;
typedef BoxedType<int32_t> Int32;
typedef BoxedType<int64_t> Int64;
typedef BoxedType<unsigned int> UInt;
typedef BoxedType<unsigned long int> ULongInt;
typedef BoxedType<unsigned long long int> ULongLongInt;
typedef BoxedType<uint8_t> UInt8;
typedef BoxedType<uint16_t> UInt16;
typedef BoxedType<uint32_t> UInt32;
typedef BoxedType<uint64_t> UInt64;
//float
typedef BoxedType<float> Float;
// char
typedef BoxedType<char> Char;
typedef BoxedType<unsigned char> UChar;
--
+++ GMX - die erste Adresse für Mail, Message, More +++
Neu: Preissenkung für MMS und FreeMMS! http://www.gmx.net