Apache log4cxx  Version 0.12.1
cacheddateformat.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef _LOG4CXX_HELPERS_CACHED_DATE_FORMAT_H
19 #define _LOG4CXX_HELPERS_CACHED_DATE_FORMAT_H
20 
22 
23 #if defined(_MSC_VER)
24  #pragma warning ( push )
25  #pragma warning ( disable: 4251 )
26 #endif
27 
28 namespace log4cxx
29 {
30 namespace pattern
31 {
32 class LOG4CXX_EXPORT CachedDateFormat : public log4cxx::helpers::DateFormat
33 {
34  public:
35  enum
36  {
37  /*
38  * Constant used to represent that there was no change
39  * observed when changing the millisecond count.
40  */
41  NO_MILLISECONDS = -2,
42  /*
43  * Constant used to represent that there was an
44  * observed change, but was an expected change.
45  */
46  UNRECOGNIZED_MILLISECONDS = -1
47  };
48 
49  private:
56  static const logchar digits[];
57 
58 
63  static const int magic1;
64 
65 
69  static const logchar magicString1[];
70 
71 
76  static const int magic2;
77 
78 
82  static const logchar magicString2[];
83 
84 
88  static const logchar zeroString[];
89 
93  log4cxx::helpers::DateFormatPtr formatter;
94 
99  mutable int millisecondStart;
100 
104  mutable log4cxx_time_t slotBegin;
105 
106 
110  mutable LogString cache;
111 
112 
118  const int expiration;
119 
123  mutable log4cxx_time_t previousTime;
124 
125  public:
134  CachedDateFormat(const log4cxx::helpers::DateFormatPtr& dateFormat, int expiration);
135 
146  static int findMillisecondStart(
147  log4cxx_time_t time, const LogString& formatted,
148  const log4cxx::helpers::DateFormatPtr& formatter,
149  log4cxx::helpers::Pool& pool);
150 
158  virtual void format(LogString& sbuf,
159  log4cxx_time_t date,
160  log4cxx::helpers::Pool& p) const;
161 
162  private:
170  static void millisecondFormat(int millis,
171  LogString& buf,
172  int offset);
173 
174 
175  public:
183  virtual void setTimeZone(const log4cxx::helpers::TimeZonePtr& zone);
184 
191  virtual void numberFormat(LogString& s,
192  int n,
193  log4cxx::helpers::Pool& p) const;
194 
202  static int getMaximumCacheValidity(const LogString& pattern);
203 
204  private:
206  CachedDateFormat& operator=(const CachedDateFormat&);
207 
217  static bool regionMatches(
218  const LogString& target,
219  size_t toffset,
220  const LogString& other,
221  size_t ooffset,
222  size_t len);
223 
224 };
225 
226 
227 
228 } // namespace helpers
229 } // namespace log4cxx
230 
231 #if defined(_MSC_VER)
232  #pragma warning (pop)
233 #endif
234 
235 #endif // _LOG4CXX_HELPERS_SIMPLE_DATE_FORMAT_H
Definition: cacheddateformat.h:32
Definition: pool.h:32
DateFormat is an abstract class for date/time formatting patterned after java.text.DateFormat.
Definition: dateformat.h:33
Definition: appender.h:32
std::basic_string< logchar > LogString
Definition: logstring.h:66