1//
2// Formatter.h
3//
4// Library: Foundation
5// Package: Logging
6// Module: Formatter
7//
8// Definition of the Formatter class.
9//
10// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
11// and Contributors.
12//
13// SPDX-License-Identifier: BSL-1.0
14//
15
16
17#ifndef Foundation_Formatter_INCLUDED
18#define Foundation_Formatter_INCLUDED
19
20
21#include "Poco/Foundation.h"
22#include "Poco/Configurable.h"
23#include "Poco/RefCountedObject.h"
24#include "Poco/AutoPtr.h"
25
26
27namespace Poco {
28
29
30class Message;
31
32
33class Foundation_API Formatter: public Configurable, public RefCountedObject
34 /// The base class for all Formatter classes.
35 ///
36 /// A formatter basically takes a Message object
37 /// and formats it into a string. How the formatting
38 /// is exactly done is up to the implementation of
39 /// Formatter. For example, a very simple implementation
40 /// might simply take the message's Text (see Message::getText()).
41 /// A useful implementation should at least take the Message's
42 /// Time, Priority and Text fields and put them into a string.
43 ///
44 /// The Formatter class supports the Configurable interface,
45 /// so the behaviour of certain formatters is configurable.
46 /// It also supports reference counting based garbage collection.
47 ///
48 /// Trivial implementations of of getProperty() and
49 /// setProperty() are provided.
50 ///
51 /// Subclasses must at least provide a format() method.
52{
53public:
54 typedef AutoPtr<Formatter> Ptr;
55
56 Formatter();
57 /// Creates the formatter.
58
59 virtual void format(const Message& msg, std::string& text) = 0;
60 /// Formats the message and places the result in text.
61 /// Subclasses must override this method.
62
63 void setProperty(const std::string& name, const std::string& value);
64 /// Throws a PropertyNotSupportedException.
65
66 std::string getProperty(const std::string& name) const;
67 /// Throws a PropertyNotSupportedException.
68
69protected:
70 virtual ~Formatter();
71 /// Destroys the formatter.
72};
73
74
75} // namespace Poco
76
77
78#endif // Foundation_Formatter_INCLUDED
79