5 #include "filedata.hpp"
9 FileData::FileData( char _type,
13 unsigned long long _size,
14 unsigned long long _modified_date,
15 unsigned long long _last_backup,
18 permissions( _permissions ),
22 modified_date( _modified_date ),
23 last_backup_date( _last_backup ),
27 vector<string> split( const string &line, char c, int limit = -1 ) {
28 string::size_type start = 0, end = 0;
31 while( 0 != limit-- && end != line.size() ) {
35 end = line.find( c, start );
36 if( end == string::npos ) {
40 out.push_back( line.substr( start, end-start ) );
46 ostream &operator<<( const FileData *d, ostream &o ) {
47 return operator<<( *d, o );
50 ostream &operator<<( const FileData &d, ostream &o ) {
51 o << d.getFileType() << ' ';
52 o << d.getPermissions() << ' ';
53 o << d.getUserName() << ' ';
54 o << d.getGroupName() << ' ';
55 o << d.getFileSize() << ' ';
56 o << d.getModifiedDate() << ' ';
57 o << d.getLastBackupDate() << ' ';
58 o << d.getFileName() << '\0';
63 istream &operator>>( istream &i, FileData *d ) {
64 return operator>>( i, *d );
67 istream &operator>>( istream &i, FileData &d ) {
70 for( int c = i.get(); 0 != c && ! i.eof(); c = i.get() ) {
71 file_string.push_back( c );
74 if( 0 != file_string.size() ) {
76 // type perms user group size datemodified name (8 total)
77 // f 0600 cnb cnb 424 20051015205340 0 ./.git/index
78 vector<string> vals = split( file_string, ' ', 8 );
79 d.setFileType( vals[0][0] );
80 d.setPermissions( vals[1] );
81 d.setUserName( vals[2] );
82 d.setGroupName( vals[3] );
83 d.setFileSize( atoi( vals[4].c_str() ) );
84 d.setModifiedDate( atoi( vals[5].c_str() ) );
85 d.setLastBackupDate( atoi( vals[6].c_str() ) );
86 d.setFileName( vals[7] );