[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / dep / ACE_wrappers / ace / Read_Buffer.h
blobfafd42d6512599a3c08f7057732c6fa85dc99c45
1 // -*- C++ -*-
3 //==========================================================================
4 /**
5 * @file Read_Buffer.h
7 * $Id: Read_Buffer.h 80826 2008-03-04 14:51:23Z wotte $
9 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
10 * @author Seth Widoff
12 //==========================================================================
14 #ifndef ACE_READ_BUFFER_H
15 #define ACE_READ_BUFFER_H
17 #include /**/ "ace/pre.h"
19 #include /**/ "ace/ACE_export.h"
21 #if !defined (ACE_LACKS_PRAGMA_ONCE)
22 # pragma once
23 #endif /* ACE_LACKS_PRAGMA_ONCE */
25 #include "ace/Global_Macros.h"
26 #include "ace/os_include/os_stdio.h"
28 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
30 class ACE_Allocator;
32 /**
33 * @class ACE_Read_Buffer
35 * @brief Efficiently reads an artibrarily large buffer from an input
36 * stream up to and including a termination character. Also
37 * performs search/replace on single occurrences a character in
38 * the buffer using the principles of Integrated Layer
39 * Processing.
41 * This implementation is optimized to do a single dynamic
42 * allocation and make only one copy of the data. It uses
43 * recursion and the run-time stack to accomplish this
44 * efficiently.
46 class ACE_Export ACE_Read_Buffer
48 public:
49 // = Initialization and termination methods.
50 /// Read from a FILE *.
51 ACE_Read_Buffer (FILE *fp,
52 bool close_on_delete = false,
53 ACE_Allocator * = 0);
55 #if !defined (ACE_HAS_WINCE)
56 // Note that ACE_HANDLE = FILE under CE.
58 /// Read from an open HANDLE.
59 ACE_Read_Buffer (ACE_HANDLE handle,
60 bool close_on_delete = false,
61 ACE_Allocator * = 0);
62 #endif // ACE_HAS_WINCE
64 /// Closes the FILE *.
65 ~ACE_Read_Buffer (void);
67 /**
68 * Returns a pointer dynamically allocated with
69 * ACE_Allocator::malloc to data from the input stream up to (and
70 * including) the @a terminator. If @a search is >= 0 then all
71 * occurrences of the @a search value are substituted with the
72 * @a replace value. The last of the byte of data is a 0, so that
73 * @c strlen can be used on it. The caller is responsible for
74 * freeing the pointer returned from this method using the
75 * ACE_Allocator::free.
77 char *read (int terminator = EOF,
78 int search = '\n',
79 int replace = '\0');
81 /// Returns the number of characters replaced during a @c read.
82 size_t replaced (void) const;
84 /// Returns the size of the allocated buffer obtained during a
85 /// @c read, not including the null terminator.
86 size_t size (void) const;
88 /// Returns a pointer to its allocator.
89 ACE_Allocator *alloc (void) const;
91 /// Dump the state of the object.
92 void dump (void) const;
94 private:
96 // Disallow copying and assignment...
97 void operator= (const ACE_Read_Buffer &);
98 ACE_Read_Buffer (const ACE_Read_Buffer &);
100 private:
101 /// Recursive helper method that does the work...
102 char *rec_read (int term, int search, int replace);
104 /// The total number of characters in the buffer.
105 size_t size_;
107 /// The total number of characters replaced.
108 size_t occurrences_;
110 /// The stream we are reading from.
111 FILE *stream_;
113 /// Keeps track of whether we should close the FILE in the
114 /// destructor.
115 bool const close_on_delete_;
117 /// Pointer to the allocator.
118 ACE_Allocator *allocator_;
121 ACE_END_VERSIONED_NAMESPACE_DECL
123 #if defined (__ACE_INLINE__)
124 # include "ace/Read_Buffer.inl"
125 #endif /* __ACE_INLINE__ */
127 #include /**/ "ace/post.h"
129 #endif /* ACE_READ_BUFFER_H */