OMKIAccessRule.cpp

Go to the documentation of this file.
00001 
00002 /************************************************************************/
00003 /* This file is part of openMask(c) INRIA, CNRS, Universite de Rennes 1 */
00004 /* 1993-2002, thereinafter the Software                                 */
00005 /*                                                                      */
00006 /* The Software has been developped within the Siames Project.          */
00007 /* INRIA, the University of Rennes 1 and CNRS jointly hold intellectual */
00008 /* property rights                                                      */
00009 /*                                                                      */
00010 /* The Software has been registered with the Agence pour la Protection  */
00011 /* des Programmes (APP) under registration number                       */
00012 /* IDDN.FR.001.510008.00.S.P.2001.000.41200                             */
00013 /*                                                                      */
00014 /* This file may be distributed under the terms of the Q Public License */
00015 /* version 1.0 as defined by Trolltech AS of Norway and appearing in    */
00016 /* the file LICENSE.QPL included in the packaging of this file.         */
00017 /*                                                                      */
00018 /* Licensees holding valid specific licenses issued by INRIA, CNRS or   */
00019 /* Universite Rennes 1 for the software may use this file in            */
00020 /* acordance with that specific license                                 */
00021 /************************************************************************/
00022                 
00023 #include "OMKIAccessRule.h"
00024 #include "OMKParametersAccessor.inl"
00025 
00026 using namespace OMK ;
00027 using namespace OMK::Iii ;
00028 using namespace OMK::Type ;
00029 
00030 IAccessRule::IAccessRule( const ConfigurationParameterDescriptor* node )
00031 : _defaultLevel(),
00032   _currentLevel(),
00033   _freezableLevel( -1 ),
00034   _freezableType( UNFREEZABLE )
00035 {
00036   // read the acces type
00037   std::map< std::string, FreezableType > mapping ;
00038   mapping[ "unfreezable"             ] = UNFREEZABLE ;
00039   mapping[ "freezable at tool level" ] = FREEZABLE_AT_TOOL_LEVEL ;
00040   mapping[ "freezable at any level"  ] = FREEZABLE_AT_ANY_LEVEL ;
00041   ParametersAccessor::get( node, "FreezableType", _freezableType, mapping ) ;
00042 
00043   // if necessary read the max level
00044   if( FREEZABLE_AT_ANY_LEVEL == _freezableType ) 
00045     ParametersAccessor::get( node, "FreezableLevel", _freezableLevel ) ;
00046 
00047   // acces level for default group
00048   _defaultLevel[ "*" ] = -1 ;
00049   // try to find one in the parameters
00050   ParametersAccessor::get( node, "AccessLevels", _defaultLevel ) ;
00051   // copy the default in the current to start
00052   _currentLevel = _defaultLevel ;
00053 }
00054 
00055 //-----------------------------------------------------------------------------
00056 IAccessRule::~IAccessRule()
00057 {
00058 }
00059 
00060 //-----------------------------------------------------------------------------
00061 AccessLevel IAccessRule::getAccessLevel( const Name& name ) const 
00062 {
00063   AccessGroupLevel::const_iterator item = _currentLevel.find( name ) ;
00064   if( item == _currentLevel.end() )
00065   {
00066     item = _currentLevel.find( "*" ) ;
00067   }
00068   return ( item != _currentLevel.end() ) ? item->second : -1  ;
00069 }
00070 
00071 //-----------------------------------------------------------------------------
00072 bool IAccessRule::isAccessGranted( AccessLevel level, const Name& group ) const 
00073 { 
00074   return getAccessLevel( group ) <= level ; 
00075 }
00076 
00077 //-----------------------------------------------------------------------------
00078 void IAccessRule::resetCurrentLevel() 
00079 {
00080   _currentLevel = _defaultLevel ;
00081 }
00082 
00083 //========================================================================

logo OpenMask

Documentation generated on Mon Jun 9 11:45:56 2008

Generated with doxygen by Dimitri van Heesch ,   1997-2007