27 #include <sys/types.h>
81 SDNV(
const E value) : _value(value) {
113 return static_cast<T
>(_value);
116 const E&
get()
const {
127 return (value == _value);
132 return (value._value == _value);
137 return (value != _value);
142 return (value._value != _value);
147 E result = _value + value;
153 E result = _value + value._value;
181 _value += value._value;
200 E result = _value - value;
206 E result = _value - value._value;
234 _value -= value._value;
253 E result = _value / value;
259 E result = _value / value._value;
287 _value /= value._value;
293 E result = _value * value;
299 E result = _value * value._value;
327 _value *= value._value;
333 return (value._value & _value);
338 return (value._value | _value);
343 _value &= value._value;
349 _value |= value._value;
355 return (_value < value);
360 return (_value <= value);
365 return (_value > value);
370 return (_value >= value);
373 bool operator<(const SDNV<E> &value)
const
375 return (_value < value._value);
378 bool operator<=(const SDNV<E> &value)
const
380 return (_value <= value._value);
385 return (_value > value._value);
390 return (_value >= value._value);
395 return std::numeric_limits<E>::max();
401 uint32_t val =
static_cast<uint32_t
>(
::random());
402 (*this) =
static_cast<E
>(val);
407 std::stringstream ss;
413 std::stringstream ss; ss.str(data);
417 void read(std::istream &stream) {
423 unsigned char buffer[10];
424 unsigned char *bp = &buffer[0];
425 uint64_t val = _value;
434 unsigned char high_bit = 0;
437 *bp = (
unsigned char)(high_bit | (val & 0x7f));
445 stream.write((
const char*)&buffer[0], val_len);
451 unsigned char bp = 0;
452 unsigned char start = 0;
458 stream.get((
char&)bp);
460 _value = (_value << 7) | (bp & 0x7f);
463 if ((bp & (1 << 7)) == 0)
467 if ((val_len % 8) == 0) ++carry;
469 if ((
sizeof(E) + carry) < val_len)
472 if (start == 0) start = bp;
481 std::ostream &operator<<(std::ostream &stream, const dtn::data::SDNV<E> &obj)