source: pacpusframework/trunk/3rd/apache-log4cxx/include/log4cxx/helpers/charsetencoder.h@ 178

Last change on this file since 178 was 89, checked in by morasjul, 11 years ago

PACPUS 2.0 Beta deployed in new branch

Major changes:
-Add communication interface between components
-Add examples for communications interface (TestComponents)
-Move to Qt5 support

  • Property svn:executable set to *
File size: 4.5 KB
Line 
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_CHARSETENCODER_H
19#define _LOG4CXX_HELPERS_CHARSETENCODER_H
20
21#include <log4cxx/helpers/objectimpl.h>
22#include <log4cxx/helpers/pool.h>
23
24namespace log4cxx
25{
26
27 namespace helpers {
28 class ByteBuffer;
29 class CharsetEncoder;
30 LOG4CXX_PTR_DEF(CharsetEncoder);
31
32 /**
33 * An engine to transform LogStrings into bytes
34 * for the specific character set.
35 */
36 class LOG4CXX_EXPORT CharsetEncoder : public ObjectImpl
37 {
38 public:
39 DECLARE_ABSTRACT_LOG4CXX_OBJECT(CharsetEncoder)
40 BEGIN_LOG4CXX_CAST_MAP()
41 LOG4CXX_CAST_ENTRY(CharsetEncoder)
42 END_LOG4CXX_CAST_MAP()
43
44 protected:
45 /**
46 * Protected constructor.
47 */
48 CharsetEncoder();
49
50 public:
51 /**
52 * Destructor.
53 */
54 virtual ~CharsetEncoder();
55 /**
56 * Get encoder for default charset.
57 */
58 static CharsetEncoderPtr getDefaultEncoder();
59
60 /**
61 * Get encoder for specified character set.
62 * @param charset the following values should be recognized:
63 * "US-ASCII", "ISO-8859-1", "UTF-8",
64 * "UTF-16BE", "UTF-16LE".
65 * @return encoder.
66 * @throws IllegalArgumentException if encoding is not recognized.
67 */
68 static CharsetEncoderPtr getEncoder(const LogString& charset);
69
70
71 /**
72 * Get encoder for UTF-8.
73 */
74 static CharsetEncoderPtr getUTF8Encoder();
75
76 /**
77 * Encodes a string replacing unmappable
78 * characters with escape sequences.
79 *
80 */
81 static void encode(CharsetEncoderPtr& enc,
82 const LogString& src,
83 LogString::const_iterator& iter,
84 ByteBuffer& dst);
85
86 /**
87 * Encodes as many characters from the input string as possible
88 * to the output buffer.
89 * @param in input string
90 * @param iter position in string to start.
91 * @param out output buffer.
92 * @return APR_SUCCESS unless a character can not be represented in
93 * the encoding.
94 */
95 virtual log4cxx_status_t encode(const LogString& in,
96 LogString::const_iterator& iter,
97 ByteBuffer& out) = 0;
98
99 /**
100 * Resets any internal state.
101 */
102 virtual void reset();
103
104 /**
105 * Flushes the encoder.
106 */
107 virtual void flush(ByteBuffer& out);
108
109 /**
110 * Determines if the return value from encode indicates
111 * an unconvertable character.
112 */
113 inline static bool isError(log4cxx_status_t stat) {
114 return (stat != 0);
115 }
116
117
118 private:
119 /**
120 * Private copy constructor.
121 */
122 CharsetEncoder(const CharsetEncoder&);
123 /**
124 * Private assignment operator.
125 */
126 CharsetEncoder& operator=(const CharsetEncoder&);
127
128 static CharsetEncoder* createDefaultEncoder();
129 };
130
131 } // namespace helpers
132
133} //namespace log4cxx
134
135#endif //_LOG4CXX_HELPERS_CHARSETENCODER_H
Note: See TracBrowser for help on using the repository browser.