00001 // -*- C++ -*- 00002 00003 //========================================================================== 00004 /** 00005 * @file Read_Buffer.h 00006 * 00007 * $Id: Read_Buffer.h,v 1.1.1.4 2003/02/21 18:36:32 chad Exp $ 00008 * 00009 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu> 00010 * @author Seth Widoff 00011 */ 00012 //========================================================================== 00013 00014 #ifndef ACE_READ_BUFFER_H 00015 #define ACE_READ_BUFFER_H 00016 00017 #include "ace/pre.h" 00018 00019 #include "ace/ACE_export.h" 00020 00021 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00022 # pragma once 00023 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00024 00025 #include "ace/OS.h" 00026 00027 class ACE_Allocator; 00028 00029 /** 00030 * @class ACE_Read_Buffer 00031 * 00032 * @brief Efficiently reads an artibrarily large buffer from an input 00033 * stream up to and including a termination character. Also 00034 * performs search/replace on single occurrences a character in 00035 * the buffer using the principles of Integrated Layer 00036 * Processing. 00037 * 00038 * This implementation is optimized to do a single dynamic 00039 * allocation and make only one copy of the data. It uses 00040 * recursion and the run-time stack to accomplish this 00041 * efficiently. 00042 */ 00043 class ACE_Export ACE_Read_Buffer 00044 { 00045 public: 00046 // = Initialization and termination methods. 00047 /// Read from a FILE *. 00048 ACE_Read_Buffer (FILE *fp, 00049 int close_on_delete = 0, 00050 ACE_Allocator * = 0); 00051 00052 #if !defined (ACE_HAS_WINCE) 00053 // Note that ACE_HANDLE = FILE under CE. 00054 00055 /// Read from an open HANDLE. 00056 ACE_Read_Buffer (ACE_HANDLE handle, 00057 int close_on_delete = 0, 00058 ACE_Allocator * = 0); 00059 #endif // ACE_HAS_WINCE 00060 00061 /// Closes the FILE *. 00062 ~ACE_Read_Buffer (void); 00063 00064 /** 00065 * Returns a pointer dynamically allocated with 00066 * <ACE_Allocator::malloc> to data from the input stream up to (and 00067 * including) the <terminator>. If <search> is >= 0 then all 00068 * occurrences of the <search> value are substituted with the 00069 * <replace> value. The last of the byte of data is a 0, so that 00070 * <strlen> can be used on it. The caller is responsible for 00071 * freeing the pointer returned from this method using the 00072 * <ACE_Allocator::free>. 00073 */ 00074 char *read (int terminator = EOF, 00075 int search = '\n', 00076 int replace = '\0'); 00077 00078 /// Returns the number of characters replaced during a <read>. 00079 size_t replaced (void) const; 00080 00081 /// Returns the size of the allocated buffer obtained during a 00082 /// <read>, not including the null terminator. 00083 size_t size (void) const; 00084 00085 /// Returns a pointer to its allocator. 00086 ACE_Allocator *alloc (void) const; 00087 00088 /// Dump the state of the object. 00089 void dump (void) const; 00090 00091 private: 00092 /// Recursive helper method that does the work... 00093 char *rec_read (int term, int search, int replace); 00094 00095 /// The total number of characters in the buffer. 00096 size_t size_; 00097 00098 /// The total number of characters replaced. 00099 size_t occurrences_; 00100 00101 /// The stream we are reading from. 00102 FILE *stream_; 00103 00104 /// Keeps track of whether we should close the FILE in the 00105 /// destructor. 00106 int close_on_delete_; 00107 00108 /// Pointer to the allocator. 00109 ACE_Allocator *allocator_; 00110 00111 // = Disallow copying and assignment... 00112 ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_Read_Buffer &)) 00113 ACE_UNIMPLEMENTED_FUNC (ACE_Read_Buffer (const ACE_Read_Buffer &)) 00114 }; 00115 00116 #if defined (__ACE_INLINE__) 00117 # include "ace/Read_Buffer.i" 00118 #endif /* __ACE_INLINE__ */ 00119 00120 #include "ace/post.h" 00121 00122 #endif /* ACE_READ_BUFFER_H */
1.2.14 written by Dimitri van Heesch,
© 1997-2002