Panda3D
indent.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file indent.I
10  * @author drose
11  * @date 1999-02-15
12  */
13 
14 /**
15  * Writes a list of things to the indicated output stream, with a space
16  * separating each item. One or more lines will be written, and the lines
17  * will automatically be broken such that no line exceeds max_col columns if
18  * possible.
19  */
20 template<class InputIterator>
21 void
22 write_long_list(std::ostream &out, int indent_level,
23  InputIterator first, InputIterator last,
24  std::string first_prefix, std::string later_prefix,
25  int max_col) {
26  if (later_prefix.empty()) {
27  later_prefix = first_prefix;
28  }
29 
30  if (first != last) {
31  // We have to use an intermediate strstream object so we can count the
32  // number of characters the item will have when it is output.
33  std::ostringstream item;
34  item << *first;
35  std::string str = item.str();
36 
37  indent(out, indent_level) << first_prefix << str;
38  int col = indent_level + (int)(first_prefix.length() + str.length());
39 
40  ++first;
41 
42  while (first != last) {
43  std::ostringstream item;
44  item << *first;
45  std::string str = item.str();
46 
47  col += 1 + str.length();
48  if (col > max_col) {
49  out << "\n";
50  indent(out, indent_level) << later_prefix << str;
51  col = indent_level + (int)(later_prefix.length() + str.length());
52 
53  } else {
54  out << " " << str;
55  }
56 
57  ++first;
58  }
59  out << "\n";
60  }
61 }
void write_long_list(std::ostream &out, int indent_level, InputIterator first, InputIterator last, std::string first_prefix, std::string later_prefix, int max_col)
Writes a list of things to the indicated output stream, with a space separating each item.
Definition: indent.I:22
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20