📄 evalrat.cpp
字号:
// EvalRat.cpp : Implementation of CEvalRat
#include "stdafx.h"
#include "CxTVRate.h"
#include "EvalRat.h"
#include "cxTVRateDbg.h"
/////////////////////////////////////////////////////////////////////////////
// CEvalRat
// By default unrated programs should be allowed, so _blockUnrated = FALSE
CEvalRat::CEvalRat(): _blockUnrated( FALSE )
{
DBP(( "CEvalRat::CEvalRat() -- called\n" ));
// Initialize the blocking Flags to unblocked.
for( int i = 0; i < NUM_SYSTEMS; ++i )
for( int j = 0; j < NUM_LEVELS; ++j )
_blockingFlags[i][j] = 0;
}
STDMETHODIMP
CEvalRat::get_BlockedRatingAttributes( EnTvRat_System system,
EnTvRat_GenericLevel level,
LONG *p_attrib )
{
DBP(( "CEvalRat::get_BlockedRatingAttributes() -- called\n" ));
if( !p_attrib )
return E_POINTER;
// Check if the system is supported and the level is valid
if( system >= MPAA && system <= Canadian_French &&
level >= TvRat_0 && level <= TvRat_7 )
{
*p_attrib = _blockingFlags[system][level];
return S_OK;
}
else
return E_INVALIDARG;
}
STDMETHODIMP
CEvalRat::get_BlockUnRated( BOOL *p_blockUnrated )
{
DBP(( "CEvalRat::get_BlockUnRated() -- called\n" ));
if( !p_blockUnrated )
return E_POINTER;
*p_blockUnrated = _blockUnrated;
return S_OK;
}
int
cntAttribs( LONG attrib )
{
int numAttribsSet = 0;
ULONG msk = US_TV_IsViolent;
// Count the number of attribute flags set.
for( ; msk <= US_TV_IsSexuallySuggestiveDialog; msk <<= 1 )
if( msk & attrib )
numAttribsSet++;
return numAttribsSet;
}
STDMETHODIMP
CEvalRat::MostRestrictiveRating( EnTvRat_System system1,
EnTvRat_GenericLevel level1,
LONG attrib1,
EnTvRat_System system2,
EnTvRat_GenericLevel level2,
LONG attrib2,
EnTvRat_System *p_retSystem,
EnTvRat_GenericLevel *p_retLevel,
LONG *p_retAttrib )
{
DBP(( "CEvalRat::MostRestrictiveRating() -- called\n" ));
if( !p_retSystem || !p_retLevel || !p_retAttrib )
return E_POINTER;
// When we compare ratings from two different rating systems, we are to
// return a rating expressed in the first system unless the first system
// is TvRat_SystemDontKnow, then we use the second system. see DX9 SDK.
*p_retSystem = system1 == TvRat_SystemDontKnow ? system2 : system1;
*p_retLevel = min( level1, level2 );
*p_retAttrib = level1 < level2 ? attrib1 : attrib2;
if( level1 == level2 && system1 == US_TV && system2 == US_TV )
{
*p_retAttrib = cntAttribs( attrib1 ) > cntAttribs( attrib2 ) ?
attrib1 : attrib2;
}
return system1 == system2 ? S_OK : S_FALSE;
}
STDMETHODIMP
CEvalRat::put_BlockedRatingAttributes( EnTvRat_System system,
EnTvRat_GenericLevel level,
LONG attrib )
{
DBP(( "CEvalRat::put_BRAtr() sys = %x lev = %x atr = %x\n",
system, level, attrib ));
// Check if the system is supported and the level is valid
if( system >= MPAA && system <= Canadian_French &&
level >= TvRat_0 && level <= TvRat_7 )
{
_blockingFlags[system][level] = attrib;
}
return S_OK;
}
STDMETHODIMP
CEvalRat::put_BlockUnRated( BOOL blockUnrated )
{
DBP(( "CEvalRat::put_BlockUnRated() blockUnrated = %d\n", blockUnrated ));
_blockUnrated = blockUnrated;
return S_OK;
}
STDMETHODIMP
CEvalRat::TestRating( EnTvRat_System system,
EnTvRat_GenericLevel level,
LONG attrib )
{
if( system == TvRat_SystemDontKnow || level == TvRat_LevelDontKnow )
return _blockUnrated ? S_FALSE: S_OK;
if( system >= MPAA && system <= Canadian_French &&
level >= TvRat_0 && level <= TvRat_7 )
return _blockingFlags[system][level] & (BfIsBlocked | attrib) ?
S_FALSE : S_OK;
else
return E_INVALIDARG;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -