Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

PlugInCallback.h

Go to the documentation of this file.
00001 // Copyright NVIDIA Corporation 2002-2004
00002 // TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED
00003 // *AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS
00004 // OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
00005 // AND FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS
00006 // BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES
00007 // WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
00008 // BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS)
00009 // ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS
00010 // BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES 
00011 
00012 #pragma once
00013 
00015 #include "nvsgcommon.h"
00016 
00017 #include  "nvutil/RCObject.h"
00018 
00019 namespace nvutil
00020 {
00022 
00030   class PlugInCallback : public RCObject
00031   {
00032     public:
00034       typedef enum
00035       {
00036         PICE_UNEXPECTED_EOF,
00037         PICE_UNEXPECTED_TOKEN,
00038         PICE_UNKNOWN_TOKEN,
00039         PICE_FILE_ACCESS_FAILED,
00040         PICE_FILE_MAPPING_FAILED,
00041         PICE_INCOMPATIBLE_FILE,
00042         PICE_INVALID_FILE
00043       } PIC_ERROR;
00044 
00046       typedef enum
00047       {
00048         PICW_FILE_EMPTY,
00049         PICW_FILE_NOT_FOUND,
00050         PICW_FILES_NOT_FOUND,
00051         PICW_EMPTY_TOKEN,
00052         PICW_INCOMPATIBLE_VALUES,
00053         PICW_INVALID_VALUE,
00054         PICW_UNDEFINED_TOKEN,
00055         PICW_UNSUPPORTED_TOKEN
00056       } PIC_WARNING;
00057 
00059       typedef enum
00060       {
00061         PICT_INT,
00062         PICT_FLOAT
00063       } PIC_TYPE_ID;
00064 
00066       typedef struct
00067       {
00068         size_t  position;           
00069         std::string  context;            
00070         std::string  token;              
00071       } EmptyTokenInfo;
00072 
00074       typedef struct
00075       {
00076         size_t        position;     
00077         std::string        context;      
00078         PIC_TYPE_ID   valueType;    
00079         std::string        value0Name;   
00080         const void *  value0;       
00081         std::string        value1Name;   
00082         const void *  value1;       
00083       } IncompatibleValueInfo;
00084 
00086       typedef struct
00087       {
00088         size_t        position;     
00089         std::string        context;      
00090         PIC_TYPE_ID   valueType;    
00091         std::string        valueName;    
00092         const void *  value;        
00093       } InvalidValueInfo;
00094 
00096       typedef struct
00097       {
00098         size_t        position;     
00099         std::string        context;      
00100         std::string        token;        
00101       } UndefinedTokenInfo;
00102 
00104       typedef struct
00105       {
00106         size_t        position;     
00107         std::string        expected;     
00108         std::string        encountered;  
00109       } UnexpectedTokenInfo;
00110 
00112       typedef struct
00113       {
00114         size_t        position;     
00115         std::string        context;      
00116         std::string        token;        
00117       } UnknownTokenInfo;
00118 
00120       typedef struct
00121       {
00122         size_t        position;     
00123         std::string        context;      
00124         std::string        token;        
00125       } UnsupportedTokenInfo;
00126 
00128       typedef struct
00129       {
00130         std::string        file;         
00131         unsigned int  systemSpecificErrorCode; 
00132       } FileAccessFailedInfo;
00133 
00135       typedef struct
00136       {
00137         unsigned int  systemSpecificErrorCode; 
00138       } FileMappingFailedInfo;
00139 
00141       typedef struct
00142       {
00143         std::string        file;         
00144         std::string        context;      
00145         unsigned int  expectedVersion; 
00146 
00147         unsigned int  detectedVersion; 
00148 
00149       } IncompatibleFileInfo;      
00150 
00152       typedef struct
00153       {
00154         std::string        file;         
00155         std::string        context;      
00156       } InvalidFileInfo;
00157 
00158     public:
00160       PlugInCallback();
00161 
00163       void  setThrowExceptionOnError( bool set );
00164 
00166 
00171       virtual void onError( PIC_ERROR eid       
00172                           , const void *info    
00173                           ) const;
00174 
00176 
00182       virtual bool onWarning( PIC_WARNING wid   
00183                             , const void *info  
00184                             ) const;
00185 
00187 
00190       virtual void onUnexpectedEndOfFile( size_t position 
00191                                         ) const;
00192 
00194 
00198       virtual void onUnexpectedToken( size_t position           
00199                                     , const std::string &expected    
00200                                     , const std::string &encountered 
00201                                     ) const;
00202 
00204 
00208       virtual void onUnknownToken( size_t position        
00209                                  , const std::string &context  
00210                                  , const std::string &token    
00211                                  ) const;
00212 
00214 
00218       virtual bool onEmptyToken( size_t position        
00219                                , const std::string &context  
00220                                , const std::string &token    
00221                                ) const;
00222 
00224 
00227       virtual bool onFileEmpty( const std::string &file  
00228                               ) const;
00229 
00231 
00234       virtual bool onFileNotFound( const std::string &file 
00235                                  ) const;
00236 
00238 
00241       virtual bool onFilesNotFound( const std::vector<std::string> &files 
00242                                   ) const;
00243 
00245 
00249       virtual bool onUndefinedToken( size_t position        
00250                                    , const std::string &context  
00251                                    , const std::string &token    
00252                                    ) const;
00253 
00255 
00259       virtual bool onIncompatibleValues( size_t position          
00260                                        , const std::string &context    
00261                                        , const std::string &value0Name 
00262                                        , int value0               
00263                                        , const std::string &value1Name 
00264                                        , int value1               
00265                                        ) const;
00266 
00268 
00272       virtual bool onIncompatibleValues( size_t position          
00273                                        , const std::string &context    
00274                                        , const std::string &value0Name 
00275                                        , float value0             
00276                                        , const std::string &value1Name 
00277                                        , float value1             
00278                                        ) const;
00279 
00281 
00285       virtual bool onInvalidValue( size_t position          
00286                                  , const std::string &context    
00287                                  , const std::string &valueName  
00288                                  , int value                
00289                                  ) const;
00290 
00292 
00296       virtual bool onInvalidValue( size_t position          
00297                                  , const std::string &context    
00298                                  , const std::string &valueName  
00299                                  , float value              
00300                                  ) const;
00301 
00303 
00307       virtual bool onUnsupportedToken( size_t position        
00308                                      , const std::string &context  
00309                                      , const std::string &token    
00310                                      ) const;
00311 
00313 
00317       virtual void onFileAccessFailed( const std::string& file  
00318                                      , unsigned int systemSpecificErrorCode 
00319                                      ) const;
00320 
00322 
00326       virtual void onFileMappingFailed( unsigned int systemSpecificErrorCode 
00327                                       ) const; 
00328 
00330 
00334       virtual void onImcompatibleFile( const std::string& file 
00335                                      , const std::string& context 
00336                                      , unsigned int expectedVersion 
00337 
00338                                      , unsigned int detectedVersion 
00339 
00340                                      ) const; 
00341 
00343 
00347       virtual void onInvalidFile( const std::string& file 
00348                                 , const std::string& context 
00349                                 ) const;
00350 
00351     protected: 
00353       virtual ~PlugInCallback();
00354 
00355     private:
00356       bool  m_throwExceptionOnError;
00357   };
00358 
00359   inline  PlugInCallback::PlugInCallback()
00360     : m_throwExceptionOnError(true)
00361   {
00362   }
00363 
00364   inline  PlugInCallback::~PlugInCallback()
00365   {
00366   }
00367 
00368   inline  void  PlugInCallback::setThrowExceptionOnError( bool set )
00369   {
00370     m_throwExceptionOnError = set;
00371   }
00372 
00373   inline  void  PlugInCallback::onError( PIC_ERROR eid, const void *info ) const
00374   {
00375     if ( m_throwExceptionOnError )
00376     {
00377       throw( eid );
00378     }
00379   }
00380 
00381   inline  bool  PlugInCallback::onWarning( PIC_WARNING wid, const void *info ) const
00382   {
00383     return( true );
00384   }
00385 
00386 
00387   inline  void  PlugInCallback::onUnexpectedEndOfFile( size_t position ) const
00388   {
00389     onError( PICE_UNEXPECTED_EOF, &position );
00390   }
00391 
00392   inline  void  PlugInCallback::onUnexpectedToken( size_t position, const std::string &expected, const std::string &encountered ) const
00393   {
00394     UnexpectedTokenInfo uti;
00395     uti.position    = position;
00396     uti.expected    = expected;
00397     uti.encountered = encountered;
00398     onError( PICE_UNEXPECTED_TOKEN, &uti );
00399   }
00400 
00401   inline  void  PlugInCallback::onUnknownToken( size_t position, const std::string &context, const std::string &token ) const
00402   {
00403     UnknownTokenInfo  uti;
00404     uti.position  = position;
00405     uti.context   = context;
00406     uti.token     = token;
00407     onError( PICE_UNKNOWN_TOKEN, &uti );
00408   }
00409 
00410 
00411   inline  bool  PlugInCallback::onEmptyToken( size_t position, const std::string &context, const std::string &token ) const
00412   {
00413     EmptyTokenInfo  uti;
00414     uti.position  = position;
00415     uti.context   = context;
00416     uti.token     = token;
00417     return( onWarning( PICW_EMPTY_TOKEN, &uti ) );
00418   }
00419 
00420   inline  bool  PlugInCallback::onFileEmpty( const std::string &file ) const
00421   {
00422     return( onWarning( PICW_FILE_EMPTY, &file ) );
00423   }
00424 
00425   inline  bool  PlugInCallback::onFileNotFound( const std::string &file ) const
00426   {
00427     return( onWarning( PICW_FILE_NOT_FOUND, &file ) );
00428   }
00429 
00430   inline  bool  PlugInCallback::onFilesNotFound( const std::vector<std::string> &files ) const
00431   {
00432     return( onWarning( PICW_FILES_NOT_FOUND, &files ) );
00433   }
00434 
00435   inline  bool  PlugInCallback::onUndefinedToken( size_t position, const std::string &context, const std::string &token ) const
00436   {
00437     EmptyTokenInfo  uti;
00438     uti.position  = position;
00439     uti.context   = context;
00440     uti.token     = token;
00441     return( onWarning( PICW_UNDEFINED_TOKEN, &uti ) );
00442   }
00443 
00444   inline  bool  PlugInCallback::onIncompatibleValues( size_t position, const std::string &context, const std::string &value0Name,
00445                                                       int value0, const std::string &value1Name, int value1 ) const
00446   {
00447     IncompatibleValueInfo ivi;
00448     ivi.position    = position;
00449     ivi.context     = context;
00450     ivi.valueType   = PICT_INT;
00451     ivi.value0Name  = value0Name;
00452     ivi.value0      = &value0;
00453     ivi.value1Name  = value1Name;
00454     ivi.value1      = &value1;
00455     return( onWarning( PICW_INCOMPATIBLE_VALUES, &ivi ) );
00456   }
00457 
00458   inline  bool  PlugInCallback::onIncompatibleValues( size_t position, const std::string &context, const std::string &value0Name,
00459                                                       float value0, const std::string &value1Name, float value1 ) const
00460   {
00461     IncompatibleValueInfo ivi;
00462     ivi.position    = position;
00463     ivi.context     = context;
00464     ivi.valueType   = PICT_FLOAT;
00465     ivi.value0Name  = value0Name;
00466     ivi.value0      = &value0;
00467     ivi.value1Name  = value1Name;
00468     ivi.value1      = &value1;
00469     return( onWarning( PICW_INCOMPATIBLE_VALUES, &ivi ) );
00470   }
00471 
00472 
00473   inline  bool  PlugInCallback::onInvalidValue( size_t position, const std::string &context,
00474                                                 const std::string &valueName, int value ) const
00475   {
00476     InvalidValueInfo  ivi;
00477     ivi.position  = position;
00478     ivi.context   = context;
00479     ivi.valueName = valueName;
00480     ivi.valueType = PICT_INT;
00481     ivi.value     = &value;
00482     return( onWarning( PICW_INVALID_VALUE, &ivi ) );
00483   }
00484 
00485   inline  bool  PlugInCallback::onInvalidValue( size_t position, const std::string &context,
00486                                                 const std::string &valueName, float value ) const
00487   {
00488     InvalidValueInfo  ivi;
00489     ivi.position  = position;
00490     ivi.context   = context;
00491     ivi.valueName = valueName;
00492     ivi.valueType = PICT_FLOAT;
00493     ivi.value     = &value;
00494     return( onWarning( PICW_INVALID_VALUE, &ivi ) );
00495   }
00496 
00497   inline  bool  PlugInCallback::onUnsupportedToken( size_t position, const std::string &context, const std::string &token ) const
00498   {
00499     UnsupportedTokenInfo  uti;
00500     uti.position  = position;
00501     uti.context   = context;
00502     uti.token     = token;
00503     return( onWarning( PICW_UNSUPPORTED_TOKEN, &uti ) );
00504   }
00505 
00506   inline  void  PlugInCallback::onFileAccessFailed( const std::string& file, unsigned int systemSpecificErrorCode ) const
00507   {
00508     FileAccessFailedInfo fafi;
00509     fafi.file = file;
00510     fafi.systemSpecificErrorCode = systemSpecificErrorCode;
00511     onError(PICE_FILE_ACCESS_FAILED, &fafi);
00512   }
00513 
00514   inline  void  PlugInCallback::onFileMappingFailed( unsigned int systemSpecificErrorCode ) const
00515   {
00516     FileMappingFailedInfo fmfi;
00517     fmfi.systemSpecificErrorCode = systemSpecificErrorCode;
00518     onError(PICE_FILE_MAPPING_FAILED, &fmfi);
00519   }
00520 
00521   inline  void  PlugInCallback::onImcompatibleFile( const std::string& file, const std::string& context
00522                                                   , unsigned int expectedVersion, unsigned int detectedVersion) const
00523   {
00524     IncompatibleFileInfo ifi;
00525     ifi.file = file;
00526     ifi.context = context;
00527     ifi.expectedVersion = expectedVersion;
00528     ifi.detectedVersion = detectedVersion;
00529     onError(PICE_INCOMPATIBLE_FILE, &ifi);
00530   }
00531 
00532   inline  void  PlugInCallback::onInvalidFile( const std::string& file, const std::string& context ) const
00533   {
00534     InvalidFileInfo ifi;
00535     ifi.file = file;
00536     ifi.context = context;
00537     onError(PICE_INVALID_FILE, &ifi);
00538   }
00539 }

Generated on Tue Mar 1 13:19:20 2005 for NVSGSDK by NVIDIA