defuze.me  Client
locker.cpp
00001 /**************************************************************************
00002 ** defuze.me Epitech Innovative Project
00003 **
00004 ** Copyright 2010-2011
00005 **   Athena Calmettes - Jocelyn De La Rosa - Francois Gaillard
00006 **   Adrien Jarthon - Alexandre Moore - Luc Peres - Arnaud Sellier
00007 **
00008 ** All rights reserved.
00009 **************************************************************************/
00010 
00011 #include "locker.hpp"
00012 #include "exception.hpp"
00013 
00014 Locker::Locker()
00015 {
00016 }
00017 
00018 Locker::~Locker()
00019 {
00020 }
00021 
00022 void Locker::setLock(const QString &flag)
00023 {
00024     if (flags.contains(flag))
00025         flags[flag] += 1;
00026     else
00027         flags[flag] = 1;
00028 }
00029 
00030 void Locker::unLock(const QString &flag)
00031 {
00032     if (flags.contains(flag))
00033         flags[flag] -= 1;
00034     else
00035         flags[flag] = 0;
00036 }
00037 
00038 bool Locker::isLocked(const QString &flag) const
00039 {
00040     if (flags.contains(flag))
00041         return (flags[flag] != 0);
00042     else
00043         return false;
00044 }
00045 
00046 void Locker::assertNotLocked(const QString &flag) const
00047 {
00048     if (isLocked(flag))
00049         throw_exception(0x01, QObject::tr("Ressource '%1' is locked.").arg(flag));
00050 }