3 //==========================================================================
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
10 //==========================================================================
12 #ifndef ACE_READ_BUFFER_H
13 #define ACE_READ_BUFFER_H
15 #include /**/ "ace/pre.h"
17 #include /**/ "ace/ACE_export.h"
19 #if !defined (ACE_LACKS_PRAGMA_ONCE)
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 #include "ace/Global_Macros.h"
24 #include "ace/os_include/os_stdio.h"
26 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
31 * @class ACE_Read_Buffer
33 * @brief Efficiently reads an arbitrarily large buffer from an input
34 * stream up to and including a termination character. Also
35 * performs search/replace on single occurrences a character in
36 * the buffer using the principles of Integrated Layer
39 * This implementation is optimized to do a single dynamic
40 * allocation and make only one copy of the data. It uses
41 * recursion and the run-time stack to accomplish this
44 class ACE_Export ACE_Read_Buffer
47 /// Read from a FILE *.
48 ACE_Read_Buffer (FILE *fp
,
49 bool close_on_delete
= false,
52 #if !defined (ACE_HAS_WINCE)
53 // Note that ACE_HANDLE = FILE under CE.
55 /// Read from an open HANDLE.
56 ACE_Read_Buffer (ACE_HANDLE handle
,
57 bool close_on_delete
= false,
59 #endif // ACE_HAS_WINCE
61 /// Closes the FILE *.
62 ~ACE_Read_Buffer (void);
65 * Returns a pointer dynamically allocated with
66 * ACE_Allocator::malloc() to data from the input stream up to (and
67 * including) the @a terminator. If @a search is >= 0 then all
68 * occurrences of the @a search value are substituted with the
69 * @a replace value. The last of the byte of data is a 0, so that
70 * @c strlen can be used on it. The caller is responsible for
71 * freeing the pointer returned from this method using the
72 * ACE_Allocator::free().
74 char *read (int terminator
= EOF
,
78 /// Returns the number of characters replaced during a @c read.
79 size_t replaced (void) const;
81 /// Returns the size of the allocated buffer obtained during a
82 /// @c read, not including the null terminator.
83 size_t size (void) const;
85 /// Returns a pointer to its allocator.
86 ACE_Allocator
*alloc (void) const;
88 /// Dump the state of the object.
89 void dump (void) const;
93 // Disallow copying and assignment...
94 void operator= (const ACE_Read_Buffer
&);
95 ACE_Read_Buffer (const ACE_Read_Buffer
&);
98 /// Recursive helper method that does the work...
99 char *rec_read (int term
, int search
, int replace
);
101 /// The total number of characters in the buffer.
104 /// The total number of characters replaced.
107 /// The stream we are reading from.
110 /// Keeps track of whether we should close the FILE in the
112 bool const close_on_delete_
;
114 /// Pointer to the allocator.
115 ACE_Allocator
*allocator_
;
118 ACE_END_VERSIONED_NAMESPACE_DECL
120 #if defined (__ACE_INLINE__)
121 # include "ace/Read_Buffer.inl"
122 #endif /* __ACE_INLINE__ */
124 #include /**/ "ace/post.h"
126 #endif /* ACE_READ_BUFFER_H */