source: XMLIO_V2/external/src/POCO/Foundation.save/Message.cpp @ 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: 3.8 KB
Line 
1//
2// Message.cpp
3//
4// $Id: //poco/1.3/Foundation/src/Message.cpp#4 $
5//
6// Library: Foundation
7// Package: Logging
8// Module:  Message
9//
10// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
11// and Contributors.
12//
13// Permission is hereby granted, free of charge, to any person or organization
14// obtaining a copy of the software and accompanying documentation covered by
15// this license (the "Software") to use, reproduce, display, distribute,
16// execute, and transmit the Software, and to prepare derivative works of the
17// Software, and to permit third-parties to whom the Software is furnished to
18// do so, all subject to the following:
19//
20// The copyright notices in the Software and this entire statement, including
21// the above license grant, this restriction and the following disclaimer,
22// must be included in all copies of the Software, in whole or in part, and
23// all derivative works of the Software, unless such copies or derivative
24// works are solely in the form of machine-executable object code generated by
25// a source language processor.
26//
27// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
30// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
31// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
32// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
33// DEALINGS IN THE SOFTWARE.
34//
35
36
37#include "Poco/Message.h"
38#include "Poco/Exception.h"
39#include "Poco/Process.h"
40#include "Poco/Thread.h"
41#include <algorithm>
42
43
44namespace Poco {
45
46
47Message::Message(): 
48        _prio(PRIO_FATAL), 
49        _tid(0), 
50        _pid(0),
51        _pMap(0) 
52{
53        init();
54}
55
56
57Message::Message(const std::string& source, const std::string& text, Priority prio): 
58        _source(source), 
59        _text(text), 
60        _prio(prio), 
61        _tid(0),
62        _pid(0),
63        _pMap(0) 
64{
65        init();
66}
67
68
69Message::Message(const Message& msg):
70        _source(msg._source),
71        _text(msg._text),
72        _prio(msg._prio),
73        _time(msg._time),
74        _tid(msg._tid),
75        _thread(msg._thread),
76        _pid(msg._pid)
77{
78        if (msg._pMap)
79                _pMap = new StringMap(*msg._pMap);
80        else
81                _pMap = 0;
82}
83
84
85Message::Message(const Message& msg, const std::string& text):
86        _source(msg._source),
87        _text(text),
88        _prio(msg._prio),
89        _time(msg._time),
90        _tid(msg._tid),
91        _thread(msg._thread),
92        _pid(msg._pid)
93{
94        if (msg._pMap)
95                _pMap = new StringMap(*msg._pMap);
96        else
97                _pMap = 0;
98}
99
100
101Message::~Message()
102{
103        delete _pMap;
104}
105
106
107void Message::init()
108{
109        _pid = Process::id();
110        Thread* pThread = Thread::current();
111        if (pThread)
112        {
113                _tid    = pThread->id();
114                _thread = pThread->name();
115        }
116}
117
118
119Message& Message::operator = (const Message& msg)
120{
121        if (&msg != this)
122        {
123                Message tmp(msg);
124                swap(tmp);
125        }
126        return *this;
127}
128
129
130void Message::swap(Message& msg)
131{
132        using std::swap;
133        swap(_source, msg._source);
134        swap(_text, msg._text);
135        swap(_prio, msg._prio);
136        swap(_time, msg._time);
137        swap(_tid, msg._tid);
138        swap(_thread, msg._thread);
139        swap(_pid, msg._pid);
140        swap(_pMap, msg._pMap);
141}
142
143
144void Message::setSource(const std::string& src)
145{
146        _source = src;
147}
148
149
150void Message::setText(const std::string& text)
151{
152        _text = text;
153}
154
155
156void Message::setPriority(Priority prio)
157{
158        _prio = prio;
159}
160
161
162void Message::setTime(const Timestamp& t)
163{
164        _time = t;
165}
166
167
168void Message::setThread(const std::string& thread)
169{
170        _thread = thread;
171}
172
173
174void Message::setTid(long tid)
175{
176        _tid = tid;
177}
178
179
180void Message::setPid(long pid)
181{
182        _pid = pid;
183}
184
185
186const std::string& Message::operator [] (const std::string& param) const
187{
188        if (_pMap)
189                return (*_pMap)[param];
190        else
191                throw NotFoundException();
192}
193
194
195std::string& Message::operator [] (const std::string& param)
196{
197        if (!_pMap)
198                _pMap = new StringMap;
199        return (*_pMap)[param];
200}
201
202
203} // namespace Poco
Note: See TracBrowser for help on using the repository browser.