GPU-SD  1.1.2
module.cpp
00001 
00002 /* Copyright (c) 2011, Stefan Eilemann <eile@eyescale.ch> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #include <gpusd/module.h>
00019 #include <gpusd/gpuInfo.h>
00020 
00021 namespace gpusd
00022 {
00023 namespace
00024 {
00025 Module* stack_ = 0;
00026 }
00027 namespace detail
00028 {
00029 class Module
00030 {
00031 public:
00032     Module() : next_( 0 ) {}
00033     ~Module() {};
00034 
00035     gpusd::Module* next_;
00036 };
00037 }
00038 
00039 Module::Module()
00040         : impl_( new detail::Module( ))
00041 {
00042     if( !stack_ )
00043     {
00044         stack_ = this;
00045         return;
00046     }
00047 
00048     for( Module* module = stack_; module; module = module->impl_->next_ )
00049     {
00050         if( !module->impl_->next_ )
00051         {
00052             module->impl_->next_ = this;
00053             return;
00054         }
00055     }
00056 }
00057 
00058 Module::~Module()
00059 {
00060     Module* previous = stack_;
00061     for( Module* module = stack_; module; module = module->impl_->next_ )
00062     {
00063         if( module == this )
00064         {
00065             if( previous )
00066                 previous->impl_->next_ = impl_->next_;
00067             else
00068                 stack_ = impl_->next_;
00069             return;
00070         }
00071         previous = module;
00072     }
00073     delete impl_;
00074 }
00075 
00076 GPUInfos Module::discoverGPUs( FilterPtr filter )
00077 {
00078     GPUInfos result;
00079     for( Module* module = stack_; module; module = module->impl_->next_ )
00080     {
00081         const GPUInfos infos = module->discoverGPUs_(); 
00082         for( GPUInfosCIter i = infos.begin(); i != infos.end(); ++i )
00083         {
00084             const GPUInfo& info = *i;
00085             if( !filter || (*filter)( result, info ))
00086                 result.push_back( info );
00087         }
00088     }
00089     return result;
00090 }
00091 
00092 }
Generated on Thu Jun 14 2012 07:53:07 for GPU-SD 1.1.2 by  doxygen 1.8.0