00001 /* 00002 FALCON - The Falcon Programming Language. 00003 FILE: genericvector.h 00004 00005 Generic vector - a generic vector of elements 00006 ------------------------------------------------------------------- 00007 Author: Giancarlo Niccolai 00008 Begin: ven oct 27 11:02:00 CEST 2006 00009 00010 00011 ------------------------------------------------------------------- 00012 (C) Copyright 2004: the FALCON developers (see list in AUTHORS file) 00013 00014 See LICENSE file for licensing details. 00015 */ 00016 00017 #ifndef flc_genericvector_h 00018 #define flc_genericvector_h 00019 00020 #include <falcon/setup.h> 00021 #include <falcon/traits.h> 00022 #include <falcon/basealloc.h> 00023 00024 namespace Falcon 00025 { 00026 00034 class FALCON_DYN_CLASS GenericVector: public BaseAlloc 00035 { 00036 byte *m_data; 00037 uint32 m_size; 00038 uint32 m_allocated; 00039 uint32 m_threshold_size; 00040 00041 typedef enum { 00042 alloc_block = 32 00043 } consts; 00044 00045 protected: 00046 uint32 m_itemSize; 00047 const ElementTraits *m_traits; 00048 00049 GenericVector(): 00050 m_data(0), 00051 m_size(0), 00052 m_allocated(0), 00053 m_threshold_size(0) 00054 {} 00055 00056 void init( const ElementTraits *traits, uint32 prealloc ); 00057 00058 public: 00059 00060 GenericVector( const ElementTraits *traits, uint32 prealloc=0 ); 00061 ~GenericVector(); 00062 00063 void insert( void *data, uint32 pos ); 00064 bool remove( uint32 pos ); 00065 void *at( uint32 pos ) const { return m_data + ( pos * m_itemSize ); } 00066 void set( void *data, uint32 pos ); 00067 void push( void *data ); 00068 void pop() { m_size --; } 00069 00070 void *top() const { return m_data + ( (m_itemSize) * (m_size-1) ); } 00071 void reserve( uint32 s ); 00072 void resize( uint32 s ); 00073 00074 void threshHold( uint32 size ) { m_threshold_size = size; } 00075 uint32 threshHold() const { return m_threshold_size; } 00076 00077 uint32 size() const { return m_size; } 00078 bool empty() const { return m_size == 0; } 00079 }; 00080 00081 } 00082 00083 #endif 00084 00085 /* end of genericvector.h */