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