anl_cbuf.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef anl_cbuf_INCLUDED
00038 #define anl_cbuf_INCLUDED
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 #define CBUF_SMALLEST_ALLOC_SIZE 128
00064
00065 class ANL_CBUF
00066 {
00067 private:
00068
00069 const char *_splitchars;
00070 const char *_continuation;
00071 UINT32 _max_linelength;
00072 UINT32 _linelength;
00073 UINT32 _chunk_size;
00074 UINT _size;
00075 UINT _next;
00076 char *_buf;
00077 MEM_POOL *_pool;
00078
00079 UINT _A_Number_Of_Chunks(UINT size)
00080 {
00081 return (size <= 0? 0 : (((size/_chunk_size) + 1) * _chunk_size));
00082 }
00083
00084 char *_Alloc(UINT size)
00085 {
00086 char *buf;
00087
00088 if (size > 0)
00089 {
00090 buf = CXX_NEW_ARRAY(char, size, _pool);
00091 buf[0] = '\0';
00092 }
00093 else
00094 buf = NULL;
00095 return buf;
00096 }
00097
00098 BOOL _Is_Splitc(char splitc);
00099
00100 void _Split();
00101
00102 public:
00103
00104
00105
00106 ANL_CBUF(MEM_POOL *pool):
00107 _splitchars(""),
00108 _continuation(""),
00109 _max_linelength(UINT32_MAX),
00110 _linelength(0),
00111 _chunk_size(CBUF_SMALLEST_ALLOC_SIZE),
00112 _size(0),
00113 _next(0),
00114 _buf(NULL),
00115 _pool(pool)
00116 {}
00117
00118 ANL_CBUF(MEM_POOL *pool, UINT chunk_size, UINT size):
00119 _splitchars(""),
00120 _continuation(""),
00121 _linelength(0),
00122 _max_linelength(UINT32_MAX),
00123 _next(0),
00124 _pool(pool)
00125 {
00126 _chunk_size = (chunk_size > CBUF_SMALLEST_ALLOC_SIZE?
00127 chunk_size : CBUF_SMALLEST_ALLOC_SIZE);
00128 _size = _A_Number_Of_Chunks(size);
00129 _buf = _Alloc(_size);
00130 }
00131
00132 ANL_CBUF(MEM_POOL *pool, const char *s);
00133
00134
00135
00136
00137 ~ANL_CBUF()
00138 {
00139 if (_size > 0)
00140 CXX_DELETE_ARRAY(_buf, _pool);
00141 }
00142
00143
00144
00145 void Set_Linesplit(const char *continuation,
00146 const char *splitchars,
00147 mUINT32 max_linelength)
00148 {
00149
00150
00151
00152
00153 _splitchars = splitchars;
00154 _continuation = continuation;
00155 _max_linelength = max_linelength;
00156 }
00157
00158 void Reset_Linesplit()
00159 {
00160 _splitchars = "";
00161 _continuation = "";
00162 _max_linelength = UINT32_MAX;
00163 }
00164
00165 void Reset()
00166 {
00167 _next = 0;
00168 }
00169
00170 void Reduce_Size(UINT by_amount)
00171 {
00172 _next = (by_amount > _next? 0 : (_next - by_amount));
00173 _buf[_next] = '\0';
00174 }
00175
00176 void Write_Char(char c);
00177
00178 void Write_String(const char *s);
00179
00180 void Write_Int(INT64 i)
00181 {
00182 char s[32];
00183
00184 sprintf(s, "%1lld", i);
00185 Write_String(s);
00186 }
00187
00188 void Append_Pragma_Preamble(BOOL is_omp, BOOL lower_case);
00189
00190
00191
00192 UINT Size() const {return _next;}
00193 const char *Chars() const {return _buf;}
00194
00195 };
00196
00197
00198 #endif