PPL  1.2
Parma_Polyhedra_Library::IO_Operators Namespace Reference

All input/output operators are confined to this namespace. More...

Functions

template<typename D >
std::ostream & operator<< (std::ostream &s, const Ask_Tell< D > &x)
 
template<typename Row >
std::ostream & operator<< (std::ostream &s, const Linear_Expression_Impl< Row > &e)
 
std::ostream & operator<< (std::ostream &os, const PIP_Tree_Node &x)
 
std::ostream & operator<< (std::ostream &os, const PIP_Tree_Node::Artificial_Parameter &x)
 
std::string wrap_string (const std::string &src_string, unsigned indent_depth, unsigned preferred_first_line_length, unsigned preferred_line_length)
 Utility function for the wrapping of lines of text. More...
 

Detailed Description

All input/output operators are confined to this namespace.

This is done so that the library's input/output operators do not interfere with those the user might want to define. In fact, it is highly unlikely that any predefined I/O operator will suit the needs of a client application. On the other hand, those applications for which the PPL I/O operator are enough can easily obtain access to them. For example, a directive like

would suffice for most uses. In more complex situations, such as

const Constraint_System& cs = ...;
copy(cs.begin(), cs.end(),
ostream_iterator<Constraint>(cout, "\n"));

the Parma_Polyhedra_Library namespace must be suitably extended. This can be done as follows:

// Import all the output operators into the main PPL namespace.
using IO_Operators::operator<<;
}

Function Documentation

template<typename D >
std::ostream& Parma_Polyhedra_Library::IO_Operators::operator<< ( std::ostream &  s,
const Ask_Tell< D > &  x 
)
related

Definition at line 252 of file Ask_Tell_templates.hh.

Referenced by Parma_Polyhedra_Library::Grid_Generator::fancy_print(), Parma_Polyhedra_Library::Generator::fancy_print(), and Parma_Polyhedra_Library::Linear_Expression_Impl< Row >::print().

252  {
253  if (x.is_top()) {
254  s << "true";
255  }
256  else if (x.is_bottom()) {
257  s << "false";
258  }
259  else {
260  for (typename Ask_Tell<D>::const_iterator xi = x.begin(),
261  x_end = x.end(); xi != x_end; ++xi)
262  s << "(" << xi->ask() << " -> " << xi->tell() << ")";
263  }
264  return s;
265 }
template<typename Row >
std::ostream& Parma_Polyhedra_Library::IO_Operators::operator<< ( std::ostream &  s,
const Linear_Expression_Impl< Row > &  e 
)
related

Definition at line 285 of file Linear_Expression_Impl_inlines.hh.

285  {
286  e.print(s);
287  return s;
288 }
std::ostream& Parma_Polyhedra_Library::IO_Operators::operator<< ( std::ostream &  os,
const PIP_Tree_Node x 
)
related

Definition at line 902 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::PIP_Tree_Node::print().

902  {
903  x.print(os);
904  return os;
905 }
std::ostream& Parma_Polyhedra_Library::IO_Operators::operator<< ( std::ostream &  os,
const PIP_Tree_Node::Artificial_Parameter x 
)
related

Definition at line 908 of file PIP_Tree.cc.

References Parma_Polyhedra_Library::PIP_Tree_Node::Artificial_Parameter::denominator().

908  {
909  const Linear_Expression& expr = static_cast<const Linear_Expression&>(x);
910  os << "(" << expr << ") div " << x.denominator();
911  return os;
912 }
std::string Parma_Polyhedra_Library::IO_Operators::wrap_string ( const std::string &  src_string,
unsigned  indent_depth,
unsigned  preferred_first_line_length,
unsigned  preferred_line_length 
)

Utility function for the wrapping of lines of text.

Parameters
src_stringThe source string holding the lines to wrap.
indent_depthThe indentation depth.
preferred_first_line_lengthThe preferred length for the first line of text.
preferred_line_lengthThe preferred length for all the lines but the first one.
Returns
The wrapped string.

Definition at line 34 of file wrap_string.cc.

References Parma_Polyhedra_Library::is_space().

37  {
38  const unsigned npos = C_Integer<unsigned>::max;
39  std::string dst_string;
40  const char *src = src_string.c_str();
41  for (unsigned line = 0; ; ++line) {
42  const unsigned line_length = ((line == 0)
43  ? preferred_first_line_length
44  : preferred_line_length);
45  unsigned last_comma = npos;
46  unsigned last_space = npos;
47  unsigned split_pos = npos;
48  unsigned idx;
49  for (idx = 0; idx <= line_length; ++idx) {
50  if (src[idx] == '\0' || src[idx] == '\n') {
51  split_pos = idx;
52  break;
53  }
54  if (src[idx] == ',' && idx < line_length) {
55  last_comma = idx;
56  }
57  if (is_space(src[idx]) && (idx == 0 || !is_space(src[idx-1]))) {
58  last_space = idx;
59  }
60  }
61  if (split_pos == npos) {
62  if (last_comma != npos) {
63  split_pos = last_comma + 1;
64  }
65  else if (last_space != npos) {
66  split_pos = last_space;
67  }
68  else {
69  for ( ; src[idx] != '\0'; ++idx) {
70  if (src[idx] == ',') {
71  ++idx;
72  break;
73  }
74  if (is_space(src[idx])) {
75  break;
76  }
77  }
78  split_pos = idx;
79  }
80  }
81  PPL_ASSERT(split_pos != npos);
82  if (split_pos > 0 && line > 0 && indent_depth > 0) {
83  dst_string.append(indent_depth, ' ');
84  }
85  dst_string.append(src, split_pos);
86  src += split_pos;
87  if (is_space(*src)) {
88  ++src;
89  }
90  while (*src == ' ') {
91  ++src;
92  }
93  if (*src == '\0') {
94  break;
95  }
96  dst_string.push_back('\n');
97  }
98  return dst_string;
99 }
Generator line(const Linear_Expression &e, Representation r=Generator::default_representation)
Shorthand for Generator::line(const Linear_Expression& e, Representation r).
bool is_space(char c)
Returns true if c is any kind of space character.