ulib  1.0
S.W. Lee's essential C++ library
 All Classes Namespaces Files Functions Variables Typedefs Macros Pages
utextfile.h
Go to the documentation of this file.
1 /*
2  작성자 : 이승욱
3  작성일 : 06.09.23
4  버전 : 0.6.0
5  설명 : 텍스트 파일 처리 라이브러리
6  미구현 : ???
7  버그 : ???
8 */
9 
10 #ifndef ___utextfile___
11 #define ___utextfile___
12 
13 #include <stdio.h>
14 #include <string.h>
15 #include <time.h>
16 #include "ustring.h"
17 
18 #ifndef UNKNOWN
19 #define UNKNOWN -1
20 #endif
21 #ifndef UFILE_BUFF_SIZE
22 #define UFILE_BUFF_SIZE 1024 // fgets로 읽을 버퍼의 크기( 최소 2 이상 )
23 #endif
24 
25 namespace ulib {
26 
27  class CUTextFile {
28  public:
29  // 생성자 소멸자
30  CUTextFile( int verbosity = 0 );
31  CUTextFile( CUString arg_file_name, CUString arg_file_mode = "rb", int verbosity = 0 );
32  ~CUTextFile();
33 
34 
35  public:
36  void Verbosity( int arg_verbosity );
37  bool IsOpen();
38  bool OpenFile( CUString arg_file_name, CUString arg_file_mode = "r" );
39  bool CheckOpen( FILE *fp = stderr );
40  void CloseFile();
41  bool ReopenFile( CUString arg_file_name, CUString arg_file_mode = "r" );
42  FILE *GetFP();
43  void MoveToStart();
44  void MoveToEnd();
45  long GetFileSize();
48 
49  long GetNumLine();
50  bool MoveToLine( long sel_line );
51  bool ReadLine( CUString &str ); // 한 줄의 내용을 읽음. 마지막에 \n 문자는 제거됨.
52  char* ReadLine();
53  bool WriteLine( CUString str ); // 한 줄의 내용을 씀. 마지막에 \n 문자를 자동으로 추가.
54  bool WriteLog( CUString str ); // 로그 파일에 기록 (날짜가 같이 출력됨)
55  //CUString GetLineMem( long sel_line );
56  //bool GetNextLineMem( CUString &str );
57  //bool MoveToNextLine();
58 
59  bool LoadToStr( CUString &str );
60 
61  public:
62 
63  private:
64  //char mem[UFILE_BUFF_SIZE]; //
65  long num_line; // 최대 라인수
66  long now_line; // 현재 라인
67  CUString file_name; // 파일명
68  CUString file_mode; // 파일모드
69  FILE *fp; // 파일포인터
70  long file_size; // 파일 크기
71  int verbosity; // 메시지를 화면에 출력할 정도
72  void Flush();
73 
74  private:
75  // 초기화
76  void Init();
77  char *content;
78  bool LoadToMem();
79  int line_start_idx;
80 
81  };
82 
83 }
84 
85 #endif
86 
87