dlvhex  2.5.0
include/dlvhex2/Printhelpers.h File Reference

Helpers for printing objects to streams. More...

#include <boost/range/iterator_range.hpp>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/optional.hpp>
#include <iostream>
#include <sstream>
#include <set>
#include <vector>
Include dependency graph for Printhelpers.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

class  ostream_printable< T >
 With this class, you can make your own classes ostream-printable. More...
struct  print_container
 Printable object base class. More...
struct  print_stream_container< T >
 Printable object base class. More...
struct  print_method_container
 Printable object base class. More...

Functions

std::ostream & operator<< (std::ostream &o, print_container *c)
 Streaming operator.
template<typename T >
print_containerprint_method (const T &t)
 This can be used if T contains a method "ostream& print(ostream&) const".
print_containerprint_function (const print_method_container::PrintFn &fn)
 This can be used if some third party method is used to print T.
template<typename T >
print_containerprintopt (const boost::optional< T > &t)
 Create a print_container for an object only if it is defined.
template<typename T >
print_containerprintptr (const boost::shared_ptr< T > &t)
 Create a print_container pointer for an object only if it is defined.
template<typename T >
print_containerprintptr (const boost::shared_ptr< const T > &t)
 Create a print_container pointer for an object only if it is defined.
template<typename T >
print_containerprintptr (const T *const t)
 Create a print_container pointer for an object only if it is defined.
template<typename Range >
print_containerprintrange (Range r, const char *open="<", const char *sep=",", const char *close=">")
 Creates a print_container pointer for multiple objects.
template<typename T >
print_containerprintset (const std::set< T > &t, const char *open="{", const char *sep=",", const char *close="}")
 Creates a print_container pointer for multiple objects in set notation.
template<typename T >
print_containerprintvector (const std::vector< T > &t, const char *open="[", const char *sep=",", const char *close="]")
 Creates a print_container pointer for multiple objects in vector notation.

Detailed Description

Helpers for printing objects to streams.

Author:
Peter Schueller <ps@kr.tuwien.ac.at>

Definition in file Printhelpers.h.


Function Documentation

std::ostream& operator<< ( std::ostream &  o,
print_container c 
) [inline]

Streaming operator.

Parameters:
oOutput stream to print to.
cContainer to print using print_container::print.
Returns:
o.

Definition at line 104 of file Printhelpers.h.

References print_container::print().

This can be used if some third party method is used to print T.

E.g. std::ostream& BAR::printFOO(std::ostream& o, const FOO& p) const is printed as ... << print_function(boost::bind(&BAR::printFOO, &bar, _1, foo)) << ... .

Parameters:
fnprint_method_container to create a print_container for.
Returns:
print_container for fn.

Definition at line 164 of file Printhelpers.h.

Referenced by State::changeState(), and OnlineModelBuilder< EvalGraphT >::printEUMBP().

template<typename T >
print_container* print_method ( const T &  t) [inline]

This can be used if T contains a method "ostream& print(ostream&) const".

Parameters:
tObject to create a container for.
Returns:
print_container for t.

Definition at line 150 of file Printhelpers.h.

Referenced by OnlineModelBuilder< EvalGraphT >::advanceOModelForIModel().

template<typename T >
print_container* printopt ( const boost::optional< T > &  t) [inline]

Create a print_container for an object only if it is defined.

Parameters:
tObject to print, can be undefined using boost::optional.
Returns:
print_container for t if defined and a dummy container otherwise.

Definition at line 175 of file Printhelpers.h.

Referenced by OnlineModelBuilder< EvalGraphT >::advanceOModelForIModel(), OnlineModelBuilder< EvalGraphT >::getNextIModel(), OnlineModelBuilder< EvalGraphT >::getNextOModel(), and OnlineModelBuilder< EvalGraphT >::printEUMBPhelper().

template<typename T >
print_container* printptr ( const boost::shared_ptr< const T > &  t) [inline]

Create a print_container pointer for an object only if it is defined.

Parameters:
tObject to print, can be undefined using boost::optional.
Returns:
print_container pointer for t if defined and a dummy container otherwise.

Definition at line 202 of file Printhelpers.h.

template<typename T >
print_container* printptr ( const T *const  t) [inline]

Create a print_container pointer for an object only if it is defined.

Parameters:
tObject to print, can be undefined using boost::optional.
Returns:
print_container pointer for t if defined and a dummy container otherwise.

