From 86faab1e066d08d8888b5bd606d869fceafdae17 Mon Sep 17 00:00:00 2001 From: Matthias Vallentin Date: Thu, 13 Dec 2012 18:39:29 -0800 Subject: [PATCH] C++ify RandTest.* Specifically: - Move implementation details into *.cc. - Const correctness: do not require superfluous cast. - Style: asterisk "binds" to type, not name. --- src/RandTest.cc | 20 +++++++++++++++----- src/RandTest.h | 18 ++++++------------ 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/RandTest.cc b/src/RandTest.cc index 638cc6c765..99237e114e 100644 --- a/src/RandTest.cc +++ b/src/RandTest.cc @@ -12,7 +12,17 @@ Modified for Bro by Seth Hall - July 2010 */ -#include +#include "RandTest.h" + +#define log2of10 3.32192809488736234787 +/* RT_LOG2 -- Calculate log to the base 2 */ +static double rt_log2(double x) +{ + return log2of10 * log10(x); +} + +// RT_INCIRC = pow(pow(256.0, (double) (RT_MONTEN / 2)) - 1, 2.0); +#define RT_INCIRC 281474943156225.0 RandTest::RandTest() { @@ -28,9 +38,9 @@ RandTest::RandTest() } } -void RandTest::add(void *buf, int bufl) +void RandTest::add(const void *buf, int bufl) { - unsigned char *bp = (unsigned char*)buf; + const unsigned char *bp = static_cast(buf); int oc; while (bufl-- > 0) @@ -78,8 +88,8 @@ void RandTest::add(void *buf, int bufl) } } -void RandTest::end(double *r_ent, double *r_chisq, - double *r_mean, double *r_montepicalc, double *r_scc) +void RandTest::end(double* r_ent, double* r_chisq, + double* r_mean, double* r_montepicalc, double* r_scc) { int i; double ent, chisq, scc, datasum; diff --git a/src/RandTest.h b/src/RandTest.h index a4f551b602..d787392e14 100644 --- a/src/RandTest.h +++ b/src/RandTest.h @@ -1,28 +1,22 @@ #include -#define log2of10 3.32192809488736234787 -/* RT_LOG2 -- Calculate log to the base 2 */ -static double rt_log2(double x) -{ - return log2of10 * log10(x); -} +class EntropyVal; #define RT_MONTEN 6 /* Bytes used as Monte Carlo co-ordinates. This should be no more bits than the mantissa of your "double" floating point type. */ -// RT_INCIRC = pow(pow(256.0, (double) (RT_MONTEN / 2)) - 1, 2.0); -#define RT_INCIRC 281474943156225.0 - class RandTest { public: RandTest(); - void add(void *buf, int bufl); - void end(double *r_ent, double *r_chisq, double *r_mean, - double *r_montepicalc, double *r_scc); + void add(const void* buf, int bufl); + void end(double* r_ent, double* r_chisq, double* r_mean, + double* r_montepicalc, double* r_scc); private: + friend class EntropyVal; + long ccount[256]; /* Bins to count occurrences of values */ long totalc; /* Total bytes counted */ int mp;