diff options
Diffstat (limited to 'file_index.h')
-rw-r--r-- | file_index.h | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/file_index.h b/file_index.h index 2f055b1..92cf11c 100644 --- a/file_index.h +++ b/file_index.h @@ -25,7 +25,8 @@ class Block long long pos_, size_; // pos + size <= INT64_MAX public: - Block( const long long p, const long long s ) : pos_( p ), size_( s ) {} + Block( const long long p, const long long s ) + : pos_( p ), size_( s ) {} long long pos() const { return pos_; } long long size() const { return size_; } @@ -34,9 +35,17 @@ public: void pos( const long long p ) { pos_ = p; } void size( const long long s ) { size_ = s; } + bool operator==( const Block & b ) const + { return pos_ == b.pos_ && size_ == b.size_; } + bool operator!=( const Block & b ) const + { return pos_ != b.pos_ || size_ != b.size_; } + + bool operator<( const Block & b ) const { return pos_ < b.pos_; } + bool overlaps( const Block & b ) const { return ( pos_ < b.end() && b.pos_ < end() ); } void shift( Block & b ) { ++size_; ++b.pos_; --b.size_; } + Block split( const long long pos ); }; @@ -49,18 +58,35 @@ class File_index Member( const long long dp, const long long ds, const long long mp, const long long ms ) : dblock( dp, ds ), mblock( mp, ms ) {} + + bool operator==( const Member & m ) const { return ( mblock == m.mblock ); } + bool operator!=( const Member & m ) const { return ( mblock != m.mblock ); } }; std::vector< Member > member_vector; std::string error_; + long long isize; int retval_; public: - File_index( const int infd ); + File_index() : error_( "No index." ), isize( 0 ), retval_( 2 ) {} + explicit File_index( const int infd ); + File_index( const std::vector< int > & infd_vector, const long long fsize ); + int members() const { return member_vector.size(); } const std::string & error() const { return error_; } int retval() const { return retval_; } + bool operator==( const File_index & fi ) const + { + if( retval_ || fi.retval_ || isize != fi.isize || + member_vector.size() != fi.member_vector.size() ) return false; + for( unsigned i = 0; i < member_vector.size(); ++i ) + if( member_vector[i] != fi.member_vector[i] ) return false; + return true; + } + bool operator!=( const File_index & fi ) const { return !( *this == fi ); } + long long data_end() const { if( member_vector.size() ) return member_vector.back().dblock.end(); else return 0; } @@ -69,11 +95,14 @@ public: { if( member_vector.size() ) return member_vector.back().mblock.end(); else return 0; } + // total size including trailing garbage (if any) + long long file_size() const + { if( isize >= 0 ) return isize; else return 0; } + const Block & dblock( const int i ) const { return member_vector[i].dblock; } const Block & mblock( const int i ) const { return member_vector[i].mblock; } - int members() const { return (int)member_vector.size(); } }; |