pull/21/head
Darrell Anderson 12 years ago
parent 6b96e6cfbb
commit d53e057f92

@ -50,11 +50,11 @@ namespace byte_io {
T read( const unsigned char* ); T read( const unsigned char* );
template<typename T> template<typename T>
struct byte_lenght_struct { }; struct byte_length_struct { };
template<typename T> template<typename T>
struct byte_lenght_struct<const T> { struct byte_length_struct<const T> {
static const int value = byte_lenght_struct<T>::value; static const int value = byte_length_struct<T>::value;
}; };
@ -63,8 +63,8 @@ namespace byte_io {
* for supported types. * for supported types.
*/ */
template<typename T> template<typename T>
unsigned byte_lenght() { unsigned byte_length() {
return byte_lenght_struct<T>::value; return byte_length_struct<T>::value;
} }
} }

@ -39,7 +39,7 @@ namespace byte_io {
} }
template<> template<>
struct byte_lenght_struct<uint8_t> { struct byte_length_struct<uint8_t> {
static const int value = 1; static const int value = 1;
}; };
@ -60,7 +60,7 @@ namespace byte_io {
} }
template<> template<>
struct byte_lenght_struct<uint16_t> { struct byte_length_struct<uint16_t> {
static const int value = 2; static const int value = 2;
}; };
@ -84,7 +84,7 @@ namespace byte_io {
return res; return res;
} }
template<> template<>
struct byte_lenght_struct<uint32_t> { struct byte_length_struct<uint32_t> {
static const int value = 4; static const int value = 4;
}; };
} }

@ -50,7 +50,7 @@ uint32_t leaf_data::get_reference( unsigned idx ) const {
} }
bool leaf_data::can_add( uint32_t ref ) const { bool leaf_data::can_add( uint32_t ref ) const {
if ( ( capacity() - usedbytes() ) > ( 1 + byte_io::byte_lenght<uint32_t>() ) ) return true; if ( ( capacity() - usedbytes() ) > ( 1 + byte_io::byte_length<uint32_t>() ) ) return true;
if ( capacity() == usedbytes() ) return false; if ( capacity() == usedbytes() ) return false;
uint32_t last = 0; uint32_t last = 0;
for ( iterator first = begin(), past = end(); first != past; ++first ) { for ( iterator first = begin(), past = end(); first != past; ++first ) {
@ -97,7 +97,7 @@ void leaf_data::add_reference( uint32_t ref ) {
} else { } else {
*target++ = 0; *target++ = 0;
byte_io::write<uint32_t>( target, ref ); byte_io::write<uint32_t>( target, ref );
set_usedbytes( usedbytes() + 1 + byte_io::byte_lenght<uint32_t>() ); set_usedbytes( usedbytes() + 1 + byte_io::byte_length<uint32_t>() );
} }
assert( usedbytes() <= capacity() ); assert( usedbytes() <= capacity() );
} }
@ -123,7 +123,7 @@ void leaf_data::remove_reference( uint32_t ref ) {
else { else {
++iter; ++iter;
byte_io::write<uint32_t>(iter,byte_io::read<uint32_t>(iter)-1); byte_io::write<uint32_t>(iter,byte_io::read<uint32_t>(iter)-1);
iter += byte_io::byte_lenght<uint32_t>(); iter += byte_io::byte_length<uint32_t>();
} }
} }
} }

@ -60,7 +60,7 @@ struct leafdata_iterator : public std::iterator<STD_NAMESPACE_PREFIX input_itera
value_ += delta; value_ += delta;
} else { } else {
value_ = byte_io::read<uint32_t>( data_ ); value_ = byte_io::read<uint32_t>( data_ );
data_ += byte_io::byte_lenght<uint32_t>(); data_ += byte_io::byte_length<uint32_t>();
} }
return value_ - 1; return value_ - 1;
} }

