Marsyas  0.5.0-beta1
/Users/jleben/code/marsyas/src/marsyas/system/MarControlAccessor.h
Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 1998-2006 George Tzanetakis <gtzan@cs.uvic.ca>
00003 **
00004 ** This program is free software; you can redistribute it and/or modify
00005 ** it under the terms of the GNU General Public License as published by
00006 ** the Free Software Foundation; either version 2 of the License, or
00007 ** (at your option) any later version.
00008 **
00009 ** This program is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 ** GNU General Public License for more details.
00013 **
00014 ** You should have received a copy of the GNU General Public License
00015 ** along with this program; if not, write to the Free Software
00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 */
00018 
00019 //#ifndef __MARCONTROL__
00020 //#error Do not include this file directly, include only MarControl.h
00021 //#endif
00022 
00023 #include <marsyas/system/MarControl.h>
00024 
00025 namespace Marsyas
00026 {
00032 class MarControlAccessor
00033 {
00034 private:
00035   MarControlPtr ctrl_;
00036   bool update_;
00037   bool readOnlyAccess_;
00038 
00039 public:
00040   MarControlAccessor(MarControlPtr ctrl, bool update = true, bool readOnlyAccess = false)
00041   {
00042     ctrl_ = ctrl;
00043     update_ = update;
00044     readOnlyAccess_ = readOnlyAccess;
00045   }
00046 
00047   ~MarControlAccessor()
00048   {
00049 #ifdef MARSYAS_TRACECONTROLS
00050     ctrl_->value_->setDebugValue();
00051 #endif
00052 
00053     if(update_)
00054       ctrl_->value_->callMarSystemsUpdate();
00055   }
00056 
00057   void enableUpdates() {update_ = true;};
00058   void disableUpdates() {update_ = false;};
00059 
00060   template<class T> T& to()
00061   {
00062     return const_cast<T&>(ctrl_->to<T>());
00063   }
00064 };
00065 }
00066