1 /**************************************************************************** 2 * VCGLib o o * 3 * Visual and Computer Graphics Library o o * 4 * _ O _ * 5 * Copyright(C) 2004-2016 \/)\/ * 6 * Visual Computing Lab /\/| * 7 * ISTI - Italian National Research Council | * 8 * \ * 9 * All rights reserved. * 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 * This program is distributed in the hope that it will be useful, * 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 19 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * 20 * for more details. * 21 * * 22 ****************************************************************************/ 23 24 #ifndef __VCGLIB_ENTRIES__ 25 #define __VCGLIB_ENTRIES__ 26 27 28 namespace vcg { 29 30 // EntryCATBase: base class for the entry of the allocation table 31 // templated over the container type 32 template <class STL_CONT> 33 class EntryCATBase{ 34 public: EntryCATBase(STL_CONT & _c)35EntryCATBase(STL_CONT & _c):c(_c){}; 36 typename STL_CONT::value_type * Start() const; Empty()37virtual bool Empty(){return true;}; 38 const STL_CONT * C(); Push_back(const int &)39virtual void Push_back(const int &){}; 40 Reserve(const int & s)41virtual void Reserve(const int & s){}; Resize(const int & s)42virtual void Resize(const int & s){}; 43 44 const bool operator < (const EntryCATBase<STL_CONT> & other) const; 45 46 private: 47 STL_CONT & c; 48 }; 49 50 //EntryCAT: entry for the case of optional core types (matches with CAT) 51 template <class STL_CONT,class ATTR_TYPE > 52 struct EntryCAT: public EntryCATBase<STL_CONT>{ 53 typedef ATTR_TYPE attr_type; EntryCATEntryCAT54EntryCAT(STL_CONT & _c) : EntryCATBase<STL_CONT>(_c){}; DataEntryCAT55std::vector<ATTR_TYPE> & Data(){return data;} Push_backEntryCAT56void Push_back(const int & n){ for(int i = 0; i < n ; ++i) data.push_back(ATTR_TYPE());} ReserveEntryCAT57virtual void Reserve(const int & s){data.reserve(s);}; ResizeEntryCAT58virtual void Resize(const int & s){data.resize(s);}; 59 60 61 private: 62 std::vector<ATTR_TYPE> data; 63 }; 64 65 //----------------------EntryCAT: implementation ---------------------------------------- 66 template <class STL_CONT> 67 const bool EntryCATBase<STL_CONT>:: operator < (const EntryCATBase<STL_CONT> & other) const{ 68 return (Start() < other.Start()); 69 } 70 71 template <class STL_CONT> Start()72 typename STL_CONT::value_type * EntryCATBase<STL_CONT>::Start()const { 73 return c.Pointer2begin(); 74 } 75 76 template <class STL_CONT> C()77 const STL_CONT * EntryCATBase<STL_CONT>::C(){ 78 return &c; 79 } 80 81 82 83 }; // end namespace vcg 84 85 #endif 86