|
CLAM-Development
1.3
|
00001 /* 00002 * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG) 00003 * UNIVERSITAT POMPEU FABRA 00004 * 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 * 00020 */ 00021 00022 00023 #include "ProcessingDefinitionAdapter.hxx" 00024 #include "Assert.hxx" 00025 #include "Processing.hxx" 00026 #include "ProcessingConfig.hxx" 00027 #include "ProcessingFactory.hxx" 00028 #include "XMLAdapter.hxx" 00029 #include "XmlStorageErr.hxx" 00030 00031 namespace CLAM 00032 { 00033 ProcessingDefinitionAdapter::ProcessingDefinitionAdapter( Processing * adaptee, const std::string & name, const std::string & position, const std::string & size ) 00034 : mAdaptee(adaptee) 00035 , mConfiguration(0) 00036 , mName(name) 00037 , mPosition(position) 00038 , mSize(size) 00039 { 00040 } 00041 00042 ProcessingDefinitionAdapter::~ProcessingDefinitionAdapter() 00043 { 00044 if (mConfiguration) delete mConfiguration; 00045 } 00046 00047 void ProcessingDefinitionAdapter::StoreOn (Storage & store) const 00048 { 00049 Text nameCopy(mName); 00050 XMLAdapter<Text> nameAdapter( nameCopy, "id"); 00051 Text className(mAdaptee->GetClassName()); 00052 XMLAdapter<Text> classNameAdapter( className, "type"); 00053 store.Store(nameAdapter); 00054 store.Store(classNameAdapter); 00055 if (mPosition!="") // check if position is defined (QPoint values are integers) 00056 { 00057 Text positionCopy(mPosition); 00058 XMLAdapter<Text> positionAdapter (positionCopy, "position"); 00059 store.Store(positionAdapter); 00060 } 00061 if (mSize!="") // check if size is defined 00062 { 00063 Text sizeCopy(mSize); 00064 XMLAdapter<Text> sizeAdapter (sizeCopy, "size"); 00065 store.Store(sizeAdapter); 00066 } 00067 XMLComponentAdapter configAdapter((ProcessingConfig&)mAdaptee->GetConfig()); 00068 store.Store(configAdapter); 00069 } 00070 00071 void ProcessingDefinitionAdapter::LoadFrom (Storage & store) 00072 { 00073 XMLAdapter<Text> nameAdapter( mName, "id"); 00074 if (!store.Load(nameAdapter)) 00075 throw XmlStorageErr("Processing without id attribute"); 00076 Text className; 00077 XMLAdapter<Text> classNameAdapter( className, "type"); 00078 if (!store.Load(classNameAdapter)) 00079 throw XmlStorageErr("Processing without type attribute"); 00080 00081 XMLAdapter<Text> positionAdapter (mPosition, "position"); 00082 store.Load(positionAdapter); 00083 XMLAdapter<Text> sizeAdapter (mSize, "size"); 00084 store.Load(sizeAdapter); 00085 00086 try 00087 { 00088 mAdaptee = ProcessingFactory::GetInstance().CreateSafe(className); 00089 } catch (ErrFactory & e) 00090 { 00091 std::string msg = 00092 "Error creating a processing object of type '" + 00093 className + "' which is not available."; 00094 throw XmlStorageErr(msg); 00095 } 00096 Component * cfg = mAdaptee->GetConfig().DeepCopy(); 00097 XMLComponentAdapter configAdapter( *cfg ); 00098 store.Load(configAdapter); 00099 mConfiguration = dynamic_cast<ProcessingConfig *>(cfg); 00100 CLAM_ASSERT(mConfiguration, "Retrieved config fails to cast as a ProcessingConfig"); 00101 } 00102 } // namespace CLAM 00103
1.7.6.1