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()
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)
00068 {
00069     map<string,PData*>::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     TypedPData<dVector> *data = dynamic_cast<TypedPData<dVector>*>(i->second);  
00078     if (data) type='v';
00079     else
00080     {
00081         TypedPData<dColour> *data = dynamic_cast<TypedPData<dColour>*>(i->second);
00082         if (data) type='c';
00083         else 
00084         {
00085             TypedPData<float> *data = dynamic_cast<TypedPData<float>*>(i->second);
00086             if (data) type='f';
00087             else 
00088             {
00089                 TypedPData<dMatrix> *data = dynamic_cast<TypedPData<dMatrix>*>(i->second);
00090                 if (data) type='m';
00091             }
00092         }
00093     }
00094         
00095     return true;
00096 }
00097     
00098 void PDataContainer::AddData(const string &name, PData* pd)
00099 {
00100     map<string,PData*>::iterator i=m_PData.find(name);
00101     if (i!=m_PData.end())
00102     {
00103         Trace::Stream<<"Primitive::AddData: pdata: "<<name<<" already exists"<<endl;
00104         return;
00105     }
00106     
00107     m_PData[name]=pd;
00108 }
00109 
00110 void PDataContainer::CopyData(const string &name, string newname)
00111 {
00112     map<string,PData*>::iterator i=m_PData.find(name);
00113     if (i==m_PData.end())
00114     {
00115         Trace::Stream<<"Primitive::CopyData: pdata source: "<<name<<" doesn't exist"<<endl;
00116         return;
00117     }
00118     
00119     // delete the old one if it exists
00120     map<string,PData*>::iterator oldi=m_PData.find(newname);
00121     if (oldi!=m_PData.end())
00122     {
00123         delete oldi->second;
00124     }
00125     
00126     m_PData[newname]=i->second->Copy();
00127     
00128     PDataDirty();
00129 }
00130 
00131 void PDataContainer::RemoveDataVec(const string &name)
00132 {
00133     map<string,PData*>::iterator i=m_PData.find(name);
00134     if (i==m_PData.end())
00135     {
00136         Trace::Stream<<"Primitive::RemovePDataVec: pdata: "<<name<<" doesn't exist"<<endl;
00137         return;
00138     }
00139     
00140     delete i->second;
00141     m_PData.erase(i);
00142 }
00143 
00144 PData* PDataContainer::GetDataRaw(const string &name)
00145 {
00146     map<string,PData*>::iterator i=m_PData.find(name);
00147     if (i==m_PData.end())
00148     {
00149         return NULL;
00150     }
00151     
00152     return i->second;
00153 }
00154 
00155 void PDataContainer::SetDataRaw(const string &name, PData* pd)
00156 {
00157     map<string,PData*>::iterator i=m_PData.find(name);
00158     if (i==m_PData.end())
00159     {
00160         Trace::Stream<<"Primitive::SetDataRaw: pdata: "<<name<<" doesn't exist"<<endl;
00161         return;
00162     }
00163     delete i->second;
00164     i->second = pd;
00165     PDataDirty();
00166 }

Generated on Mon Feb 11 06:54:25 2008 for The Fluxus Renderer (libfluxus) by  doxygen 1.5.1