remove \r
[extl.git] / extl / log / file_log.h
blob9d3804fc21825be05dbc88155985a9948e5641a0
1 /* ///////////////////////////////////////////////////////////////////////
2 * File: file_log.h
4 * Created: 08.06.08
5 * Updated: 08.06.08
7 * Brief: file_log class
9 * [<Home>]
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
13 #ifndef EXTL_LOG_FILE_LOG_H
14 #define EXTL_LOG_FILE_LOG_H
16 /*!\file file_log.h
17 * \brief file_log class
19 #ifndef __cplusplus
20 # error file_log.h need be supported by c++.
21 #endif
23 /* ///////////////////////////////////////////////////////////////////////
24 * Includes
26 #include "file_report_traits.h"
28 /* ///////////////////////////////////////////////////////////////////////
29 * ::extl::detail namespace
31 EXTL_BEGIN_NAMESPACE
32 EXTL_DETAIL_BEGIN_NAMESPACE
34 template <typename_param_k T>
35 struct file_log_traits{};
37 EXTL_TEMPLATE_SPECIALISATION
38 struct file_log_traits<e_char_t>
40 typedef FILE* handle_type;
41 typedef e_char_t char_type;
43 static handle_type open(char_type const* filename, char_type const* flag)
45 return e_a_fopen(filename, flag);
48 static char_type const* default_flag()
50 return "w";
54 EXTL_TEMPLATE_SPECIALISATION
55 struct file_log_traits<e_wchar_t>
57 typedef FILE* handle_type;
58 typedef e_wchar_t char_type;
60 static handle_type open(char_type const* filename, char_type const* flag)
62 /* DMC: _fwopen will collapse to unicode character set */
63 #if defined(EXTL_COMPILER_IS_DMC) && defined(EXTL_UNICODE)
64 return e_w_fsopen(filename, flag, 1);
65 #else
66 return e_w_fopen(filename, flag);
67 #endif
69 static char_type const* default_flag()
71 return L"w";
75 /* ///////////////////////////////////////////////////////////////////////
76 * ::extl::detail namespace
78 EXTL_DETAIL_END_NAMESPACE
79 /*!\brief file_log class
81 * \param The character type
82 * \param RECORD_MAX_SIZE The maximum size of the record string
83 * \ingroup extl_group_log
85 #ifdef EXTL_TEMPLATE_CLASS_DEFAULT_ARGUMENT_SUPPORT
86 template< typename_param_k C
87 , e_size_t RECORD_MAX_SIZE = EXTL_LOG_RECORD_MAX_SIZE
89 #else
90 template< typename_param_k C
91 , e_size_t RECORD_MAX_SIZE
93 #endif
94 class basic_file_log
95 : public log_base<C, file_report_traits, RECORD_MAX_SIZE>
97 /// \name Types
98 /// @{
99 public:
100 typedef log_base<C, file_report_traits, RECORD_MAX_SIZE> base_type;
101 typedef file_report_traits report_traits_type;
102 typedef basic_file_log<C, RECORD_MAX_SIZE> class_type;
103 typedef C char_type;
104 typedef EXTL_NS_DETAIL(file_log_traits)<C> file_log_traits_type;
105 typedef FILE* handle_type;
106 /// @}
108 private:
109 /// The file handle
110 handle_type m_hfile;
112 #ifdef EXTL_COMPILER_IS_VECTORC
113 public:
114 #else
115 private:
116 #endif
117 static char_type const* default_flag()
119 return file_log_traits_type::default_flag();
122 /// \name Constructors
123 /// @{
124 public:
125 basic_file_log()
126 : base_type()
129 basic_file_log(char_type const* filename, char_type const* flag = default_flag())
130 : base_type(report_traits_type(open(filename, flag)))
133 ~basic_file_log()
135 close();
137 /// @}
139 /// \name Opens and closes the file log
140 /// @{
141 public:
142 handle_type open(char_type const* filename, char_type const* flag = default_flag())
144 EXTL_ASSERT(NULL != filename);
145 EXTL_ASSERT(NULL != flag);
147 m_hfile = file_log_traits_type::open(filename, flag);
148 return m_hfile;
150 void close()
152 if(NULL != m_hfile)
154 fclose(m_hfile);
155 m_hfile = NULL;
158 /// @}
161 typedef basic_file_log<e_char_t, EXTL_LOG_RECORD_MAX_SIZE> file_log_a;
162 typedef basic_file_log<e_wchar_t, EXTL_LOG_RECORD_MAX_SIZE> file_log_w;
163 typedef basic_file_log<e_tchar_t, EXTL_LOG_RECORD_MAX_SIZE> file_log;
164 /* ///////////////////////////////////////////////////////////////////////
165 * ::extl namespace
167 EXTL_END_NAMESPACE
169 /* //////////////////////////////////////////////////////////////////// */
170 #endif /* EXTL_LOG_FILE_LOG_H */
171 /* //////////////////////////////////////////////////////////////////// */