1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     util_InitializationTransaction.h
4 
5   Copyright (C)2009-2012 Nintendo Co., Ltd.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Rev: 46347 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NN_UTIL_DETAIL_UTIL_INITIALIZATIONTRANSACTION_H_
17 #define NN_UTIL_DETAIL_UTIL_INITIALIZATIONTRANSACTION_H_
18 
19 #define NN_UTIL_DETAIL_INITIALIZATIONTRANSACTION_H_STRING_JOIN_(X, Y) NN_UTIL_DETAIL_INITIALIZATIONTRANSACTION_H_STRING_JOIN1_(X, Y)
20 #define NN_UTIL_DETAIL_INITIALIZATIONTRANSACTION_H_STRING_JOIN1_(X, Y) X##Y
21 
22 #define NN_UTIL_DETAIL_BEGIN_INITIALIZATION_TRANSACTION(transaction) \
23 { \
24     bool transaction = false; \
25     {
26 
27 #define NN_UTIL_DETAIL_REGISTER_INITIALIZATION_TRANSACTION(transaction, T, object, f) \
28         class NN_UTIL_DETAIL_INITIALIZATIONTRANSACTION_H_STRING_JOIN_(nn_util_detail_initialtransaction_class_, __LINE__) \
29         { \
30         private: \
31             T& m_Object; \
32             bool& m_Transaction; \
33         public: \
34             NN_UTIL_DETAIL_INITIALIZATIONTRANSACTION_H_STRING_JOIN_(nn_util_detail_initialtransaction_class_, __LINE__)(bool& transaction, T& object) : m_Object(object), m_Transaction(transaction) {} \
35             ~NN_UTIL_DETAIL_INITIALIZATIONTRANSACTION_H_STRING_JOIN_(nn_util_detail_initialtransaction_class_, __LINE__)() \
36             { \
37                 if (!m_Transaction) \
38                 { \
39                     m_Object.f(); \
40                 } \
41             } \
42         } NN_UTIL_DETAIL_INITIALIZATIONTRANSACTION_H_STRING_JOIN_(nn_util_detail_initialtransaction_object_, __LINE__) (transaction, object)
43 
44 #define NN_UTIL_DETAIL_END_INITIALIZATION_TRANSACTION(transaction) \
45         transaction = true; \
46     } \
47 }
48 
49 #endif
50