1 //===-- MIUtilSingletonHelper.h ---------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
19 #include "MIUtilString.h"
20 #include "MICmnResources.h"
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.
37 ModuleInit(const MIint vErrorResrcId, bool &vwrbOk, CMIUtilString &vwrErrMsg)
39 if (vwrbOk && !T::Instance().Initialize())
41 vwrbOk = MIstatus::failure;
42 vwrErrMsg = CMIUtilString::Format(MIRSRC(vErrorResrcId), T::Instance().GetErrorDescription().c_str());
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
56 // vwrErrMsg - (RW) Append to existing error description string MI
57 // driver module initialise error description on
59 // Return: True - Module shutdown succeeded.
60 // False - Module shutdown failed.
61 // Authors: Aidan Dodds 17/03/2014.
66 ModuleShutdown(const MIint vErrorResrcId, bool &vwrbOk, CMIUtilString &vwrErrMsg)
68 bool bOk = MIstatus::success;
70 if (!T::Instance().Shutdown())
72 const bool bMoreThanOneError(!vwrErrMsg.empty());
73 bOk = MIstatus::failure;
74 if (bMoreThanOneError)
76 vwrErrMsg += CMIUtilString::Format(MIRSRC(vErrorResrcId), T::Instance().GetErrorDescription().c_str());
79 vwrbOk = bOk ? vwrbOk : MIstatus::failure;