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