@ -135,7 +135,7 @@ void mempool<Traits>::print( std::ostream& out ) const {
template <typename Traits> template <typename Traits>
memory_reference<uint32_t> mempool<Traits>::free_list( unsigned order ) { memory_reference<uint32_t> mempool<Traits>::free_list( unsigned order ) {
assert( order ); assert( order );
return memory_reference<uint32_t>( manager_->rw_base( order * byte_io::byte_lenght<uint32_t>() ) ); return memory_reference<uint32_t>( manager_->rw_base( order * byte_io::byte_length<uint32_t>() ) );
} }
template <typename Traits> template <typename Traits>

@ -72,23 +72,23 @@ struct memory_iterator : public std::iterator<STD_NAMESPACE_PREFIX random_access
} }
memory_iterator& operator ++() { memory_iterator& operator ++() {
data_ += byte_io::byte_lenght<T>(); data_ += byte_io::byte_length<T>();
return *this; return *this;
} }
memory_iterator& operator --() { memory_iterator& operator --() {
data_ -= byte_io::byte_lenght<T>(); data_ -= byte_io::byte_length<T>();
return *this; return *this;
} }
memory_iterator& operator += ( ptrdiff_t dif ) { memory_iterator& operator += ( ptrdiff_t dif ) {
data_ += dif * byte_io::byte_lenght<T>(); data_ += dif * byte_io::byte_length<T>();
return *this; return *this;
} }
ptrdiff_t operator - ( const memory_iterator<T>& other ) const { ptrdiff_t operator - ( const memory_iterator<T>& other ) const {
assert( !( ( raw() - other.raw() )%byte_io::byte_lenght<T>() ) ); assert( !( ( raw() - other.raw() )%byte_io::byte_length<T>() ) );
return ( raw() - other.raw() )/byte_io::byte_lenght<T>(); return ( raw() - other.raw() )/byte_io::byte_length<T>();
} }
bool operator < ( const memory_iterator<T>& other ) const { bool operator < ( const memory_iterator<T>& other ) const {
@ -211,8 +211,8 @@ struct memvector {
boost::scoped_ptr<memory_manager> data_; boost::scoped_ptr<memory_manager> data_;
unsigned char* address_of( unsigned i ) { unsigned char* address_of( unsigned i ) {
return data_->rw_base( return data_->rw_base(
byte_io::byte_lenght<unsigned>() + byte_io::byte_length<unsigned>() +
i * byte_io::byte_lenght<T>() ); i * byte_io::byte_length<T>() );
} }
const unsigned char* address_of( unsigned i ) const { const unsigned char* address_of( unsigned i ) const {
return const_cast<memvector*>( this )->address_of( i ); return const_cast<memvector*>( this )->address_of( i );

@ -9,7 +9,7 @@ memvector<T>::memvector( std::string fname ):
data_( new mmap_manager( fname ) ) data_( new mmap_manager( fname ) )
{ {
if ( !data_->size() ) { if ( !data_->size() ) {
data_->resize( byte_io::byte_lenght<unsigned>() ); data_->resize( byte_io::byte_length<unsigned>() );
byte_io::write<unsigned>( data_->rw_base( 0 ), 0 ); byte_io::write<unsigned>( data_->rw_base( 0 ), 0 );
} }
} }
@ -31,7 +31,7 @@ void memvector<T>::resize( size_type n_s ) {
if ( size() >= n_s ) return; if ( size() >= n_s ) return;
using namespace byte_io; using namespace byte_io;
data_->resize( n_s * byte_lenght<value_type>() + byte_lenght<unsigned>() ); data_->resize( n_s * byte_length<value_type>() + byte_length<unsigned>() );
iterator p_end = end(); iterator p_end = end();
write<unsigned>( data_->rw_base( 0 ), n_s ); write<unsigned>( data_->rw_base( 0 ), n_s );
while ( p_end != end() ) { while ( p_end != end() ) {
@ -45,10 +45,10 @@ void memvector<T>::insert( const_iterator where, const value_type v ) {
assert( !( where < begin() ) ); assert( !( where < begin() ) );
assert( where <= end() ); assert( where <= end() );
const unsigned to_idx = where.raw() - data_->ronly_base( 0 ); 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>() ); data_->resize( ( size() + 1 ) * byte_io::byte_length<value_type>() + byte_io::byte_length<unsigned>() );
unsigned char* to = data_->rw_base( to_idx ); unsigned char* to = data_->rw_base( to_idx );
// make space: // make space:
std::memmove( to + byte_io::byte_lenght<value_type>(), to, end().raw() - to ); std::memmove( to + byte_io::byte_length<value_type>(), to, end().raw() - to );
byte_io::write<value_type>( to, v ); byte_io::write<value_type>( to, v );
byte_io::write<unsigned>( data_->rw_base( 0 ), size() + 1 ); byte_io::write<unsigned>( data_->rw_base( 0 ), size() + 1 );
} }
@ -68,7 +68,7 @@ void memvector<T>::erase( iterator where ) {
template <typename T> template <typename T>
void memvector<T>::clear() { void memvector<T>::clear() {
data_->resize( byte_io::byte_lenght<uint32_t>() ); data_->resize( byte_io::byte_length<uint32_t>() );
byte_io::write<uint32_t>( data_->rw_base( 0 ), 0 ); byte_io::write<uint32_t>( data_->rw_base( 0 ), 0 );
} }

@ -157,8 +157,8 @@ struct simple_accessor {
write<uint32_t>( out, p.cast_to_uint32() ); \ write<uint32_t>( out, p.cast_to_uint32() ); \
} \ } \
template<> \ template<> \
struct byte_lenght_struct< pointer <name> > { \ struct byte_length_struct< pointer <name> > { \
static const unsigned value = byte_lenght_struct<uint32_t>::value; \ static const unsigned value = byte_length_struct<uint32_t>::value; \
}; \ }; \
} // namespace } // namespace

Loading…
Cancel
Save