dlvhex  2.5.0
include/dlvhex2/Printer.h
Go to the documentation of this file.
00001 /* dlvhex -- Answer-Set Programming with external interfaces.
00002  * Copyright (C) 2005-2007 Roman Schindlauer
00003  * Copyright (C) 2006-2015 Thomas Krennwallner
00004  * Copyright (C) 2009-2016 Peter Schüller
00005  * Copyright (C) 2011-2016 Christoph Redl
00006  * Copyright (C) 2015-2016 Tobias Kaminski
00007  * Copyright (C) 2015-2016 Antonius Weinzierl
00008  *
00009  * This file is part of dlvhex.
00010  *
00011  * dlvhex is free software; you can redistribute it and/or modify it
00012  * under the terms of the GNU Lesser General Public License as
00013  * published by the Free Software Foundation; either version 2.1 of
00014  * the License, or (at your option) any later version.
00015  *
00016  * dlvhex is distributed in the hope that it will be useful, but
00017  * WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  * Lesser General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Lesser General Public
00022  * License along with dlvhex; if not, write to the Free Software
00023  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00024  * 02110-1301 USA.
00025  */
00026 
00035 #ifndef PRINTER_HPP_INCLUDED_14012011
00036 #define PRINTER_HPP_INCLUDED_14012011
00037 
00038 #include "dlvhex2/PlatformDefinitions.h"
00039 #include "dlvhex2/fwd.h"
00040 #include "dlvhex2/ID.h"
00041 
00042 #include <vector>
00043 #include <string>
00044 #include <iosfwd>
00045 
00046 DLVHEX_NAMESPACE_BEGIN
00047 
00049 class DLVHEX_EXPORT Printer
00050 {
00051     protected:
00053         std::ostream& out;
00055         Registry* registry;
00056 
00057     public:
00061         Printer(std::ostream& out, Registry* registry):
00062         out(out), registry(registry) {}
00066         Printer(std::ostream& out, RegistryPtr registry):
00067         out(out), registry(registry.get()) {}
00069         virtual ~Printer() {}
00073         void printmany(const Tuple& ids, const std::string& separator);
00076         virtual void print(ID id) = 0;
00077 };
00078 
00080 class DLVHEX_EXPORT RawPrinter:
00081 public Printer
00082 {
00083     private:
00084         std::string removeModulePrefix(const std::string& text);
00085     public:
00089         RawPrinter(std::ostream& out, Registry* registry):
00090         Printer(out, registry) {}
00094         RawPrinter(std::ostream& out, RegistryPtr registry):
00095         Printer(out, registry) {}
00096         virtual void print(ID id);
00099         void printWithoutPrefix(ID id);
00104         static std::string toString(RegistryPtr reg, ID id);
00105 };
00106 
00111 template<typename PrinterT>
00112 std::string printToString(ID id, RegistryPtr reg)
00113 {
00114     std::ostringstream s;
00115     PrinterT p(s, reg);
00116     p.print(id);
00117     return s.str();
00118 }
00119 
00120 
00126 template<typename PrinterT>
00127 std::string printManyToString(
00128 const Tuple& ids, const std::string& separator, RegistryPtr reg)
00129 {
00130     std::ostringstream s;
00131     PrinterT p(s, reg);
00132     p.printmany(ids, separator);
00133     return s.str();
00134 }
00135 
00136 
00137 DLVHEX_NAMESPACE_END
00138 #endif                           // PRINTER_HPP_INCLUDED_14012011
00139 
00140 // vim:expandtab:ts=4:sw=4:
00141 // mode: C++
00142 // End: