Panda3D
 All Classes Functions Variables Enumerations
indent.I
00001 // Filename: indent.I
00002 // Created by:  drose (15Feb99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 ////////////////////////////////////////////////////////////////////
00016 //     Function: write_long_list
00017 //  Description: Writes a list of things to the indicated output
00018 //               stream, with a space separating each item.  One or
00019 //               more lines will be written, and the lines will
00020 //               automatically be broken such that no line exceeds
00021 //               max_col columns if possible.
00022 ////////////////////////////////////////////////////////////////////
00023 template<class InputIterator>
00024 void
00025 write_long_list(ostream &out, int indent_level,
00026                 InputIterator first, InputIterator last,
00027                 string first_prefix, string later_prefix,
00028                 int max_col) {
00029   if (later_prefix.empty()) {
00030     later_prefix = first_prefix;
00031   }
00032 
00033   if (first != last) {
00034     // We have to use an intermediate strstream object so we can
00035     // count the number of characters the item will have when it is
00036     // output.
00037     ostringstream item;
00038     item << *first;
00039     string str = item.str();
00040 
00041     indent(out, indent_level) << first_prefix << str;
00042     int col = indent_level + first_prefix.length() + str.length();
00043 
00044     ++first;
00045 
00046     while (first != last) {
00047       ostringstream item;
00048       item << *first;
00049       string str = item.str();
00050 
00051       col += 1 + str.length();
00052       if (col > max_col) {
00053         out << "\n";
00054         indent(out, indent_level) << later_prefix << str;
00055         col = indent_level + later_prefix.length() + str.length();
00056 
00057       } else {
00058         out << " " << str;
00059       }
00060 
00061       ++first;
00062     }
00063     out << "\n";
00064   }
00065 }
 All Classes Functions Variables Enumerations