SMBIOS Library
TokenTableFactory.cpp
Go to the documentation of this file.
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  * vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=c:cindent:textwidth=0:
3  *
4  * Copyright (C) 2005 Dell Inc.
5  * by Michael Brown <Michael_E_Brown@dell.com>
6  * Licensed under the Open Software License version 2.1
7  *
8  * Alternatively, you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published
10  * by the Free Software Foundation; either version 2 of the License,
11  * or (at your option) any later version.
12 
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  */
18 
19 #define LIBSMBIOS_SOURCE
20 #include "TokenImpl.h"
21 #include "FactoryImpl2.h"
22 
23 using namespace std;
24 
25 namespace smbios
26 {
27  class TokenTableFactoryImpl : public factory::TFactory<TokenTableFactory>
28  {
29  public:
31  virtual ~TokenTableFactoryImpl() throw();
32  virtual ITokenTable *getSingleton( const smbios::ISmbiosTable *table = 0 );
33  virtual ITokenTable *makeNew( const smbios::ISmbiosTable *table );
34  protected:
35  static ITokenTable *_tablePtr;
36  };
37 
39  {}
40 
41  TokenTableFactory::~TokenTableFactory() throw()
42  {}
43 
44 
45  TokenTableFactory *TokenTableFactory::getFactory()
46  {
47  // reinterpret_cast<...>(0) to ensure template parameter is correct
48  // this is a workaround for VC6 which cannot use explicit member template
49  // function initialization.
50  return TokenTableFactoryImpl::getFactory(reinterpret_cast<TokenTableFactoryImpl *>(0));
51  }
52 
53  ITokenTable *TokenTableFactoryImpl::_tablePtr = 0;
54 
55  TokenTableFactoryImpl::~TokenTableFactoryImpl() throw()
56  {
57  if( _tablePtr )
58  {
59  delete _tablePtr;
60  }
61  _tablePtr = 0;
62  }
63 
64  ITokenTable *TokenTableFactoryImpl::getSingleton(const ISmbiosTable *table)
65  {
66  if( !table )
67  {
69  }
70 
71  if (! _tablePtr)
72  _tablePtr = makeNew(table);
73 
74  return _tablePtr;
75  }
76 
77 
78  ITokenTable *TokenTableFactoryImpl::makeNew(const ISmbiosTable *table)
79  {
80  if ((mode == AutoDetectMode) || (mode == UnitTestMode))
81  {
82  return new TokenTable( *table );
83  }
84  else
85  {
86  throw InvalidTokenTableModeImpl();
87  }
88  }
89 
90 }