00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- 00002 * vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=c:cindent:textwidth=0: 00003 * 00004 * Copyright (C) 2005 Dell Inc. 00005 * by Michael Brown <Michael_E_Brown@dell.com> 00006 * Licensed under the Open Software License version 2.1 00007 * 00008 * Alternatively, you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published 00010 * by the Free Software Foundation; either version 2 of the License, 00011 * or (at your option) any later version. 00012 00013 * This program is distributed in the hope that it will be useful, but 00014 * WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00016 * See the GNU General Public License for more details. 00017 */ 00018 00019 #define LIBSMBIOS_SOURCE 00020 #include "TokenImpl.h" 00021 #include "FactoryImpl2.h" 00022 00023 using namespace std; 00024 00025 namespace smbios 00026 { 00027 class TokenTableFactoryImpl : public factory::TFactory<TokenTableFactory> 00028 { 00029 public: 00030 TokenTableFactoryImpl() {}; 00031 virtual ~TokenTableFactoryImpl() throw(); 00032 virtual ITokenTable *getSingleton( const smbios::ISmbiosTable *table = 0 ); 00033 virtual ITokenTable *makeNew( const smbios::ISmbiosTable *table ); 00034 protected: 00035 static ITokenTable *_tablePtr; 00036 }; 00037 00038 TokenTableFactory::TokenTableFactory() 00039 {} 00040 00041 TokenTableFactory::~TokenTableFactory() throw() 00042 {} 00043 00044 00045 TokenTableFactory *TokenTableFactory::getFactory() 00046 { 00047 // reinterpret_cast<...>(0) to ensure template parameter is correct 00048 // this is a workaround for VC6 which cannot use explicit member template 00049 // function initialization. 00050 return TokenTableFactoryImpl::getFactory(reinterpret_cast<TokenTableFactoryImpl *>(0)); 00051 } 00052 00053 ITokenTable *TokenTableFactoryImpl::_tablePtr = 0; 00054 00055 TokenTableFactoryImpl::~TokenTableFactoryImpl() throw() 00056 { 00057 if( _tablePtr ) 00058 { 00059 delete _tablePtr; 00060 } 00061 _tablePtr = 0; 00062 } 00063 00064 ITokenTable *TokenTableFactoryImpl::getSingleton(const ISmbiosTable *table) 00065 { 00066 if( !table ) 00067 { 00068 table = smbios::SmbiosFactory::getFactory()->getSingleton(); 00069 } 00070 00071 if (! _tablePtr) 00072 _tablePtr = makeNew(table); 00073 00074 return _tablePtr; 00075 } 00076 00077 00078 ITokenTable *TokenTableFactoryImpl::makeNew(const ISmbiosTable *table) 00079 { 00080 if ((mode == AutoDetectMode) || (mode == UnitTestMode)) 00081 { 00082 return new TokenTable( *table ); 00083 } 00084 else 00085 { 00086 throw InvalidTokenTableModeImpl(); 00087 } 00088 } 00089 00090 }