tizen beta release
[framework/web/wrt-plugins-common.git] / src / Commons / StaticAssert.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * @file        StaticAssert.h
18  * @author      Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
19  * @author      Grzegorz Krawczyk (g.krawczyk@samsung.com)
20  * @version     0.1
21  */
22
23 #ifndef WRTDEVICEAPIS_COMMONS_STATIC_ASSERT_H
24 #define WRTDEVICEAPIS_COMMONS_STATIC_ASSERT_H
25
26 namespace WrtDeviceApis {
27 namespace Commons {
28
29 template<bool>
30 struct CompileTimeChecker
31 {
32     CompileTimeChecker(...);
33 };
34
35 template<>
36 struct CompileTimeChecker<false> {};
37
38 #define STATIC_CHECK(expr, msg) \
39     { \
40         class ERROR_ ## msg {}; \
41         CompileTimeChecker<(expr)!= 0>((ERROR_ ## msg())); \
42     }
43
44 /**
45  * Define used to inform about errors in compilation time
46  * useful in templates
47  * @param msg - message to be displayed,
48  * msg have to be a valid C++ identifier,
49  * other way reported errors will be meaningless
50  * @param C - instance of object which caused problem
51  * error generated by compiler display type of C
52  * */
53 #define STATIC_ERROR(msg, C) \
54     { \
55         C->_ ## msg(); \
56     }
57
58 }
59 } // WrtDeviceApisCommon
60
61 #endif // WRTDEVICEAPIS_COMMONS_STATIC_ASSERT_H