1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
// Cyphesis Online RPG Server and AI Engine
// Copyright (C) 2008 Alistair Riddoch
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "Monitors.h"
#include "Variable.h"
#include <iostream>
using Atlas::Message::Element;
using Atlas::Message::MapType;
Monitors * Monitors::m_instance = NULL;
Monitors::Monitors()
{
}
Monitors::~Monitors()
{
MonitorDict::const_iterator I = m_variableMonitors.begin();
MonitorDict::const_iterator Iend = m_variableMonitors.end();
for (; I != Iend; ++I) {
delete I->second;
}
}
Monitors * Monitors::instance()
{
if (m_instance == NULL) {
m_instance = new Monitors();
}
return m_instance;
}
void Monitors::cleanup()
{
delete m_instance;
m_instance = 0;
}
void Monitors::insert(const std::string & key, const Element & val)
{
m_pairs[key] = val;
}
void Monitors::watch(const::std::string & name, VariableBase * monitor)
{
m_variableMonitors[name] = monitor;
}
static std::ostream & operator<<(std::ostream & s, const Element & e)
{
switch (e.getType()) {
case Atlas::Message::Element::TYPE_INT:
s << e.Int();
break;
case Atlas::Message::Element::TYPE_FLOAT:
s << e.Float();
break;
case Atlas::Message::Element::TYPE_STRING:
s << e.String();
break;
default:
break;
};
return s;
}
void Monitors::send(std::ostream & io)
{
MapType::const_iterator I = m_pairs.begin();
MapType::const_iterator Iend = m_pairs.end();
for (; I != Iend; ++I) {
io << I->first << " " << I->second << std::endl;
}
MonitorDict::const_iterator J = m_variableMonitors.begin();
MonitorDict::const_iterator Jend = m_variableMonitors.end();
for (; J != Jend; ++J) {
io << J->first << " ";
J->second->send(io);
io << std::endl;
}
}
|