26#ifndef DCCLConstants20091211H
27#define DCCLConstants20091211H
35#include <google/protobuf/descriptor.h>
36#include <google/protobuf/message.h>
42inline unsigned floor_bits2bytes(
unsigned bits) {
return bits >> 3; }
45inline unsigned ceil_bits2bytes(
unsigned bits)
51 return (bits & BYTE_MASK) ? floor_bits2bytes(bits) + 1 : floor_bits2bytes(bits);
56typedef google::protobuf::uint32
uint32;
58using int32 = google::protobuf::int32;
60using uint64 = google::protobuf::uint64;
62using int64 = google::protobuf::int64;
64const unsigned BITS_IN_BYTE = 8;
66inline std::ostream& operator<<(std::ostream& out,
const google::protobuf::Message& msg)
68 return (out <<
"[[" << msg.GetDescriptor()->name() <<
"]] " << msg.DebugString());
71template <
typename Float> Float round(Float d) {
return std::floor(d + 0.5); }
77template <
typename Float>
78typename std::enable_if<std::is_floating_point<Float>::value, Float>::type round(Float value,
81 Float scaling = std::pow(10.0, precision);
82 return round(value * scaling) / scaling;
89template <
typename Float>
90typename std::enable_if<std::is_floating_point<Float>::value, Float>::type
quantize(Float value,
94 return round(value / interval) * interval;
97 double interval_inv = 1.0 / interval;
98 return round(value * interval_inv) / interval_inv;
103template <
typename Int> Int abs(Int i) {
return (i < 0) ? -i : i; }
109template <
typename Int>
110typename std::enable_if<std::is_integral<Int>::value, Int>::type round(Int value,
int precision)
119 Int scaling = (Int)std::pow(10.0, -precision);
120 Int remainder = value % scaling;
123 if (remainder >= scaling / 2)
134template <
typename Int>
135typename std::enable_if<std::is_integral<Int>::value, Int>::type
quantize(Int value,
138 if ((interval -
static_cast<uint64_t
>(interval)) >= std::numeric_limits<double>::epsilon())
144 Int remainder = value %
static_cast<Int
>(interval);
146 if (remainder >= interval / 2)
152template <
class T>
inline void hash_combine(std::size_t& seed,
const T& v)
155 seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
Dynamic Compact Control Language namespace.
google::protobuf::uint64 uint64
an unsigned 64 bit integer
google::protobuf::int32 int32
a signed 32 bit integer
google::protobuf::int64 int64
a signed 64 bit integer
std::enable_if< std::is_floating_point< Float >::value, Float >::type quantize(Float value, double interval)
google::protobuf::uint32 uint32
an unsigned 32 bit integer
void hash_combine(std::size_t &seed, const T &v)
hash combine - from boost::hash_combine