GPU-SD  1.0.2
gpuInfo.h
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 #ifndef GPUSD_GPUINFO_H
00019 #define GPUSD_GPUINFO_H
00020 
00021 #include <climits>
00022 #include <cstring>
00023 #include <iostream>
00024 #include <string>
00025 
00026 namespace gpusd
00027 {
00029     struct GPUInfo
00030     {
00032         static const unsigned defaultValue = UINT_MAX;
00033 
00035         GPUInfo()
00036                 : type( 0 ), port( defaultValue ), device( defaultValue )
00037                 , session( "local" )
00038             { invalidatePVP(); }
00039 
00049         GPUInfo( const std::string& name )
00050                 : type( 0 ), port( defaultValue ), device( defaultValue )
00051                 , session( "local" )
00052             {
00053                 invalidatePVP();
00054                 strncpy( reinterpret_cast< char* >( &type ), name.c_str(), 4 );
00055             }
00056 
00058         void invalidatePVP()
00059             {
00060                 pvp[0] = 0;
00061                 pvp[1] = 0;
00062                 pvp[2] = -1;
00063                 pvp[3] = -1;
00064             }
00065 
00067         bool operator == ( const GPUInfo& rhs ) const 
00068             { 
00069                 return ( type == rhs.type && hostname == rhs.hostname &&
00070                          session == rhs.session && port == rhs.port &&
00071                          device == rhs.device &&
00072                          pvp[0] == rhs.pvp[0] && pvp[1] == rhs.pvp[1] &&
00073                          pvp[2] == rhs.pvp[2] && pvp[3] == rhs.pvp[3] );
00074             }
00075 
00077         bool operator != ( const GPUInfo& rhs ) const 
00078             { 
00079                 return ( type != rhs.type || hostname != rhs.hostname ||
00080                          session != rhs.session || port != rhs.port ||
00081                          device != rhs.device || 
00082                          pvp[0] != rhs.pvp[0] || pvp[1] != rhs.pvp[1] ||
00083                          pvp[2] != rhs.pvp[2] || pvp[3] != rhs.pvp[3] );
00084             }
00085 
00087         std::string getName() const
00088             { return std::string( reinterpret_cast<const char*>( &type ), 4 ); }
00089 
00091         unsigned type;
00092 
00094         unsigned port;
00095 
00100         unsigned device;
00101 
00103         int pvp[4];
00104 
00105         std::string hostname; 
00106         std::string session; 
00107 
00108         char dummy[32]; 
00109     };
00110 
00111     inline std::ostream& operator << ( std::ostream& os, const GPUInfo& info )
00112     {
00113         if( !info.getName().empty( ))
00114             os << "type     " << info.getName() << std::endl;
00115         if( !info.hostname.empty( ))
00116             os << "hostname " << info.hostname << std::endl;
00117         if( !info.session.empty() && info.session != "local" )
00118             os << "session  " << info.session << std::endl;
00119         if( info.port != GPUInfo::defaultValue )
00120             os << "port     " << info.port << std::endl;
00121         if( info.device != GPUInfo::defaultValue )
00122             os << "device   " << info.device << std::endl;
00123         if( info.pvp[2] >0 && info.pvp[3] > 0 )
00124             os << "viewport [" << info.pvp[0] << ' ' << info.pvp[1] << ' '
00125                << info.pvp[2] << ' ' << info.pvp[3] << ']' << std::endl;
00126         return os;
00127     }
00128 }
00129 #endif // GPUSD_GPUINFO_H
00130 
Generated on Tue Dec 13 2011 17:52:00 for GPU-SD 1.0.2 by  doxygen 1.7.5.1