2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 | Copyright (c) 1997-2010 The PHP Group |
7 +----------------------------------------------------------------------+
8 | This source file is subject to version 3.01 of the PHP license, |
9 | that is bundled with this package in the file LICENSE, and is |
10 | available through the world-wide-web at the following url: |
11 | http://www.php.net/license/3_01.txt |
12 | If you did not receive a copy of the PHP license and are unable to |
13 | obtain it through the world-wide-web, please send a note to |
14 | license@php.net so we can mail you a copy immediately. |
15 +----------------------------------------------------------------------+
18 #ifndef incl_HPHP_CLASSNAME_IS_H
19 #define incl_HPHP_CLASSNAME_IS_H
24 * InstantStatic allows defining a static in-class variable that is
25 * initialized during program startup, without actually needing to define
26 * it anywhere. When defining the static, just specify its type (T), the
27 * type that T's constructor will receive (TInit), and the name of the
28 * function that will be called for construction (init). One copy of
29 * static data is generated per T/init.
31 template <typename T
, typename TInit
, TInit
init()>
32 struct InstantStatic
{
36 template <typename T
, typename TInit
, TInit
init()>
37 T InstantStatic
<T
, TInit
, init
>::value(init());
39 #define CLASSNAME_IS(str) \
40 static const auto& GetClassName() { return str; } \
41 static const StaticString& classnameof() { \
42 return InstantStatic<const StaticString, \
43 decltype(GetClassName()), \
44 GetClassName>::value; \
47 #define RESOURCENAME_IS(str) \
48 static const auto& GetResourceName() { return str; } \
49 static const StaticString& resourcenameof() { \
50 return InstantStatic<const StaticString, \
51 decltype(GetResourceName()), \
52 GetResourceName>::value; \