diff --git a/CMakeLists.txt b/CMakeLists.txt index ea408b7..30b5790 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,6 @@ set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/build/bin) set(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/lib) - find_package(gflags REQUIRED) include_directories(lz4/lib) diff --git a/README.org b/README.org index f185944..5408b11 100644 --- a/README.org +++ b/README.org @@ -1,3 +1,8 @@ + +* Introduction + + A collection of C++ + * install git clone --recursive git@github.com:zzjjzzgggg/cpplib.git diff --git a/io/ioutils.h b/io/ioutils.h index 2a4e6fb..8b4d597 100644 --- a/io/ioutils.h +++ b/io/ioutils.h @@ -28,18 +28,26 @@ std::unique_ptr getIOIn(const std::string& filename); class TSVParser { private: - size_t line_NO_; char split_ch_; - char buf_[1024]; // assume each line has a maximum length of 1024 bytes. + size_t line_NO_; + std::string filename_; + + // assume each line has a maximum length of 1024 bytes. + char buf_[1024]; std::vector field_vec_; std::unique_ptr in_ptr_; public: TSVParser(const std::string& filename, const char sep = '\t') - : line_NO_(0), split_ch_(sep) { + : split_ch_(sep), line_NO_(0), filename_(filename) { in_ptr_ = getIOIn(filename); } + void reset() { + line_NO_ = 0; + in_ptr_ = getIOIn(filename_); + } + bool next(); int getNumFields() const { return (int)(field_vec_.size()); } diff --git a/io/lz4io.h b/io/lz4io.h index ec7f8aa..f84be63 100644 --- a/io/lz4io.h +++ b/io/lz4io.h @@ -165,6 +165,6 @@ class LZ4In : public IOIn { void decompress(const char* output_file_name); }; -} +} // namespace ioutils #endif /* __LZ4IO_H__ */ diff --git a/test/test_ioutils.cpp b/test/test_ioutils.cpp index cf5c055..4df8360 100644 --- a/test/test_ioutils.cpp +++ b/test/test_ioutils.cpp @@ -6,8 +6,8 @@ */ #include -#include "ioutils.h" -#include "osutils.h" +#include "../io/ioutils.h" +#include "../os/osutils.h" void test_null_ptr() { // auto ptr = std::unique_ptr(); @@ -27,7 +27,19 @@ void test_print() { ioutils::printMap(m); } +void test_tsvparser() { + printf("use file test.dat\n"); + ioutils::TSVParser ss("test.dat"); + while (ss.next()) printf("%d ", ss.get(0)); + printf("\n"); + + ss.reset(); + while (ss.next()) printf("%d ", ss.get(0)); + printf("\n"); +} + int main(int argc, char* argv[]) { - test_null_ptr(); + // test_null_ptr(); + test_tsvparser(); return 0; }