ProcessingDefinitionAdapter.cxx

Go to the documentation of this file.
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), mName(name), mPosition(position), mSize(size)
00035         {
00036         }
00037 
00038         ProcessingDefinitionAdapter::~ProcessingDefinitionAdapter()
00039         {
00040         }
00041 
00042         void ProcessingDefinitionAdapter::StoreOn (Storage & store) const
00043         {
00044                 Text nameCopy(mName);
00045                 XMLAdapter<Text> nameAdapter( nameCopy, "id");
00046                 Text className(mAdaptee->GetClassName());
00047                 XMLAdapter<Text> classNameAdapter( className, "type");
00048                 store.Store(nameAdapter);
00049                 store.Store(classNameAdapter);
00050                 if (mPosition!="") // check if position is defined (QPoint values are integers)
00051                 {
00052                         Text positionCopy(mPosition);
00053                         XMLAdapter<Text> positionAdapter (positionCopy, "position");
00054                         store.Store(positionAdapter);
00055                 }
00056                 if (mSize!="") // check if size is defined
00057                 {
00058                         Text sizeCopy(mSize);
00059                         XMLAdapter<Text> sizeAdapter (sizeCopy, "size");
00060                         store.Store(sizeAdapter);
00061                 }
00062                 XMLComponentAdapter configAdapter((ProcessingConfig&)mAdaptee->GetConfig());
00063                 store.Store(configAdapter);
00064         }
00065 
00066         void ProcessingDefinitionAdapter::LoadFrom (Storage & store) 
00067         {       
00068                 XMLAdapter<Text> nameAdapter( mName, "id");
00069                 store.Load(nameAdapter);
00070                 Text className("");
00071                 XMLAdapter<Text> classNameAdapter( className, "type");
00072                 store.Load(classNameAdapter);
00073 
00074                 XMLAdapter<Text> positionAdapter (mPosition, "position");
00075                 store.Load(positionAdapter);
00076                 XMLAdapter<Text> sizeAdapter (mSize, "size");
00077                 store.Load(sizeAdapter);
00078 
00079                 try
00080                 {
00081                         mAdaptee = ProcessingFactory::GetInstance().CreateSafe(className);
00082                 } catch (ErrFactory & e)
00083                 {
00084                         std::string msg = 
00085                                 "Error creating a processing object of type '" +
00086                                 className + "' which is not available.";
00087                         throw XmlStorageErr(msg);
00088                 }
00089                 ProcessingConfig&  cfg = (ProcessingConfig&)mAdaptee->GetConfig();
00090                 XMLComponentAdapter configAdapter( cfg );
00091                 store.Load(configAdapter);
00092                 mAdaptee->Configure(cfg);
00093         }
00094 } // namespace CLAM
00095 

Generated on Tue Aug 12 22:33:43 2008 for CLAM by  doxygen 1.5.5