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
00064
00065
00066
00067
00068 #define CBUF_SMALLEST_ALLOC_SIZE 128
00069
00070 class ANL_CBUF
00071 {
00072 private:
00073
00074 const char *_splitchars;
00075 const char *_continuation;
00076 UINT32 _max_linelength;
00077 UINT32 _linelength;
00078 UINT32 _chunk_size;
00079 UINT _size;
00080 UINT _next;
00081 char *_buf;
00082 MEM_POOL *_pool;
00083
00084 UINT _A_Number_Of_Chunks(UINT size)
00085 {
00086 return (size <= 0? 0 : (((size/_chunk_size) + 1) * _chunk_size));
00087 }
00088
00089 char *_Alloc(UINT size)
00090 {
00091 char *buf;
00092
00093 if (size > 0)
00094 {
00095 buf = CXX_NEW_ARRAY(char, size, _pool);
00096 buf[0] = '\0';
00097 }
00098 else
00099 buf = NULL;
00100 return buf;
00101 }
00102
00103 BOOL _Is_Splitc(char splitc);
00104
00105 void _Split();
00106
00107 public:
00108
00109
00110
00111 ANL_CBUF(MEM_POOL *pool):
00112 _splitchars(""),
00113 _continuation(""),
00114 _max_linelength(UINT32_MAX),
00115 _linelength(0),
00116 _chunk_size(CBUF_SMALLEST_ALLOC_SIZE),
00117 _size(0),
00118 _next(0),
00119 _buf(NULL),
00120 _pool(pool)
00121 {}
00122
00123 ANL_CBUF(MEM_POOL *pool, UINT chunk_size, UINT size):
00124 _splitchars(""),
00125 _continuation(""),
00126 _linelength(0),
00127 _max_linelength(UINT32_MAX),
00128 _next(0),
00129 _pool(pool)
00130 {
00131 _chunk_size = (chunk_size > CBUF_SMALLEST_ALLOC_SIZE?
00132 chunk_size : CBUF_SMALLEST_ALLOC_SIZE);
00133 _size = _A_Number_Of_Chunks(size);
00134 _buf = _Alloc(_size);
00135 }
00136
00137 ANL_CBUF(MEM_POOL *pool, const char *s);
00138
00139
00140
00141
00142 ~ANL_CBUF()
00143 {
00144 if (_size > 0)
00145 CXX_DELETE_ARRAY(_buf, _pool);
00146 }
00147
00148
00149
00150 void Set_Linesplit(const char *continuation,
00151 const char *splitchars,
00152 mUINT32 max_linelength)
00153 {
00154
00155
00156
00157
00158 _splitchars = splitchars;
00159 _continuation = continuation;
00160 _max_linelength = max_linelength;
00161 }
00162
00163 void Reset_Linesplit()
00164 {
00165 _splitchars = "";
00166 _continuation = "";
00167 _max_linelength = UINT32_MAX;
00168 }
00169
00170 void Reset()
00171 {
00172 _next = 0;
00173 }
00174
00175 void Reduce_Size(UINT by_amount)
00176 {
00177 _next = (by_amount > _next? 0 : (_next - by_amount));
00178 _buf[_next] = '\0';
00179 }
00180
00181 void Write_Char(char c);
00182
00183 void Write_String(const char *s);
00184
00185 void Write_Int(INT64 i)
00186 {
00187 char s[32];
00188
00189 sprintf(s, "%1lld", i);
00190 Write_String(s);
00191 }
00192
00193 void Append_Pragma_Preamble(BOOL is_omp, BOOL lower_case);
00194
00195
00196
00197 UINT Size() const {return _next;}
00198 const char *Chars() const {return _buf;}
00199
00200 };
00201
00202
00203 #endif