00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _UT_IOSTREAMS_H_
00026 #define _UT_IOSTREAMS_H_
00027
00028
00029
00030
00031
00032 #include "UTString.h"
00033
00034
00035
00036
00037
00038 class Buffer_t;
00039
00040
00041
00042
00043
00044 #if LOG_FILE_OPS_CALLERS
00045 #define LOG_FILE_OPS 1
00046 #endif
00047
00048
00049
00050 class UT_EXPORT InputStream_t
00051
00053 {
00054
00055 public:
00056
00057 virtual ~InputStream_t();
00062
00063 virtual Status_t Read( byte* buffer,
00064 int bytes_to_read,
00065 bool force_read_all = true ) = 0;
00087
00088 virtual Status_t ReadLine(out String_t* line);
00098
00099 virtual Status_t Peek( byte* buffer, int bytes_to_read );
00107
00108 virtual Status_t Position(out fileoff_t* position) = 0;
00115
00116 virtual Status_t Seek(fileoff_t position) = 0;
00124
00125 virtual Status_t SeekRelative(fileoff_t delta);
00130
00131 virtual Status_t Close() = 0;
00134
00135
00136 private:
00137
00138 #if LOG_FILE_OPS
00139 void DebugLogReadLineError( stringliteral* why,
00140 const byte* buf,
00141 int length,
00142 int curr_index,
00143 const String_t& accumulated ) const;
00144 #endif
00145 };
00146
00147
00148
00149 class UT_EXPORT OutputStream_t
00150
00152 {
00153
00154 public:
00155
00156 virtual ~OutputStream_t();
00161
00162 virtual Status_t Write( const byte* buffer,
00163 int bytes_to_write,
00164 bool force_write_all = true ) = 0;
00196
00197 virtual Status_t WriteLine( const String_t& line,
00198 line_ending_type_t line_ending = eLINEENDING_native );
00203
00204 virtual Status_t WriteLine( const utf8* line,
00205 line_ending_type_t line_ending = eLINEENDING_native );
00210
00211 virtual Status_t WriteLine( stringliteral* line,
00212 line_ending_type_t line_ending = eLINEENDING_native );
00217
00218 virtual Status_t Position(out fileoff_t* position) = 0;
00225
00226 virtual Status_t Seek(fileoff_t position) = 0;
00233
00234 virtual Status_t SeekRelative(fileoff_t delta);
00239
00240 virtual Status_t Flush() = 0;
00246
00247 virtual Status_t Close() = 0;
00254 };
00255
00256
00257
00258 class UT_EXPORT IOStream_t
00259
00260 : public InputStream_t,
00261 public OutputStream_t
00265 {
00266
00267 public:
00268
00269 virtual Status_t Position(out fileoff_t* position) = 0;
00276
00277 virtual Status_t Seek(fileoff_t position) = 0;
00283
00284 virtual Status_t SeekRelative(fileoff_t delta);
00291
00292 virtual Status_t Close() = 0;
00298
00299 #if LOG_FILE_OPS
00300 static void SetFileUnderTest(IOStream_t* file);
00315 #endif
00316
00317
00318 protected:
00319
00320 #if LOG_FILE_OPS
00321 virtual void AppendStateInfo(String_t* state) const;
00328
00329 static void FunctionIn( const IOStream_t* file,
00330 bool from_thread,
00331 stringliteral* function,
00332 stringliteral* format,
00333 ... );
00339
00340 static void FunctionReturnStatusCode( const IOStream_t* file,
00341 bool from_thread,
00342 int line,
00343 error_code_t status );
00349
00350 static void FunctionReturn( const IOStream_t* file, bool from_thread, int line );
00356
00357 static void FunctionLogState( const IOStream_t* file,
00358 bool from_thread,
00359 int line,
00360 stringliteral* format,
00361 ... );
00367
00368 static void FunctionReadStart( const IOStream_t* file,
00369 bool from_thread,
00370 int line,
00371 fileoff_t pos,
00372 int bytes_to_read,
00373 bool force_read_all );
00379
00380 static void FunctionReadData( const IOStream_t* file,
00381 bool from_thread,
00382 int line,
00383 const byte* buffer,
00384 fileoff_t pos,
00385 int bytes_read );
00391
00392 static void FunctionWriteData( const IOStream_t* file,
00393 bool from_thread,
00394 int line,
00395 stringliteral* what,
00396 const byte* buffer,
00397 fileoff_t pos,
00398 int bytes_to_write,
00399 bool force_write_all );
00405 #endif
00406 };
00407
00408
00409
00410 class UT_EXPORT BufferIOStream_t
00411
00412 : public IOStream_t
00414 {
00415
00416 public:
00417
00418 inline BufferIOStream_t(Buffer_t* buffer);
00420
00421 virtual Status_t Read( byte* buffer,
00422 int bytes_to_read,
00423 bool force_read_all = true );
00425
00426 virtual Status_t ReadLine(out String_t* line);
00430
00431 virtual Status_t Peek( byte* buffer, int bytes_to_read );
00433
00434 virtual Status_t Write( const byte* buffer,
00435 int bytes_to_write,
00436 bool force_write_all = true );
00438
00439 virtual Status_t Position(out fileoff_t* position);
00442
00443 virtual Status_t Seek(fileoff_t position);
00445
00446 virtual Status_t SeekRelative(fileoff_t delta);
00449
00450 virtual Status_t Flush();
00452
00453 virtual Status_t Close();
00457
00458
00459 protected:
00460
00461 #if LOG_FILE_OPS
00462 virtual void AppendStateInfo(String_t* state) const;
00470
00471 #endif
00472
00473
00474 private:
00475
00476 Buffer_t* m_buffer;
00477 int m_pos;
00478 };
00479
00480
00481
00482
00483
00484 #if LOG_FILE_OPS
00485
00486
00487 class CallLogger_t;
00488 extern UT_EXPORT CallLogger_t* FileCanLog( const IOStream_t* file, bool from_thread );
00489
00490
00495 #define debug_file_func_in( file, from_thread, func, format, a1, a2 ) \
00496 IOStream_t::FunctionIn( file, from_thread, func, format, a1, a2 )
00497
00502 #define debug_file_func_return_statuscode( file, from_thread, status ) \
00503 IOStream_t::FunctionReturnStatusCode( file, from_thread, __LINE__, status )
00504
00509 #define debug_file_func_return( file, from_thread ) \
00510 IOStream_t::FunctionReturn( file, from_thread, __LINE__ )
00511
00518 #define debug_file_func_state1( file, from_thread, format, a1 ) \
00519 IOStream_t::FunctionLogState( file, from_thread, __LINE__, format, a1 )
00520
00526 #define debug_file_func_state2( file, from_thread, format, a1, a2 ) \
00527 IOStream_t::FunctionLogState( file, from_thread, __LINE__, format, a1, a2 )
00528
00533 #define debug_file_func_read_start( file, from_thread, pos, bytes_to_read, all ) \
00534 IOStream_t::FunctionReadStart( file, from_thread, __LINE__, pos, bytes_to_read, all )
00535
00540 #define debug_file_func_read_data( file, from_thread, buffer, pos, bytes_read ) \
00541 IOStream_t::FunctionReadData( file, from_thread, __LINE__, buffer, pos, bytes_read )
00542
00550 #define debug_file_func_write_data( file, from_thread, what, buffer, pos, bytes_to_write, all ) \
00551 IOStream_t::FunctionWriteData( file, \
00552 from_thread, \
00553 __LINE__, \
00554 what, \
00555 buffer, \
00556 pos, \
00557 bytes_to_write, \
00558 all )
00559
00560 #else
00561
00562 #define debug_file_func_in( file, from_thread, func, format, a1, a2 )
00563 #define debug_file_func_return_statuscode( file, from_thread, status )
00564 #define debug_file_func_return( file, from_thread )
00565 #define debug_file_func_state1( file, from_thread, format, a1 )
00566 #define debug_file_func_state2( file, from_thread, format, a1, a2 )
00567 #define debug_file_func_read_start( file, from_thread, pos, bytes_to_read, all )
00568 #define debug_file_func_read_data( file, from_thread, buffer, pos, bytes_read )
00569 #define debug_file_func_write_data( file, from_thread, what, buffer, pos, bytes_to_write, all )
00570
00571 #endif
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583 inline
00584 BufferIOStream_t::BufferIOStream_t(Buffer_t* buffer)
00585 {
00586 m_buffer = buffer;
00587 m_pos = 0;
00588 }
00589
00590
00591 #endif // _UT_IOSTREAMS_H_