1 /* ///////////////////////////////////////////////////////////////////////
7 * Brief: file_log class
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
13 #ifndef EXTL_LOG_FILE_LOG_H
14 #define EXTL_LOG_FILE_LOG_H
17 * \brief file_log class
20 # error file_log.h need be supported by c++.
23 /* ///////////////////////////////////////////////////////////////////////
26 #include "file_report_traits.h"
28 /* ///////////////////////////////////////////////////////////////////////
29 * ::extl::detail 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()
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);
66 return e_w_fopen(filename
, flag
);
69 static char_type
const* default_flag()
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
90 template< typename_param_k C
91 , e_size_t RECORD_MAX_SIZE
95 : public log_base
<C
, file_report_traits
, RECORD_MAX_SIZE
>
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
;
104 typedef EXTL_NS_DETAIL(file_log_traits
)<C
> file_log_traits_type
;
105 typedef FILE* handle_type
;
112 #ifdef EXTL_COMPILER_IS_VECTORC
117 static char_type
const* default_flag()
119 return file_log_traits_type::default_flag();
122 /// \name Constructors
129 basic_file_log(char_type
const* filename
, char_type
const* flag
= default_flag())
130 : base_type(report_traits_type(open(filename
, flag
)))
139 /// \name Opens and closes the file log
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
);
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 /* ///////////////////////////////////////////////////////////////////////
169 /* //////////////////////////////////////////////////////////////////// */
170 #endif /* EXTL_LOG_FILE_LOG_H */
171 /* //////////////////////////////////////////////////////////////////// */