monotone

monotone Mtn Source Tree

Root/src/lazy_rng.hh

1// Copyright (C) 2002 Graydon Hoare <graydon@pobox.com>
2//
3// This program is made available under the GNU GPL version 2.0 or
4// greater. See the accompanying file COPYING for details.
5//
6// This program is distributed WITHOUT ANY WARRANTY; without even the
7// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8// PURPOSE.
9
10#ifndef __LAZY_RNG_HH__
11#define __LAZY_RNG_HH__
12
13// This class instantiates a Botan::RandomNumberGenerator the first time
14// its get() method is called. Subsequent calls return the same object.
15// It is expected that callers will not hang on to the reference.
16
17#include <botan/version.h>
18
19#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,7,7)
20#include <botan/rng.h>
21
22class lazy_rng
23{
24 Botan::RandomNumberGenerator * rng;
25 lazy_rng() { rng = Botan::RandomNumberGenerator::make_rng(); }
26 ~lazy_rng() { delete rng; }
27
28public:
29
30 static Botan::RandomNumberGenerator & get()
31 {
32 static lazy_rng * instance = 0;
33 if (!instance)
34 instance = new lazy_rng();
35 return *instance->rng;
36 }
37};
38
39#endif /* botan >= 1.7.7 */
40
41#endif /* lazy_rng.hh */
42
43// Local Variables:
44// mode: C++
45// fill-column: 76
46// c-file-style: "gnu"
47// indent-tabs-mode: nil
48// End:
49// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status