📄 message.h
字号:
//
// Message.h
//
// $Id: //poco/Main/Foundation/include/Foundation/Message.h#5 $
//
// Definition of the Message class.
//
// Copyright (c) 2004, Guenter Obiltschnig/Applied Informatics.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Redistributions in any form must be accompanied by information on
// how to obtain complete source code for this software and any
// accompanying software that uses this software. The source code
// must either be included in the distribution or be available for no
// more than the cost of distribution plus a nominal fee, and must be
// freely redistributable under reasonable conditions. For an
// executable file, complete source code means the source code for all
// modules it contains. It does not include source code for modules or
// files that typically accompany the major components of the operating
// system on which the executable file runs.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
#ifndef Foundation_Message_INCLUDED
#define Foundation_Message_INCLUDED
#ifndef Foundation_Foundation_INCLUDED
#include "Foundation/Foundation.h"
#endif
#ifndef Foundation_Timestamp_INCLUDED
#include "Foundation/Timestamp.h"
#endif
#ifndef STD_MAP_INCLUDED
#include <map>
#define STD_MAP_INCLUDED
#endif
Foundation_BEGIN
class Foundation_API Message
/// This class represents a log message that is sent through a
/// chain of log channels.
///
/// A Message contains a priority denoting the severity of the
/// message, a source describing its origin, a text describing
/// its meaning, the time of its creation, and an identifier of
/// the process and thread that created the message.
///
/// A Message can also contain any number of named parameters
/// that contain additional information about the event that
/// caused the message.
{
public:
enum Priority
{
PRIO_FATAL = 1, /// A fatal error. The application will most likely terminate. This is the highest priority.
PRIO_CRITICAL, /// A critical error. The application might not be able to continue running successfully.
PRIO_ERROR, /// An error. An operation did not complete successfully, but the application as a whole is not affected.
PRIO_WARNING, /// A warning. An operation completed with an unexpected result.
PRIO_NOTICE, /// A notice, which is an information with just a higher priority.
PRIO_INFORMATION, /// An informational message, usually denoting the successful completion of an operation.
PRIO_DEBUG, /// A debugging message.
PRIO_TRACE /// A tracing message. This is the lowest priority.
};
Message();
/// Creates an empty Message.
Message(const std::string& source, const std::string& text, Priority prio);
/// Creates a Message with the given source, text and priority.
Message(const Message& msg);
/// Creates a Message by copying another one.
Message(const Message& msg, const std::string& text);
/// Creates a Message by copying all but the text from another message.
~Message();
/// Destroys the Message.
Message& operator = (const Message& msg);
/// Assignment operator.
void setSource(const std::string& src);
/// Sets the source of the message.
const std::string& getSource() const;
/// Returns the source of the message.
void setText(const std::string& text);
/// Sets the text of the message.
const std::string& getText() const;
/// Returns the text of the message.
void setPriority(Priority prio);
/// Sets the priority of the message.
Priority getPriority() const;
/// Returns the priority of the message.
void setTime(const Timestamp& time);
/// Sets the time of the message.
const Timestamp& getTime() const;
/// Returns the time of the message.
void setThread(const std::string& thread);
/// Sets the thread identifier for the message.
const std::string& getThread() const;
/// Returns the thread identifier for the message.
void setPid(long pid);
/// Sets the process identifier for the message.
long getPid() const;
/// Returns the process identifier for the message.
const std::string& operator [] (const std::string& param) const;
/// Returns a const reference to the value of the parameter
/// with the given name. Throws a NotFoundException if the
/// parameter does not exist.
std::string& operator [] (const std::string& param);
/// Returns a reference to the value of the parameter with the
/// given name. This can be used to set the parameter's value.
/// If the parameter does not exist, it is created with an
/// empty string value.
protected:
typedef std::map<std::string, std::string> StringMap;
private:
std::string _source;
std::string _text;
Priority _prio;
Timestamp _time;
std::string _thread;
long _pid;
StringMap* _pMap;
};
//
// inlines
//
inline const std::string& Message::getSource() const
{
return _source;
}
inline const std::string& Message::getText() const
{
return _text;
}
inline Message::Priority Message::getPriority() const
{
return _prio;
}
Foundation_END
#endif // Foundation_Message_INCLUDED
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -