1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef COMPHELPER_FLAGGUARD_HXX
25 #define COMPHELPER_FLAGGUARD_HXX
26 
27 #include "comphelper/scopeguard.hxx"
28 
29 //......................................................................................................................
30 namespace comphelper
31 {
32 //......................................................................................................................
33 
34 	//==================================================================================================================
35 	//= FlagRestorationGuard
36 	//==================================================================================================================
37     class COMPHELPER_DLLPUBLIC FlagRestorationGuard : public ScopeGuard
38     {
39     public:
FlagRestorationGuard(bool & i_flagRef,bool i_temporaryValue,exc_handling i_excHandling=IGNORE_EXCEPTIONS)40         FlagRestorationGuard( bool& i_flagRef, bool i_temporaryValue, exc_handling i_excHandling = IGNORE_EXCEPTIONS )
41             :ScopeGuard( ::boost::bind( RestoreFlag, ::boost::ref( i_flagRef ), !!i_flagRef ), i_excHandling )
42         {
43             i_flagRef = i_temporaryValue;
44         }
45 
46         ~FlagRestorationGuard();
47 
48     private:
RestoreFlag(bool & i_flagRef,bool i_originalValue)49         static void RestoreFlag( bool& i_flagRef, bool i_originalValue )
50         {
51             i_flagRef = i_originalValue;
52         }
53     };
54 
55 	//==================================================================================================================
56 	//= FlagGuard
57 	//==================================================================================================================
58     class COMPHELPER_DLLPUBLIC FlagGuard : public ScopeGuard
59     {
60     public:
FlagGuard(bool & i_flagRef,exc_handling i_excHandling=IGNORE_EXCEPTIONS)61         explicit FlagGuard( bool& i_flagRef, exc_handling i_excHandling = IGNORE_EXCEPTIONS )
62             :ScopeGuard( ::boost::bind( ResetFlag, ::boost::ref( i_flagRef ) ), i_excHandling )
63         {
64             i_flagRef = true;
65         }
66 
67         ~FlagGuard();
68 
69     private:
ResetFlag(bool & i_flagRef)70         static void ResetFlag( bool& i_flagRef )
71         {
72             i_flagRef = false;
73         }
74     };
75 
76 //......................................................................................................................
77 } // namespace comphelper
78 //......................................................................................................................
79 
80 #endif // COMPHELPER_FLAGGUARD_HXX
81