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