]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MIUtilSingletonHelper.h
Merge OpenSSL 1.0.1k.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / tools / lldb-mi / MIUtilSingletonHelper.h
1 //===-- MIUtilSingletonHelper.h ---------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 //++
11 // File:                MIUtilSingletonHelper.h
12 //
13 // Overview:    Contains template functions to aid the initialisation and
14 //                              shutdown of MI modules. MI modules (or components) can 
15 //                              use other MI modules to help them achieve their one task
16 //                              (Modules only do one task).
17 //
18 // Environment: Compilers:      Visual C++ 12.
19 //                                                      gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
20 //                              Libraries:      See MIReadmetxt. 
21 //
22 // Copyright:   None.
23 //--
24
25 #pragma once
26
27 namespace MI
28 {
29
30 // In house headers:
31 #include "MIUtilString.h"
32 #include "MICmnResources.h"
33
34 //++ ============================================================================
35 // Details:     Short cut helper function to simplify repeated initialisation of
36 //                      MI components (singletons) required by a client module.
37 // Type:        Template method.
38 // Args:        vErrorResrcId   - (R)  The string resource ID error message identifier to place in errMsg.
39 //                      vwrbOk                  - (RW) On input True = Try to initalise MI driver module.
40 //                                                                 On output True = MI driver module initialise successfully.
41 //                      vwrErrMsg               - (W)  MI driver module initialise error description on failure.
42 // Return:      MIstatus::success - Functional succeeded.
43 //                      MIstatus::failure - Functional failed.
44 // Authors:     Aidan Dodds 17/03/2014.
45 // Changes:     None.
46 //--
47 template< typename T >
48 bool ModuleInit( const MIint vErrorResrcId, bool & vwrbOk, CMIUtilString & vwrErrMsg )
49 {
50         if( vwrbOk && !T::Instance().Initialize() )
51         {
52                 vwrbOk = MIstatus::failure;
53                 vwrErrMsg = CMIUtilString::Format( MIRSRC( vErrorResrcId ), T::Instance().GetErrorDescription().c_str() );
54         }
55
56         return vwrbOk;
57 }
58
59 //++ ============================================================================
60 // Details:     Short cut helper function to simplify repeated shutodown of
61 //                      MI components (singletons) required by a client module.
62 // Type:        Template method.
63 // Args:        vErrorResrcId   - (R)  The string resource ID error message identifier 
64 //                                                                 to place in errMsg.
65 //                      vwrbOk                  - (W)  If not already false make false on module 
66 //                                                                 shutdown failure.
67 //                      vwrErrMsg               - (RW) Append to existing error description string MI 
68 //                                                                 driver module initialise error description on 
69 //                                                                 failure.
70 // Return:      True - Module shutdown succeeded.
71 //                      False - Module shutdown failed.
72 // Authors:     Aidan Dodds 17/03/2014.
73 // Changes:     None.
74 //--
75 template< typename T >
76 bool ModuleShutdown( const MIint vErrorResrcId, bool & vwrbOk, CMIUtilString & vwrErrMsg )
77 {
78         bool bOk = MIstatus::success;
79
80         if( !T::Instance().Shutdown() )
81         {
82                 const bool bMoreThanOneError( !vwrErrMsg.empty() );
83                 bOk = MIstatus::failure;
84                 if( bMoreThanOneError )
85                         vwrErrMsg += ", ";
86                 vwrErrMsg += CMIUtilString::Format( MIRSRC( vErrorResrcId ), T::Instance().GetErrorDescription().c_str() );
87         }
88         
89         vwrbOk = bOk ? vwrbOk : MIstatus::failure;
90
91         return bOk;
92 }
93
94 } // namespace MI
95