[2] | 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_HELPER_FORMATTING_INFO_H
|
---|
| 19 | #define _LOG4CXX_HELPER_FORMATTING_INFO_H
|
---|
| 20 |
|
---|
| 21 |
|
---|
| 22 | #include <log4cxx/helpers/objectimpl.h>
|
---|
| 23 | #include <log4cxx/logstring.h>
|
---|
| 24 |
|
---|
| 25 | namespace log4cxx {
|
---|
| 26 | namespace pattern {
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 | class FormattingInfo;
|
---|
| 30 | typedef helpers::ObjectPtrT<FormattingInfo> FormattingInfoPtr;
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | /**
|
---|
| 34 | * Modifies the output of a pattern converter for a specified minimum
|
---|
| 35 | * and maximum width and alignment.
|
---|
| 36 | *
|
---|
| 37 | *
|
---|
| 38 | *
|
---|
| 39 | *
|
---|
| 40 | */
|
---|
| 41 | class LOG4CXX_EXPORT FormattingInfo : public virtual log4cxx::helpers::ObjectImpl {
|
---|
| 42 |
|
---|
| 43 | /**
|
---|
| 44 | * Minimum length.
|
---|
| 45 | */
|
---|
| 46 | const int minLength;
|
---|
| 47 |
|
---|
| 48 | /**
|
---|
| 49 | * Maximum length.
|
---|
| 50 | */
|
---|
| 51 | const int maxLength;
|
---|
| 52 |
|
---|
| 53 | /**
|
---|
| 54 | * Alignment.
|
---|
| 55 | */
|
---|
| 56 | const bool leftAlign;
|
---|
| 57 |
|
---|
| 58 | public:
|
---|
| 59 | DECLARE_ABSTRACT_LOG4CXX_OBJECT(FormattingInfo)
|
---|
| 60 | BEGIN_LOG4CXX_CAST_MAP()
|
---|
| 61 | LOG4CXX_CAST_ENTRY(FormattingInfo)
|
---|
| 62 | END_LOG4CXX_CAST_MAP()
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 | /**
|
---|
| 66 | * Creates new instance.
|
---|
| 67 | * @param leftAlign left align if true.
|
---|
| 68 | * @param minLength minimum length.
|
---|
| 69 | * @param maxLength maximum length.
|
---|
| 70 | */
|
---|
| 71 | FormattingInfo(
|
---|
| 72 | const bool leftAlign, const int minLength, const int maxLength);
|
---|
| 73 |
|
---|
| 74 | /**
|
---|
| 75 | * Gets default instance.
|
---|
| 76 | * @return default instance.
|
---|
| 77 | */
|
---|
| 78 | static FormattingInfoPtr getDefault();
|
---|
| 79 |
|
---|
| 80 | /**
|
---|
| 81 | * Determine if left aligned.
|
---|
| 82 | * @return true if left aligned.
|
---|
| 83 | */
|
---|
| 84 | inline bool isLeftAligned() const {
|
---|
| 85 | return leftAlign;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | /**
|
---|
| 89 | * Get minimum length.
|
---|
| 90 | * @return minimum length.
|
---|
| 91 | */
|
---|
| 92 | inline int getMinLength() const {
|
---|
| 93 | return minLength;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | /**
|
---|
| 97 | * Get maximum length.
|
---|
| 98 | * @return maximum length.
|
---|
| 99 | */
|
---|
| 100 | inline int getMaxLength() const {
|
---|
| 101 | return maxLength;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | /**
|
---|
| 105 | * Adjust the content of the buffer based on the specified lengths and alignment.
|
---|
| 106 | *
|
---|
| 107 | * @param fieldStart start of field in buffer.
|
---|
| 108 | * @param buffer buffer to be modified.
|
---|
| 109 | */
|
---|
| 110 | void format(const int fieldStart, LogString& buffer) const;
|
---|
| 111 | };
|
---|
| 112 | LOG4CXX_PTR_DEF(FormattingInfo);
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 |
|
---|
| 117 | #endif
|
---|