28 #include <sys/types.h>
82 SDNV(
const E value) : _value(value) {
114 return static_cast<T
>(_value);
117 const E&
get()
const {
128 return (value == _value);
133 return (value._value == _value);
138 return (value != _value);
143 return (value._value != _value);
148 E result = _value + value;
154 E result = _value + value._value;
182 _value += value._value;
201 E result = _value - value;
207 E result = _value - value._value;
235 _value -= value._value;
254 E result = _value / value;
260 E result = _value / value._value;
288 _value /= value._value;
294 E result = _value * value;
300 E result = _value * value._value;
328 _value *= value._value;
334 return (value._value & _value);
339 return (value._value | _value);
344 _value &= value._value;
350 _value |= value._value;
356 return (_value < value);
361 return (_value <= value);
366 return (_value > value);
371 return (_value >= value);
374 bool operator<(const SDNV<E> &value)
const
376 return (_value < value._value);
379 bool operator<=(const SDNV<E> &value)
const
381 return (_value <= value._value);
386 return (_value > value._value);
391 return (_value >= value._value);
396 return std::numeric_limits<E>::max();
404 (*this) =
static_cast<E
>(val);
409 std::stringstream ss;
415 std::stringstream ss; ss.str(data);
419 void read(std::istream &stream) {
425 unsigned char buffer[10];
426 unsigned char *bp = &buffer[0];
427 uint64_t val = _value;
436 unsigned char high_bit = 0;
439 *bp = (
unsigned char)(high_bit | (val & 0x7f));
447 stream.write((
const char*)&buffer[0], val_len);
453 unsigned char bp = 0;
454 unsigned char start = 0;
460 stream.get((
char&)bp);
462 _value = (_value << 7) | (bp & 0x7f);
465 if ((bp & (1 << 7)) == 0)
469 if ((val_len % 8) == 0) ++carry;
471 if ((
sizeof(E) + carry) < val_len)
474 if (start == 0) start = bp;
483 std::ostream &operator<<(std::ostream &stream, const dtn::data::SDNV<E> &obj)