packages/Utils/rng/RNG.cc
//---------------------------------------------------------------------------//
/*!
 * \brief Pack a RNG object into a vector<char>.
 */
\brief Pack a RNG object into a vector.
\ brief Pack a RNG object into a vector .
std::vector<char> RNG::pack() const
{
    REQUIRE(d_streamid);
    profugus::Packer p;
    char *prng   = 0;
    int rng_size = pack_sprng(d_streamid->id, &prng);
    int size     = rng_size + 2 * sizeof(int);
    CHECK(prng);
    std::vector<char> packed(size);
    p.set_buffer(size, &packed[0]);
    p << d_stream << rng_size;
    for (int i = 0; i < rng_size; i++)
        p << prng[i];
    std::free(prng);
    ENSURE(p.get_ptr() == &packed[0] + size);
    return packed;
}
std :: vector < char > RNG :: pack ( ) const { REQUIRE ( d_streamid ) ; profugus :: Packer p ; char * prng = 0 ; int rng_size = pack_sprng ( d_streamid -> id , & prng ) ; int size = rng_size + 2 * sizeof ( int ) ; CHECK ( prng ) ; std :: vector < char > packed ( size ) ; p . set_buffer ( size , & packed [ 0 ] ) ; p << d_stream << rng_size ; for ( int i = 0 ; i < rng_size ; i ++ ) p << prng [ i ] ; std :: free ( prng ) ; ENSURE ( p . get_ptr ( ) == & packed [ 0 ] + size ) ; return packed ; }
\brief Pack a RNG object into a vector<char>.
\ brief Pack a RNG object into a vector<char > .
// make a packer // first pack the random number object and determine the size // now set the buffer // pack the stream number and rng size // pack the stream state // free the prng buffer