packages/Utils/rng/RNG.cc
//---------------------------------------------------------------------------//
// CONSTRUCTORS
//---------------------------------------------------------------------------//
/*!
 * \brief Unpacking constructor.
 */
CONSTRUCTORS
\brief Unpacking constructor.
CONSTRUCTORS \ brief Unpacking constructor .
RNG::RNG(const std::vector<char> &packed)
    : d_streamid(0)
    , d_stream(0)
{
    REQUIRE(packed.size() >= 2 * sizeof(int));
    profugus::Unpacker u;
    u.set_buffer(packed.size(), &packed[0]);
    int rng_size = 0;
    u >> d_stream >> rng_size;
    CHECK(d_stream >= 0);
    CHECK(rng_size >= 0);
    char *prng = new char[rng_size];
    for (int i = 0; i < rng_size; i++)
        u >> prng[i];
    int *rnid = unpack_sprng(prng);
    d_streamid = new RNGValue(rnid);
    delete [] prng;
    ENSURE(u.get_ptr() == &packed[0] + packed.size());
    ENSURE(d_streamid);
}
RNG :: RNG ( const std :: vector < char > & packed ) : d_streamid ( 0 ) , d_stream ( 0 ) { REQUIRE ( packed . size ( ) >= 2 * sizeof ( int ) ) ; profugus :: Unpacker u ; u . set_buffer ( packed . size ( ) , & packed [ 0 ] ) ; int rng_size = 0 ; u >> d_stream >> rng_size ; CHECK ( d_stream >= 0 ) ; CHECK ( rng_size >= 0 ) ; char * prng = new char [ rng_size ] ; for ( int i = 0 ; i < rng_size ; i ++ ) u >> prng [ i ] ; int * rnid = unpack_sprng ( prng ) ; d_streamid = new RNGValue ( rnid ) ; delete [ ] prng ; ENSURE ( u . get_ptr ( ) == & packed [ 0 ] + packed . size ( ) ) ; ENSURE ( d_streamid ) ; }
CONSTRUCTORS
 \brief Unpacking constructor.
CONSTRUCTORS \ brief Unpacking constructor .
// make an unpacker // set the buffer // unpack the stream num and size of state // unpack the random stream state // now rebuild the sprng object // now make a new streamid // reclaim memory