lazy.h
1//-*-C++-*-
2/***************************************************************************
3 *
4 * Copyright (C) 2009 by Willem van Straten
5 * Licensed under the Academic Free License version 2.1
6 *
7 ***************************************************************************/
8
9// psrchive/Util/units/lazy.h
10
11#ifndef __lazy_h
12#define __lazy_h
13
14#include "debug.h"
15
17
25
26
27/*
28 LAZY_GLOBAL implements a static pointer and (static) class method
29 that provides access to it.
30
31 Two symbols are created:
32
33 static type* the_name
34 type& class::get_name ()
35
36 and, when constructed:
37
38 the_name = new type (value)
39*/
40
41#define LAZY_GLOBAL(class,type,name,value) \
42 static type* the_##name = 0; \
43 type& class :: get_##name () \
44 { \
45 if (! the_##name) \
46 the_##name = new type ( value ); \
47 DEBUG( #class "::get_" #name " ptr=" << the_##name); \
48 return *the_##name; \
49 }
50
51/*
52 LAZY_STATIC implements a static pointer and static function
53 that provides access to it.
54
55 Two symbols are created:
56
57 static type* the_name
58 type& get_name ()
59
60 and, when constructed:
61
62 the_name = new type (value)
63*/
64
65#define LAZY_STATIC(type,name,value) \
66 static type* the_##name = 0; \
67 static type& get_##name () \
68 { \
69 if (! the_##name) \
70 the_##name = new type ( value ); \
71 DEBUG( "get_" #name " ptr=" << the_##name); \
72 return *the_##name; \
73 }
74
75#endif
76

Generated using doxygen 1.14.0