summaryrefslogtreecommitdiffstats
path: root/indexlib/memvector.tcc
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch)
tree67208f7c145782a7e90b123b982ca78d88cc2c87 /indexlib/memvector.tcc
downloadtdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz
tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'indexlib/memvector.tcc')
-rw-r--r--indexlib/memvector.tcc80
1 files changed, 80 insertions, 0 deletions
diff --git a/indexlib/memvector.tcc b/indexlib/memvector.tcc
new file mode 100644
index 000000000..ef45c2b5f
--- /dev/null
+++ b/indexlib/memvector.tcc
@@ -0,0 +1,80 @@
+#include "format.h"
+#include "mmap_manager.h"
+#include <cstring>
+
+#include <cstring>
+
+template <typename T>
+memvector<T>::memvector( std::string fname ):
+ data_( new mmap_manager( fname ) )
+{
+ if ( !data_->size() ) {
+ data_->resize( byte_io::byte_lenght<unsigned>() );
+ byte_io::write<unsigned>( data_->rw_base( 0 ), 0 );
+ }
+}
+
+template <typename T>
+memvector<T>::~memvector() {
+}
+
+template <typename T>
+void memvector<T>::print( std::ostream& out ) const {
+ out << format( "size(): %s\n" ) % size();
+ for ( const_iterator first = begin(), past = end(); first != past; ++first ) {
+ out << *first << std::endl;
+ }
+}
+
+template <typename T>
+void memvector<T>::resize( size_type n_s ) {
+ if ( size() >= n_s ) return;
+
+ data_->resize( n_s * byte_io::byte_lenght<value_type>() + byte_io::byte_lenght<unsigned>() );
+ iterator p_end = end();
+ byte_io::write<unsigned>( data_->rw_base( 0 ), n_s );
+ while ( operator !=<unsigned, unsigned>(p_end, end()) ) {
+ *p_end = value_type();
+ ++p_end;
+
+ }
+}
+
+template<typename T>
+void memvector<T>::insert( const_iterator where, const value_type v ) {
+ assert( !( where < begin() ) );
+ assert( where <= end() );
+ const unsigned to_idx = where.raw() - data_->ronly_base( 0 );
+ data_->resize( ( size() + 1 ) * byte_io::byte_lenght<value_type>() + byte_io::byte_lenght<unsigned>() );
+ unsigned char* to = data_->rw_base( to_idx );
+ // make space:
+ std::memmove( to + byte_io::byte_lenght<value_type>(), to, end().raw() - to );
+ byte_io::write<value_type>( to, v );
+ byte_io::write<unsigned>( data_->rw_base( 0 ), size() + 1 );
+}
+
+template <typename T>
+void memvector<T>::erase( iterator where ) {
+
+ assert( size() );
+ assert( !( where < begin() ) );
+ assert( where < end() );
+
+ iterator next = where;
+ ++next;
+ std::memmove( const_cast<unsigned char*>( where.raw() ), next.raw(), end().raw() - next.raw() );
+ byte_io::write<uint32_t>( data_->rw_base( 0 ), size() - 1 );
+}
+
+template <typename T>
+void memvector<T>::clear() {
+ data_->resize( byte_io::byte_lenght<uint32_t>() );
+ byte_io::write<uint32_t>( data_->rw_base( 0 ), 0 );
+}
+
+template<typename T>
+void memvector<T>::remove( std::string fname ) {
+ ::unlink( fname.c_str() );
+}
+
+