Also use Objects as part of an operation but as a result don't generate Any operation...
[ACE_TAO.git] / ACE / ace / Read_Buffer.h
blobb22d3f2d85a414e870beb1c6cb1e10a0e2388d36
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 #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,
58 ACE_Allocator * = 0);
59 #endif // ACE_HAS_WINCE
61 /// Closes the FILE *.
62 ~ACE_Read_Buffer (void);
64 /**
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,
75 int search = '\n',
76 int replace = '\0');
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;
91 private:
93 // Disallow copying and assignment...
94 void operator= (const ACE_Read_Buffer &);
95 ACE_Read_Buffer (const ACE_Read_Buffer &);
97 private:
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.
102 size_t size_;
104 /// The total number of characters replaced.
105 size_t occurrences_;
107 /// The stream we are reading from.
108 FILE *stream_;
110 /// Keeps track of whether we should close the FILE in the
111 /// destructor.
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 */