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 /// Read from an open HANDLE.
53 ACE_Read_Buffer (ACE_HANDLE handle
,
54 bool close_on_delete
= false,
57 /// Closes the FILE *.
61 * Returns a pointer dynamically allocated with
62 * ACE_Allocator::malloc() to data from the input stream up to (and
63 * including) the @a terminator. If @a search is >= 0 then all
64 * occurrences of the @a search value are substituted with the
65 * @a replace value. The last of the byte of data is a 0, so that
66 * @c strlen can be used on it. The caller is responsible for
67 * freeing the pointer returned from this method using the
68 * ACE_Allocator::free().
70 char *read (int terminator
= EOF
,
74 /// Returns the number of characters replaced during a @c read.
75 size_t replaced () const;
77 /// Returns the size of the allocated buffer obtained during a
78 /// @c read, not including the null terminator.
81 /// Returns a pointer to its allocator.
82 ACE_Allocator
*alloc () const;
84 /// Dump the state of the object.
88 void operator= (const ACE_Read_Buffer
&) = delete;
89 ACE_Read_Buffer (const ACE_Read_Buffer
&) = delete;
90 void operator= (ACE_Read_Buffer
&&) = delete;
91 ACE_Read_Buffer (ACE_Read_Buffer
&&) = delete;
94 /// Recursive helper method that does the work...
95 char *rec_read (int term
, int search
, int replace
);
97 /// The total number of characters in the buffer.
100 /// The total number of characters replaced.
103 /// The stream we are reading from.
106 /// Keeps track of whether we should close the FILE in the
108 bool const close_on_delete_
;
110 /// Pointer to the allocator.
111 ACE_Allocator
*allocator_
;
114 ACE_END_VERSIONED_NAMESPACE_DECL
116 #if defined (__ACE_INLINE__)
117 # include "ace/Read_Buffer.inl"
118 #endif /* __ACE_INLINE__ */
120 #include /**/ "ace/post.h"
122 #endif /* ACE_READ_BUFFER_H */