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 //===----------------------------------------------------------------------===//
11 // File: MIUtilSingletonHelper.h
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).
18 // Environment: Compilers: Visual C++ 12.
19 // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
20 // Libraries: See MIReadmetxt.
31 #include "MIUtilString.h"
32 #include "MICmnResources.h"
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.
47 template< typename T >
48 bool ModuleInit( const MIint vErrorResrcId, bool & vwrbOk, CMIUtilString & vwrErrMsg )
50 if( vwrbOk && !T::Instance().Initialize() )
52 vwrbOk = MIstatus::failure;
53 vwrErrMsg = CMIUtilString::Format( MIRSRC( vErrorResrcId ), T::Instance().GetErrorDescription().c_str() );
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
67 // vwrErrMsg - (RW) Append to existing error description string MI
68 // driver module initialise error description on
70 // Return: True - Module shutdown succeeded.
71 // False - Module shutdown failed.
72 // Authors: Aidan Dodds 17/03/2014.
75 template< typename T >
76 bool ModuleShutdown( const MIint vErrorResrcId, bool & vwrbOk, CMIUtilString & vwrErrMsg )
78 bool bOk = MIstatus::success;
80 if( !T::Instance().Shutdown() )
82 const bool bMoreThanOneError( !vwrErrMsg.empty() );
83 bOk = MIstatus::failure;
84 if( bMoreThanOneError )
86 vwrErrMsg += CMIUtilString::Format( MIRSRC( vErrorResrcId ), T::Instance().GetErrorDescription().c_str() );
89 vwrbOk = bOk ? vwrbOk : MIstatus::failure;