33 #ifndef __INCLUDE_MIST_LINES__
34 #define __INCLUDE_MIST_LINES__
37 #ifndef __INCLUDE_MIST_CONF_H__
38 #include "../config/mist_conf.h"
52 namespace __lines_controller__
54 struct lines_controller
56 static const unsigned char *get_line(
const unsigned char *s,
const unsigned char *e, std::string &line,
bool &__has_eol__ )
63 if( s + 1 != e && s[ 1 ] ==
'\n' )
74 else if( s[ 0 ] ==
'\n' )
85 return( s > e ? e : s );
88 template <
template <
typename T,
typename A >
class Array,
class Allocator >
89 static bool read( Array< std::string, Allocator > &lines,
const std::string &filename )
92 if( ( fp = gzopen( filename.c_str( ),
"rb" ) ) == NULL )
97 std::string line =
"";
98 size_t numBytes = 4096;
99 unsigned char *buff =
new unsigned char[ numBytes ];
101 while( gzeof( fp ) == 0 )
103 ptrdiff_t read_size = gzread( fp, (
void * )buff, static_cast< unsigned int >(
sizeof(
unsigned char ) * numBytes ) );
105 const unsigned char *sp = buff;
106 const unsigned char *ep = sp + read_size;
110 bool __has_eol__ =
false;
111 sp = get_line( sp, ep, line, __has_eol__ );
113 if( !line.empty( ) && __has_eol__ )
115 lines.push_back( line );
123 lines.push_back( line );
159 template <
template <
typename T,
typename A >
class Array,
class Allocator >
160 bool read_lines( Array< std::string, Allocator > &lines,
const std::string &filename )
164 return( __lines_controller__::lines_controller::read( lines, filename ) );
179 template <
template <
typename T,
typename A >
class Array,
class Allocator >
180 bool read_lines( Array< std::string, Allocator > &lines,
const std::wstring &filename )
193 #endif // __INCLUDE_MIST_LINES__