/******************************************************************************* * * * libretroshare: retroshare core library * * * * Copyright (C) 2018 Gioacchino Mazzurco * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * * published by the Free Software Foundation, either version 3 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 Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program. If not, see . * * * *******************************************************************************/ #include #include #include #include "util/rsjson.h" inline int getJsonManipulatorStatePosition() { static int p = std::ios_base::xalloc(); return p; } std::ostream& compactJSON(std::ostream &out) { out.iword(getJsonManipulatorStatePosition()) = 1; return out; } std::ostream& prettyJSON(std::ostream &out) { out.iword(getJsonManipulatorStatePosition()) = 0; return out; } std::ostream& operator<<(std::ostream &out, const RsJson &jDoc) { rapidjson::StringBuffer buffer; buffer.Clear(); if(out.iword(getJsonManipulatorStatePosition())) { rapidjson::Writer writer(buffer); jDoc.Accept(writer); } else { rapidjson::PrettyWriter writer(buffer); jDoc.Accept(writer); } return out << buffer.GetString(); } std::ostream& operator<<(std::ostream &out, const rapidjson::Value& jValue) { rapidjson::StringBuffer buffer; buffer.Clear(); if(out.iword(getJsonManipulatorStatePosition())) { rapidjson::Writer writer(buffer); jValue.Accept(writer); } else { rapidjson::PrettyWriter writer(buffer); jValue.Accept(writer); } return out << buffer.GetString(); }