Marsyas  0.6.0-alpha
/usr/src/RPM/BUILD/marsyas-0.6.0/src/marsyas/system/MarControlManager.cpp
Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 1998-2005 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 #include <marsyas/system/MarControlManager.h>
00020 #include <marsyas/system/MarControlValue.h>
00021 
00022 using namespace Marsyas;
00023 using std::ostringstream;
00024 
00025 MarControlManager* MarControlManager::instance_ = NULL;
00026 
00027 MarControlManager::MarControlManager()
00028 {
00029   /* Will be used when controls are created only using MarControlManager
00030   registerPrototype("mrs_natural", new MarControl(0L));
00031   registerPrototype("mrs_real", new MarControl(0.0));
00032   registerPrototype("mrs_string", new MarControl("empty"));
00033   registerPrototype("mrs_bool", new MarControl(false));
00034   registerPrototype("mrs_realvec", new MarControl(realvec()));*/
00035 }
00036 
00037 MarControlManager::~MarControlManager()
00038 {
00039   registry_.clear();
00040   if (instance_) delete instance_;
00041 }
00042 
00043 void
00044 MarControlManager::registerPrototype(mrs_string type, MarControlPtr control)
00045 {
00046   registry_[type] = control;
00047   typeRegistry_[control->value_->getTypeID()] = type;
00048 }
00049 
00050 MarControlPtr
00051 MarControlManager::create(mrs_string type)
00052 {
00053   if (registry_.find(type) != registry_.end())
00054   {
00055     MarControl *mc = registry_[type]->clone();
00056     return mc;
00057   }
00058 
00059   else
00060   {
00061     MRSWARN("MarControlManager::getPrototype: No prototype found for " + type);
00062     return MarControlPtr();
00063   }
00064 }
00065 
00066 MarControlPtr
00067 MarControlManager::createFromStream(std::string type, std::istream& in)
00068 {
00069   MarControlPtr ctrl = create(type);
00070   if (!ctrl.isInvalid())
00071   {
00072     ctrl->value_->createFromStream(in);
00073   }
00074   else
00075   {
00076     MRSWARN("MarControl::createFromStream Trying to create unknown control type.");
00077   }
00078   return ctrl;
00079 }
00080 
00081 bool MarControlManager::isRegistered (mrs_string name)
00082 {
00083   return (registry_.find(name) != registry_.end());
00084 }
00085 
00086 std::string MarControlManager::getRegisteredType(std::string typeIdName)
00087 {
00088   if (registry_.find(typeIdName) != registry_.end())
00089   {
00090     return typeRegistry_[typeIdName];
00091   }
00092   MRSWARN("MarControlManager::getRegisteredType Unknown type is being queried.");
00093   return "mrs_unknown";
00094 }