source: XMLIO_V2/external/include/Poco/Message.h @ 80

Last change on this file since 80 was 80, checked in by ymipsl, 14 years ago

ajout lib externe

  • Property svn:eol-style set to native
File size: 6.2 KB
Line 
1//
2// Message.h
3//
4// $Id: //poco/1.3/Foundation/include/Poco/Message.h#3 $
5//
6// Library: Foundation
7// Package: Logging
8// Module:  Message
9//
10// Definition of the Message class.
11//
12// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
13// and Contributors.
14//
15// Permission is hereby granted, free of charge, to any person or organization
16// obtaining a copy of the software and accompanying documentation covered by
17// this license (the "Software") to use, reproduce, display, distribute,
18// execute, and transmit the Software, and to prepare derivative works of the
19// Software, and to permit third-parties to whom the Software is furnished to
20// do so, all subject to the following:
21//
22// The copyright notices in the Software and this entire statement, including
23// the above license grant, this restriction and the following disclaimer,
24// must be included in all copies of the Software, in whole or in part, and
25// all derivative works of the Software, unless such copies or derivative
26// works are solely in the form of machine-executable object code generated by
27// a source language processor.
28//
29// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35// DEALINGS IN THE SOFTWARE.
36//
37
38
39#ifndef Foundation_Message_INCLUDED
40#define Foundation_Message_INCLUDED
41
42
43#include "Poco/Foundation.h"
44#include "Poco/Timestamp.h"
45#include <map>
46
47
48namespace Poco {
49
50
51class Foundation_API Message
52        /// This class represents a log message that is sent through a
53        /// chain of log channels.
54        ///
55        /// A Message contains a priority denoting the severity of the
56        /// message, a source describing its origin, a text describing
57        /// its meaning, the time of its creation, and an identifier of
58        /// the process and thread that created the message.
59        ///
60        /// A Message can also contain any number of named parameters
61        /// that contain additional information about the event that
62        /// caused the message.
63{
64public:
65        enum Priority
66        {
67                PRIO_FATAL = 1,   /// A fatal error. The application will most likely terminate. This is the highest priority.
68                PRIO_CRITICAL,    /// A critical error. The application might not be able to continue running successfully.
69                PRIO_ERROR,       /// An error. An operation did not complete successfully, but the application as a whole is not affected.
70                PRIO_WARNING,     /// A warning. An operation completed with an unexpected result.
71                PRIO_NOTICE,      /// A notice, which is an information with just a higher priority.
72                PRIO_INFORMATION, /// An informational message, usually denoting the successful completion of an operation.
73                PRIO_DEBUG,       /// A debugging message.
74                PRIO_TRACE        /// A tracing message. This is the lowest priority.
75        };
76       
77        Message();
78                /// Creates an empty Message.
79                /// The thread and process ids are set.
80               
81        Message(const std::string& source, const std::string& text, Priority prio);
82                /// Creates a Message with the given source, text and priority.
83                /// The thread and process ids are set.
84               
85        Message(const Message& msg);
86                /// Creates a Message by copying another one.
87               
88        Message(const Message& msg, const std::string& text);
89                /// Creates a Message by copying all but the text from another message.
90               
91        ~Message();
92                /// Destroys the Message.
93       
94        Message& operator = (const Message& msg);
95                /// Assignment operator.
96               
97        void swap(Message& msg);
98                /// Swaps the message with another one.
99               
100        void setSource(const std::string& src);
101                /// Sets the source of the message.
102               
103        const std::string& getSource() const;
104                /// Returns the source of the message.
105               
106        void setText(const std::string& text);
107                /// Sets the text of the message.
108               
109        const std::string& getText() const;
110                /// Returns the text of the message.
111               
112        void setPriority(Priority prio);
113                /// Sets the priority of the message.
114               
115        Priority getPriority() const;
116                /// Returns the priority of the message.
117       
118        void setTime(const Timestamp& time);
119                /// Sets the time of the message.
120               
121        const Timestamp& getTime() const;
122                /// Returns the time of the message.
123               
124        void setThread(const std::string& thread);
125                /// Sets the thread identifier for the message.
126               
127        const std::string& getThread() const;
128                /// Returns the thread identifier for the message.
129
130        void setTid(long pid);
131                /// Sets the numeric thread identifier for the message.
132               
133        long getTid() const;
134                /// Returns the numeric thread identifier for the message.
135       
136        void setPid(long pid);
137                /// Sets the process identifier for the message.
138               
139        long getPid() const;
140                /// Returns the process identifier for the message.
141               
142        const std::string& operator [] (const std::string& param) const;
143                /// Returns a const reference to the value of the parameter
144                /// with the given name. Throws a NotFoundException if the
145                /// parameter does not exist.
146               
147        std::string& operator [] (const std::string& param);
148                /// Returns a reference to the value of the parameter with the
149                /// given name. This can be used to set the parameter's value.
150                /// If the parameter does not exist, it is created with an
151                /// empty string value.
152
153protected:
154        void init();
155        typedef std::map<std::string, std::string> StringMap;
156
157private:       
158        std::string _source;
159        std::string _text;
160        Priority    _prio;
161        Timestamp   _time;
162        int         _tid;
163        std::string _thread;
164        long        _pid;
165        StringMap*  _pMap;
166};
167
168
169//
170// inlines
171//
172inline const std::string& Message::getSource() const
173{
174        return _source;
175}
176
177
178inline const std::string& Message::getText() const
179{
180        return _text;
181}
182
183
184inline Message::Priority Message::getPriority() const
185{
186        return _prio;
187}
188
189
190inline const Timestamp& Message::getTime() const
191{
192        return _time;
193}
194
195
196inline const std::string& Message::getThread() const
197{
198        return _thread;
199}
200
201
202inline long Message::getTid() const
203{
204        return _tid;
205}
206
207
208inline long Message::getPid() const
209{
210        return _pid;
211}
212
213
214inline void swap(Message& m1, Message& m2)
215{
216        m1.swap(m2);
217}
218
219
220} // namespace Poco
221
222
223#endif // Foundation_Message_INCLUDED
Note: See TracBrowser for help on using the repository browser.