]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/tools/lldb-mi/MIUtilSingletonHelper.h
Update LLDB snapshot to upstream r241361
[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 // Copyright:   None.
11 //--
12
13 #pragma once
14
15 namespace MI
16 {
17
18 // In house headers:
19 #include "MIUtilString.h"
20 #include "MICmnResources.h"
21
22 //++ ============================================================================
23 // Details: Short cut helper function to simplify repeated initialisation of
24 //          MI components (singletons) required by a client module.
25 // Type:    Template method.
26 // Args:    vErrorResrcId   - (R)  The string resource ID error message identifier to place in errMsg.
27 //          vwrbOk          - (RW) On input True = Try to initalise MI driver module.
28 //                                 On output True = MI driver module initialise successfully.
29 //          vwrErrMsg       - (W)  MI driver module initialise error description on failure.
30 // Return:  MIstatus::success - Functional succeeded.
31 //          MIstatus::failure - Functional failed.
32 // Authors: Aidan Dodds 17/03/2014.
33 // Changes: None.
34 //--
35 template <typename T>
36 bool
37 ModuleInit(const MIint vErrorResrcId, bool &vwrbOk, CMIUtilString &vwrErrMsg)
38 {
39     if (vwrbOk && !T::Instance().Initialize())
40     {
41         vwrbOk = MIstatus::failure;
42         vwrErrMsg = CMIUtilString::Format(MIRSRC(vErrorResrcId), T::Instance().GetErrorDescription().c_str());
43     }
44
45     return vwrbOk;
46 }
47
48 //++ ============================================================================
49 // Details: Short cut helper function to simplify repeated shutodown of
50 //          MI components (singletons) required by a client module.
51 // Type:    Template method.
52 // Args:    vErrorResrcId   - (R)  The string resource ID error message identifier
53 //                                 to place in errMsg.
54 //          vwrbOk          - (W)  If not already false make false on module
55 //                                 shutdown failure.
56 //          vwrErrMsg       - (RW) Append to existing error description string MI
57 //                                 driver module initialise error description on
58 //                                 failure.
59 // Return:  True - Module shutdown succeeded.
60 //          False - Module shutdown failed.
61 // Authors: Aidan Dodds 17/03/2014.
62 // Changes: None.
63 //--
64 template <typename T>
65 bool
66 ModuleShutdown(const MIint vErrorResrcId, bool &vwrbOk, CMIUtilString &vwrErrMsg)
67 {
68     bool bOk = MIstatus::success;
69
70     if (!T::Instance().Shutdown())
71     {
72         const bool bMoreThanOneError(!vwrErrMsg.empty());
73         bOk = MIstatus::failure;
74         if (bMoreThanOneError)
75             vwrErrMsg += ", ";
76         vwrErrMsg += CMIUtilString::Format(MIRSRC(vErrorResrcId), T::Instance().GetErrorDescription().c_str());
77     }
78
79     vwrbOk = bOk ? vwrbOk : MIstatus::failure;
80
81     return bOk;
82 }
83
84 } // namespace MI