00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "MarControlManager.h"
00020 #include "MarControlValue.h"
00021
00022
00023 using namespace Marsyas;
00024 using std::ostringstream;
00025
00026 MarControlManager* MarControlManager::instance_ = NULL;
00027
00028 MarControlManager::MarControlManager()
00029 {
00030
00031
00032
00033
00034
00035
00036 }
00037
00038 MarControlManager::~MarControlManager()
00039 {
00040 registry_.clear();
00041 if (instance_) delete instance_;
00042 }
00043
00044 void
00045 MarControlManager::registerPrototype(mrs_string type, MarControlPtr control)
00046 {
00047 registry_[type] = control;
00048 typeRegistry_[control->value_->getTypeID()] = type;
00049 }
00050
00051 MarControlPtr
00052 MarControlManager::create(mrs_string type)
00053 {
00054 if (registry_.find(type) != registry_.end())
00055 {
00056 MarControl *mc = registry_[type]->clone();
00057 return mc;
00058 }
00059
00060 else
00061 {
00062 MRSWARN("MarControlManager::getPrototype: No prototype found for " + type);
00063 return MarControlPtr();
00064 }
00065 }
00066
00067 MarControlPtr
00068 MarControlManager::createFromStream(std::string type, std::istream& in)
00069 {
00070 MarControlPtr ctrl = create(type);
00071 if (!ctrl.isInvalid())
00072 {
00073 ctrl->value_->createFromStream(in);
00074 }
00075 else
00076 {
00077 MRSWARN("MarControl::createFromStream Trying to create unknown control type.");
00078 }
00079 return ctrl;
00080 }
00081
00082 bool MarControlManager::isRegistered (mrs_string name)
00083 {
00084 return (registry_.find(name) != registry_.end());
00085 }
00086
00087 std::string MarControlManager::getRegisteredType(std::string typeIdName)
00088 {
00089 if (registry_.find(typeIdName) != registry_.end())
00090 {
00091 return typeRegistry_[typeIdName];
00092 }
00093 MRSWARN("MarControlManager::getRegisteredType Unknown type is being queried.");
00094 return "mrs_unknown";
00095 }