2006-06-21 14:28:17 +00:00
|
|
|
// Cyphesis Online RPG Server and AI Engine
|
|
|
|
|
// Copyright (C) 2006 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
|
|
|
|
|
|
2006-10-26 00:48:00 +00:00
|
|
|
|
2006-06-21 14:28:17 +00:00
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
|
|
#include <Atlas/Message/Element.h>
|
2015-04-06 00:56:06 +02:00
|
|
|
#include <Atlas/PresentationBridge.h>
|
|
|
|
|
#include <Atlas/Objects/Root.h>
|
|
|
|
|
#include <Atlas/Objects/Encoder.h>
|
|
|
|
|
#include <Atlas/Objects/SmartPtr.h>
|
|
|
|
|
#include <Atlas/Objects/Operation.h>
|
2015-09-26 19:03:23 +02:00
|
|
|
#include <Atlas/Objects/Entity.h>
|
2006-06-21 14:28:17 +00:00
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
using Atlas::Message::Element;
|
|
|
|
|
using Atlas::Message::MapType;
|
|
|
|
|
using Atlas::Message::ListType;
|
|
|
|
|
|
2017-05-27 20:27:48 +02:00
|
|
|
void output_element(std::ostream & out, const Element & item, size_t depth)
|
2006-06-21 14:28:17 +00:00
|
|
|
{
|
|
|
|
|
switch (item.getType()) {
|
|
|
|
|
case Element::TYPE_INT:
|
2012-03-24 13:05:17 +00:00
|
|
|
out << item.Int();
|
2006-06-21 14:28:17 +00:00
|
|
|
break;
|
|
|
|
|
case Element::TYPE_FLOAT:
|
2012-03-24 13:05:17 +00:00
|
|
|
out << item.Float();
|
2006-06-21 14:28:17 +00:00
|
|
|
break;
|
|
|
|
|
case Element::TYPE_STRING:
|
2012-03-24 13:05:17 +00:00
|
|
|
out << "\"" << item.String() << "\"";
|
2006-06-21 14:28:17 +00:00
|
|
|
break;
|
|
|
|
|
case Element::TYPE_LIST:
|
|
|
|
|
{
|
2012-03-24 13:05:17 +00:00
|
|
|
out << "[ ";
|
2006-06-21 14:28:17 +00:00
|
|
|
ListType::const_iterator I = item.List().begin();
|
|
|
|
|
ListType::const_iterator Iend = item.List().end();
|
|
|
|
|
for(; I != Iend; ++I) {
|
2012-05-29 12:19:05 +01:00
|
|
|
output_element(out, *I, depth + 1);
|
2012-03-24 13:05:17 +00:00
|
|
|
out << " ";
|
2006-06-21 14:28:17 +00:00
|
|
|
}
|
2012-03-24 13:05:17 +00:00
|
|
|
out << "]";
|
2006-06-21 14:28:17 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case Element::TYPE_MAP:
|
|
|
|
|
{
|
2012-03-24 13:48:30 +00:00
|
|
|
out << "{" << std::endl;
|
2006-06-21 14:28:17 +00:00
|
|
|
MapType::const_iterator I = item.Map().begin();
|
|
|
|
|
MapType::const_iterator Iend = item.Map().end();
|
|
|
|
|
for(; I != Iend; ++I) {
|
2012-03-24 13:05:17 +00:00
|
|
|
out << std::string((depth + 1) * 4, ' ') << I->first << ": ";
|
2012-05-29 12:19:05 +01:00
|
|
|
output_element(out, I->second, depth + 1);
|
2012-03-24 13:05:17 +00:00
|
|
|
out << std::endl;
|
2006-06-21 14:28:17 +00:00
|
|
|
}
|
2012-03-24 13:05:17 +00:00
|
|
|
out << std::string(depth * 4, ' ') << "}";
|
|
|
|
|
out << std::endl;
|
2006-06-21 14:28:17 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2012-03-24 13:05:17 +00:00
|
|
|
out << "(\?\?\?)";
|
2006-06-21 14:28:17 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-09-27 22:40:15 +02:00
|
|
|
|
|
|
|
|
template <>
|
|
|
|
|
void debug_dump(const Atlas::Objects::Operation::RootOperation & t, std::ostream & os)
|
|
|
|
|
{
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
Atlas::PresentationBridge bridge(ss);
|
|
|
|
|
Atlas::Objects::ObjectsEncoder encoder(bridge);
|
|
|
|
|
encoder.streamObjectsMessage(t);
|
|
|
|
|
os << ss.str();
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-06 00:56:06 +02:00
|
|
|
template <>
|
2015-09-26 19:03:23 +02:00
|
|
|
void debug_dump(const Atlas::Objects::Root & t, std::ostream & os)
|
2015-04-06 00:56:06 +02:00
|
|
|
{
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
Atlas::PresentationBridge bridge(ss);
|
|
|
|
|
Atlas::Objects::ObjectsEncoder encoder(bridge);
|
|
|
|
|
encoder.streamObjectsMessage(t);
|
|
|
|
|
os << ss.str();
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-26 19:03:23 +02:00
|
|
|
template <>
|
|
|
|
|
void debug_dump(const Atlas::Objects::Entity::Anonymous & t, std::ostream & os)
|
|
|
|
|
{
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
Atlas::PresentationBridge bridge(ss);
|
|
|
|
|
Atlas::Objects::ObjectsEncoder encoder(bridge);
|
|
|
|
|
encoder.streamObjectsMessage(t);
|
|
|
|
|
os << ss.str();
|
|
|
|
|
}
|
2006-06-21 14:28:17 +00:00
|
|
|
|
2012-03-24 13:12:56 +00:00
|
|
|
template <typename T>
|
2012-09-08 12:52:58 +01:00
|
|
|
void debug_dump(const T & t, std::ostream & os)
|
2006-06-21 14:28:17 +00:00
|
|
|
{
|
2012-09-08 12:52:58 +01:00
|
|
|
output_element(os, t, 0);
|
2006-06-21 14:28:17 +00:00
|
|
|
}
|
2007-07-17 02:26:43 +00:00
|
|
|
|
2012-03-24 13:48:30 +00:00
|
|
|
template <typename T>
|
|
|
|
|
std::string debug_tostring(const T & t)
|
|
|
|
|
{
|
|
|
|
|
std::stringstream out(std::ios::out);
|
2012-05-29 12:19:05 +01:00
|
|
|
output_element(out, t, 0);
|
2012-03-24 13:48:30 +00:00
|
|
|
return out.str();
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-24 13:12:56 +00:00
|
|
|
template
|
2012-09-08 12:52:58 +01:00
|
|
|
void debug_dump<MapType>(const MapType & map, std::ostream & os);
|
2009-12-30 15:08:49 +00:00
|
|
|
|
2012-03-24 13:12:56 +00:00
|
|
|
template
|
2012-09-08 12:52:58 +01:00
|
|
|
void debug_dump<ListType>(const ListType & list, std::ostream & os);
|
2012-03-24 13:12:56 +00:00
|
|
|
|
|
|
|
|
template
|
2012-09-08 12:52:58 +01:00
|
|
|
void debug_dump<Element>(const Element & e, std::ostream & os);
|
2012-03-24 13:48:30 +00:00
|
|
|
|
|
|
|
|
template
|
|
|
|
|
std::string debug_tostring<MapType>(const MapType & map);
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
|
std::string debug_tostring<ListType>(const ListType & list);
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
|
std::string debug_tostring<Element>(const Element & e);
|
|
|
|
|
|