PDataContainer.cpp

Go to the documentation of this file.
00001 // Copyright (C) 2005 Dave Griffiths
00002 //
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 
00017 #include "PDataContainer.h"
00018 
00019 using namespace Fluxus;
00020 
00021 PDataContainer::PDataContainer() 
00022 {
00023 }
00024 
00025 PDataContainer::PDataContainer(const PDataContainer &other) 
00026 {
00027     Clear();
00028     for (map<string,PData*>::const_iterator i=other.m_PData.begin(); 
00029         i!=other.m_PData.end(); i++)
00030     {
00031         m_PData[i->first] = i->second->Copy();
00032     }
00033 }
00034 
00035 PDataContainer::~PDataContainer() 
00036 {
00037     Clear();
00038 }
00039 
00040 void PDataContainer::Clear()
00041 {
00042     for (map<string,PData*>::iterator i=m_PData.begin(); i!=m_PData.end(); i++)
00043     {
00044         delete i->second;
00045     }
00046 }   
00047 
00048 void PDataContainer::Resize(unsigned int size)
00049 {
00050     for (map<string,PData*>::iterator i=m_PData.begin(); i!=m_PData.end(); i++)
00051     {
00052         i->second->Resize(size);
00053     }
00054 }
00055 
00056     
00057 unsigned int PDataContainer::Size() const
00058 {
00059     if (!m_PData.empty())
00060     {
00061         return m_PData.begin()->second->Size();
00062     }
00063     
00064     return 0;
00065 }
00066 
00067 bool PDataContainer::GetDataInfo(const string &name, char &type, unsigned int &size) const
00068 {
00069     map<string,PData*>::const_iterator i=m_PData.find(name);
00070     if (i==m_PData.end())
00071     {
00072         return false;
00073     }
00074     
00075     size=i->second->Size();
00076     
00077     //\todo: remove all this dynamic casting and store the char type inside pdata...
00078     TypedPData<dVector> *data = dynamic_cast<TypedPData<dVector>*>(i->second);  
00079     if (data) type='v';
00080     else
00081     {
00082         TypedPData<dColour> *data = dynamic_cast<TypedPData<dColour>*>(i->second);
00083         if (data) type='c';
00084         else 
00085         {
00086             TypedPData<float> *data = dynamic_cast<TypedPData<float>*>(i->second);
00087             if (data) type='f';
00088             else 
00089             {
00090                 TypedPData<dMatrix> *data = dynamic_cast<TypedPData<dMatrix>*>(i->second);
00091                 if (data) type='m';
00092             }
00093         }
00094     }
00095         
00096     return true;
00097 }
00098     
00099 void PDataContainer::AddData(const string &name, PData* pd)
00100 {
00101     map<string,PData*>::iterator i=m_PData.find(name);
00102     if (i!=m_PData.end())
00103     {
00104         Trace::Stream<<"Primitive::AddData: pdata: "<<name<<" already exists"<<endl;
00105         return;
00106     }
00107     
00108     m_PData[name]=pd;
00109 }
00110 
00111 void PDataContainer::CopyData(const string &name, string newname)
00112 {
00113     map<string,PData*>::iterator i=m_PData.find(name);
00114     if (i==m_PData.end())
00115     {
00116         Trace::Stream<<"Primitive::CopyData: pdata source: "<<name<<" doesn't exist"<<endl;
00117         return;
00118     }
00119     
00120     // delete the old one if it exists
00121     map<string,PData*>::iterator oldi=m_PData.find(newname);
00122     if (oldi!=m_PData.end())
00123     {
00124         delete oldi->second;
00125     }
00126     
00127     m_PData[newname]=i->second->Copy();
00128     
00129     PDataDirty();
00130 }
00131 
00132 void PDataContainer::RemoveDataVec(const string &name)
00133 {
00134     map<string,PData*>::iterator i=m_PData.find(name);
00135     if (i==m_PData.end())
00136     {
00137         Trace::Stream<<"Primitive::RemovePDataVec: pdata: "<<name<<" doesn't exist"<<endl;
00138         return;
00139     }
00140     
00141     delete i->second;
00142     m_PData.erase(i);
00143 }
00144 
00145 PData* PDataContainer::GetDataRaw(const string &name)
00146 {
00147     map<string,PData*>::iterator i=m_PData.find(name);
00148     if (i==m_PData.end())
00149     {
00150         return NULL;
00151     }
00152     
00153     return i->second;
00154 }
00155 
00156 const PData* PDataContainer::GetDataRawConst(const string &name) const
00157 {
00158     map<string,PData*>::const_iterator i=m_PData.find(name);
00159     if (i==m_PData.end())
00160     {
00161         return NULL;
00162     }
00163     
00164     return i->second;
00165 }
00166 
00167 void PDataContainer::SetDataRaw(const string &name, PData* pd)
00168 {
00169     map<string,PData*>::iterator i=m_PData.find(name);
00170     if (i==m_PData.end())
00171     {
00172         Trace::Stream<<"Primitive::SetDataRaw: pdata: "<<name<<" doesn't exist"<<endl;
00173         return;
00174     }
00175     delete i->second;
00176     i->second = pd;
00177     PDataDirty();
00178 }
00179 
00180 void PDataContainer::GetDataNames(vector<string> &names) const
00181 {
00182     for (map<string,PData*>::const_iterator i=m_PData.begin(); i!=m_PData.end(); ++i)
00183     {
00184         names.push_back(i->first);
00185     }
00186 }

Generated on Wed Sep 17 21:16:30 2008 for The Fluxus Renderer (libfluxus) by  doxygen 1.5.1