root/juggler/tags/1.0.5/Sound/vjSoundFactory.cpp

Revision 7539, 3.2 kB (checked in by anonymous, 7 years ago)

This commit was manufactured by cvs2svn to create tag
'RELENG_1_0_5_RELEASE'.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
2  *
3  * VR Juggler is (C) Copyright 1998, 1999, 2000 by Iowa State University
4  *
5  * Original Authors:
6  *   Allen Bierbaum, Christopher Just,
7  *   Patrick Hartling, Kevin Meinert,
8  *   Carolina Cruz-Neira, Albert Baker
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the
22  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23  * Boston, MA 02111-1307, USA.
24  *
25  * -----------------------------------------------------------------
26  * File:          $RCSfile$
27  * Date modified: $Date$
28  * Version:       $Revision$
29  * -----------------------------------------------------------------
30  *
31  *************** <auto-copyright.pl END do not edit this line> ***************/
32
33 #include <Sound/vjSoundFactory.h>
34 #include <Sound/vjSoundEngineConstructor.h>
35
36
37 //std::vector< vjSoundEngineConstructorBase* > vjSoundFactory::mConstructors;
38 //vjSoundFactory* vjSoundFactory::_instance = NULL;   //: The singleton instance ptr
39 vjSingletonImp(vjSoundFactory);
40
41 vjSoundFactory::vjSoundFactory()
42 {
43 }
44
45 // register a creator to the factory.
46 // this is intended to be used by each api's registration method
47
48 void vjSoundFactory::registerConstructor( vjSoundEngineConstructorBase* constructor )
49 {
50    vjASSERT(constructor != NULL);
51    mConstructors.push_back(constructor);     // Add the constructor to the list
52    std::cout << "vjSoundFactory::registerConstructor: Sound engine registered for: "
53              << constructor->getChunkType().c_str()
54              << "   :" << (void*)constructor
55              << " type:" << typeid(*constructor).name() << std::endl;
56 }
57
58 bool vjSoundFactory::recognizeEngine(vjConfigChunk* chunk)
59 {
60         if(vjSoundFactory::findConstructor(chunk) == -1)
61       return false;
62    else
63       return true;
64 }
65
66
67 vjSoundEngine* vjSoundFactory::loadEngine(vjConfigChunk* chunk)
68 {
69         vjASSERT(recognizeEngine(chunk));
70
71    int index = findConstructor(chunk);
72
73    vjSoundEngine* new_engine;
74    vjSoundEngineConstructorBase* constructor = mConstructors[index];
75
76    vjDEBUG(vjDBG_INPUT_MGR,3) << "vjSoundFactory::loadEngine: Loading device: "
77               << chunk->getType() << "  with: "
78               << typeid(*constructor).name() << std::endl << vjDEBUG_FLUSH;
79
80    new_engine = constructor->createEngine(chunk);
81    return new_engine;
82 }
83
84 int vjSoundFactory::findConstructor(vjConfigChunk* chunk)
85 {
86    std::string chunk_type;
87    chunk_type = (std::string)chunk->getType();
88    
89    for (unsigned int i = 0; i < mConstructors.size(); i++)
90    {
91       // Get next constructor
92       vjSoundEngineConstructorBase* construct = mConstructors[i];
93       vjASSERT(construct != NULL);
94
95       if(construct->getChunkType() == chunk_type)
96          return i;
97    }
98
99    return -1;
100 }
Note: See TracBrowser for help on using the browser.