Definition at line 216 of file Printhelpers.h.

template<typename Range >
print_container* printrange ( Range  r,
const char *  open = "<",
const char *  sep = ",",
const char *  close = ">" 
) [inline]

Creates a print_container pointer for multiple objects.

Parameters:
rObjects to print, can be undefined using boost::optional.
openBegin character.
sepCharacter to be printed between the objects in r.
closeEnd character.
Returns:
print_container pointer for r.

Example: std::cerr << ... << printrange(Range r) << ...;

Definition at line 237 of file Printhelpers.h.

Referenced by BOOST_FIXTURE_TEST_CASE(), EvalHeuristicOldDlvhex::build(), EvalHeuristicEasy::build(), EvalHeuristicGreedy::build(), DLVHEX_NAMESPACE_BEGIN::EvalHeuristicFromHEXSourcecode::build(), ComponentGraph::calculateComponents(), ComponentGraph::collapseComponents(), ComponentGraph::computeCollapsedComponentInfos(), sem< StrongNegationParserModuleSemantics::stronglyNegatedPrefixAtom >::createAtom(), sem< HexGrammarSemantics::classicalAtomFromPrefix >::createAtom(), DependencyGraph::createAuxiliaryRuleIfRequired(), DumpingEvalGraphBuilder::createEvalUnit(), EvalGraphBuilder::createEvalUnit(), DependencyGraph::createHeadBodyUnifyingDependencies(), BaseModelGenerator::evaluateExternalAtomQuery(), BaseModelGenerator::IntegrateExternalAnswerIntoInterpretationCB::output(), DLVHEX_NAMESPACE_BEGIN::EvalHeuristicFromHEXSourcecode::preprocessComponents(), ComponentGraph::ComponentInfo::print(), ComfortInterpretation::print(), printset(), printvector(), ProgramCtx::processPluginOptions(), TestPluginAtomReach::retrieve(), ComfortPluginAtom::retrieve(), TestSetMinusAtom::retrieve(), internal::transitivePredecessorComponents(), internalgreedy::transitivePredecessorComponents(), and ComponentGraph::writeGraphVizComponentLabel().

template<typename T >
print_container* printset ( const std::set< T > &  t,
const char *  open = "{",
const char *  sep = ",",
const char *  close = "}" 
) [inline]

Creates a print_container pointer for multiple objects in set notation.

Parameters:
tObjects to print, can be undefined using boost::optional.
openBegin character.
sepCharacter to be printed between the objects in r.
closeEnd character.
Returns:
print_container pointer for r.

Example: std::cerr << ... << printset(std::set<T>) << ...;

Definition at line 266 of file Printhelpers.h.

References printrange().

Referenced by DLVHEX_NAMESPACE_BEGIN::EvalHeuristicFromHEXSourcecode::build(), FLPModelGeneratorFactoryBase::createFLPRules(), CAUAlgorithms::AncestryMarkingVisitor< Graph >::examine_edge(), CAUAlgorithms::logAPM(), sem< QueryParserModuleSemantics::queryBody >::operator()(), ComfortPluginAtom::retrieve(), PredicateMask::updateMask(), and verifyModels().

template<typename T >
print_container* printvector ( const std::vector< T > &  t,
const char *  open = "[",
const char *  sep = ",",
const char *  close = "]" 
) [inline]

Creates a print_container pointer for multiple objects in vector notation.

Parameters:
tObjects to print, can be undefined using boost::optional.
openBegin character.
sepCharacter to be printed between the objects in r.
closeEnd character.
Returns:
print_container pointer for r.

Example: std::cerr << ... << printvector(std::vector<T>) << ...;

Definition at line 284 of file Printhelpers.h.

References printrange().

Referenced by DependencyGraph::createAuxiliaryRuleIfRequired(), DependencyGraph::createHeadBodyUnifyingDependencies(), DependencyGraph::createHeadHeadUnifyingDependencies(), evalheur::executeBuildCommands(), OrdinaryAtom::existsHomomorphism(), ProcessBuf::open(), OrdinaryAtom::print(), Rule::print(), BuiltinAtom::print(), AggregateAtom::print(), Registry::print(), ExternalAtom::print(), ModuleAtom::print(), OrdinaryAtom::unifiesWith(), and ComfortAtom::unifiesWith().