From 6dfbfb3ec8e889239ae02d88e163a389e5f610b9 Mon Sep 17 00:00:00 2001 From: ganovelli Date: Wed, 31 Mar 2004 03:00:40 +0000 Subject: [PATCH] *** empty log message *** --- apps/test/dataopt/main.cpp | 88 ++++++++++++++++++++++++++++++++ vcg/container_allocation_table.h | 2 - vcg/entries_allocation_table.h | 16 +++--- vcg/simple_temporary_data.h | 65 +++++++++++++++++++++++ 4 files changed, 163 insertions(+), 8 deletions(-) create mode 100644 apps/test/dataopt/main.cpp create mode 100644 vcg/simple_temporary_data.h diff --git a/apps/test/dataopt/main.cpp b/apps/test/dataopt/main.cpp new file mode 100644 index 00000000..039b0624 --- /dev/null +++ b/apps/test/dataopt/main.cpp @@ -0,0 +1,88 @@ +#include +#include + + +#include +#include +using namespace vcg; +#include +#include + + +class EdgeProto{}; +class Vertex0 : public VertexSimp1< Vertex0,EdgeProto,vcg::vert::Coord3fOpt>{}; + +typedef TVector TVect; +int main(){ +int i; + +// partial test for CORE DATA *********** + // put some vertex in a vector + TVector c1; + + for( i = 0; i < 10; i++) + c1.push_back(Vertex0()); + + c1.EnableAttribute(); + + // put some more vertex inthe vector + for( i= 0; i < 10; i++) + c1.push_back(Vertex0()); + + c1[2].P()=Point3f(1.0,2,3); + Point3f p = c1[2].P(); + + // drop the attributes + c1.DisableAttribute(); +// ***************************************** + + +// USER DATA +// si puo' fare in 2 modi: Se il container e'di tipo TVector (traced vector) +// si puo'usare +//(1) c.NewTempData(); che si occupa di resizare +// i container di dati temporanei (cioe' riflette tutte le push_back,reserve,resize +// eventualemnte fatte sul vettore). NewTempoData resituisce una handle per accedere +// al dato. + +// (2) si usa SimpleTempData che e' come uno tranne che non supporta automaticamente +// le variazioni di dimensione +// del vettore (si puo' fare a mano pero')...s + +// partial test for USER DATA *********** +// modo (1) + + for( i = 0; i < 10; i++) + c1.push_back(Vertex0()); + + CATEntry >::Insert(c1); // questa riga sparira' + + TempData handle = c1.NewTempData(); + handle[&c1[3]] = 71; + // put some more vertex inthe vector + for( i = 0; i < 10; i++) + c1.push_back(Vertex0()); + int h = handle[&c1[3]]; + c1.DeleteTempData(handle); +// ***************************************** + + +// partial test for USER DATA *********** +// modo (2) + + std::vector c; + for( i = 0; i < 10; i++) + c.push_back(Vertex0()); + + SimpleTempData,int> tmp(c); + tmp.Start(); + tmp[&c[1]] = 22; + int hh = tmp[&c[1]]; + tmp.Stop(); +// ************************************** + + + } + + + diff --git a/vcg/container_allocation_table.h b/vcg/container_allocation_table.h index 577cceea..a3107279 100644 --- a/vcg/container_allocation_table.h +++ b/vcg/container_allocation_table.h @@ -42,8 +42,6 @@ typedef STL_CONT::value_type VALUE_TYPE; virtual void Resort(VALUE_TYPE*,VALUE_TYPE*) =0; virtual void Remove(const STL_CONT&) = 0; virtual void AddDataElem(VALUE_TYPE*,int)=0; -//virtual void Reserve(STL_CONT::value_type * pt,const int & rs)=0; -//virtual void Resize(STL_CONT::value_type * pt,const int & rs)=0; public: // ID serves as a type trait. diff --git a/vcg/entries_allocation_table.h b/vcg/entries_allocation_table.h index e19e4883..4eed0ff3 100644 --- a/vcg/entries_allocation_table.h +++ b/vcg/entries_allocation_table.h @@ -79,13 +79,14 @@ template - +// ----------------------------------------------------------------------------------------- +// WrapBase: used to implement a list of pointers to std::vector of different types +// Wrap: derived from WrapBase (to take the function and from std::vector) struct WrapBase{ virtual void Push_back(const int & n)=0; virtual void Reserve(const int & n)=0; virtual void Resize(const int & n)=0; }; - // (note) double hineritance is not necessary, just handy template struct Wrap: public WrapBase,std::vector{ @@ -93,9 +94,9 @@ struct Wrap: public WrapBase,std::vector{ virtual void Reserve(const int & n){reserve(n);} virtual void Resize(const int & n){resize(n);} }; +//------------------------------------------------------------------------------------------- - - +// ----------------------------------------------------------------------------------------- // EntryCATMulti: entry type for multiple user data template struct EntryCATMulti: public EntryCATBase{ @@ -121,10 +122,11 @@ virtual void Resize(const int & n){ private: std::list< WrapBase * > data; }; +//---------------------------------------------------------------------------------- - - +//---------------------------------------------------------------------------------- +// TempData implements a handle to one of the vector od data stored in EntryCATMulti template class TempData{ public: @@ -139,6 +141,8 @@ public: return (*item)[pos]; } }; +//---------------------------------------------------------------------------------- + }; // end namespace vcg diff --git a/vcg/simple_temporary_data.h b/vcg/simple_temporary_data.h new file mode 100644 index 00000000..91b20081 --- /dev/null +++ b/vcg/simple_temporary_data.h @@ -0,0 +1,65 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ + + +#ifndef __VCGLIB_SIMPLE__ +#define __VCGLIB_SIMPLE__ + +#include + +namespace vcg { + +template +class SimpleTempData{ +public: +typedef typename ATTR_TYPE attr_type; + +STL_CONT& c; +std::vector data; + +SimpleTempData(STL_CONT &_c):c(_c){}; + +// access to data +ATTR_TYPE & operator[](const STL_CONT::value_type *v){return data[v-&*c.begin()];} +ATTR_TYPE & operator[](const int & i){return data[i];} + +// start temporary attribute +void Start(){data.reserve(c.capacity());data.resize(c.size());} + +// stop temporary attribute +void Stop(){data.clear();} + +// update temproary data size +bool UpdateSize(){ + if(data.size() != c.size()) + { + data.resize(c.size()); + return false; + } + return true; + } +}; + +}; // end namespace vcg + +#endif \ No newline at end of file