root/juggler/tags/1.0.7/Sound/vjSoundEngineConstructor.h
| Revision 8789, 3.1 kB (checked in by patrickh, 7 years ago) | |
|---|---|
| |
| Line | |
|---|---|
| 1 | /*************** <auto-copyright.pl BEGIN do not edit this line> ************** |
| 2 | * |
| 3 | * VR Juggler is (C) Copyright 1998, 1999, 2000, 2001, 2002 |
| 4 | * by Iowa State University |
| 5 | * |
| 6 | * Original Authors: |
| 7 | * Allen Bierbaum, Christopher Just, |
| 8 | * Patrick Hartling, Kevin Meinert, |
| 9 | * Carolina Cruz-Neira, Albert Baker |
| 10 | * |
| 11 | * This library is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU Library General Public |
| 13 | * License as published by the Free Software Foundation; either |
| 14 | * version 2 of the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This library is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | * Library General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU Library General Public |
| 22 | * License along with this library; if not, write to the |
| 23 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 24 | * Boston, MA 02111-1307, USA. |
| 25 | * |
| 26 | * ----------------------------------------------------------------- |
| 27 | * File: $RCSfile$ |
| 28 | * Date modified: $Date$ |
| 29 | * Version: $Revision$ |
| 30 | * ----------------------------------------------------------------- |
| 31 | * |
| 32 | *************** <auto-copyright.pl END do not edit this line> ***************/ |
| 33 | |
| 34 | #ifndef _VJ_SOUND_ENGINE_CONSTRUCTOR_H_ |
| 35 | #define _VJ_SOUND_ENGINE_CONSTRUCTOR_H_ |
| 36 | |
| 37 | #include <Sound/vjSoundEngine.h> |
| 38 | #include <string> |
| 39 | #include <Config/vjConfigChunk.h> |
| 40 | #include <Kernel/vjDebug.h> |
| 41 | #include <Sound/vjSoundFactory.h> |
| 42 | |
| 43 | |
| 44 | // Apparently this is needed here so that this will compile with GCC. |
| 45 | class vjSoundFactory; |
| 46 | |
| 47 | //: Base class for virtual construction of sound engines |
| 48 | // Implementations of this class are registered with the device factory |
| 49 | // for each device in the system |
| 50 | //!PUBLIC_API: |
| 51 | class vjSoundEngineConstructorBase |
| 52 | { |
| 53 | public: |
| 54 | //: Constructor |
| 55 | //! POST: Device is registered |
| 56 | vjSoundEngineConstructorBase() {;} |
| 57 | |
| 58 | //: Create the device |
| 59 | virtual vjSoundEngine* createEngine(vjConfigChunk* chunk) |
| 60 | { |
| 61 | vjDEBUG(vjDBG_ALL,0) << "ERROR: vjSoundEngineConstructorBase::createEngine: Should never be called" << vjDEBUG_FLUSH; |
| 62 | return NULL; |
| 63 | } |
| 64 | |
| 65 | //: Get the string desc of the type of chunk we can create |
| 66 | virtual std::string getChunkType() |
| 67 | { |
| 68 | return std::string("BaseConstructor: Invalid type"); |
| 69 | } |
| 70 | }; |
| 71 | |
| 72 | |
| 73 | template <class ENGINE> |
| 74 | class vjSoundEngineConstructor : public vjSoundEngineConstructorBase |
| 75 | { |
| 76 | public: |
| 77 | vjSoundEngineConstructor(); |
| 78 | |
| 79 | virtual vjSoundEngine* createEngine(vjConfigChunk* chunk) |
| 80 | { |
| 81 | ENGINE* new_engine = new ENGINE; |
| 82 | bool success = new_engine->config(chunk); |
| 83 | if(success) |
| 84 | { |
| 85 | return new_engine; |
| 86 | } else { |
| 87 | delete new_engine; |
| 88 | return NULL; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | virtual std::string getChunkType() |
| 93 | { return ENGINE::getChunkType(); } |
| 94 | }; |
| 95 | |
| 96 | |
| 97 | // self registrator with the soundfactory. |
| 98 | template <class ENGINE> |
| 99 | vjSoundEngineConstructor<ENGINE>::vjSoundEngineConstructor() |
| 100 | { |
| 101 | vjASSERT(vjSoundFactory::instance() != NULL); |
| 102 | vjSoundFactory::instance()->registerConstructor( this ); |
| 103 | } |
| 104 | |
| 105 | #endif |
Note: See TracBrowser for help on using the browser.
