Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / ace / Read_Buffer.h
blobee3a96133b053d93b8df3d6b2c29262e718c7471
1 // -*- C++ -*-
3 //==========================================================================
4 /**
5 * @file Read_Buffer.h
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
8 * @author Seth Widoff
9 */
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)
20 # 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
28 class ACE_Allocator;
30 /**
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
37 * Processing.
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
42 * efficiently.
44 class ACE_Export ACE_Read_Buffer
46 public:
47 /// Read from a FILE *.
48 ACE_Read_Buffer (FILE *fp,
49 bool close_on_delete = false,
50 ACE_Allocator * = 0);
52 /// Read from an open HANDLE.
53 ACE_Read_Buffer (ACE_HANDLE handle,
54 bool close_on_delete = false,
55 ACE_Allocator * = 0);
57 /// Closes the FILE *.
58 ~ACE_Read_Buffer ();
60 /**
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,
71 int search = '\n',
72 int replace = '\0');
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.
79 size_t size () const;
81 /// Returns a pointer to its allocator.
82 ACE_Allocator *alloc () const;
84 /// Dump the state of the object.
85 void dump () const;
87 private:
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;
93 private:
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.
98 size_t size_;
100 /// The total number of characters replaced.
101 size_t occurrences_;
103 /// The stream we are reading from.
104 FILE *stream_;
106 /// Keeps track of whether we should close the FILE in the
107 /// destructor.
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 */