Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/egg/eggMiscFuncs.cxx

Go to the documentation of this file.
00001 // Filename: eggMiscFuncs.cxx
00002 // Created by:  drose (16Jan99)
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 #include "pandabase.h"
00020 #include "eggMiscFuncs.h"
00021 #include "indent.h"
00022 
00023 #include <ctype.h>
00024 
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //     Function: enquote_string
00028 //  Description: Writes the string to the indicated output stream.  If
00029 //               the string contains any characters special to egg,
00030 //               writes quotation marks around it.  If always_quote is
00031 //               true, writes quotation marks regardless.
00032 ////////////////////////////////////////////////////////////////////
00033 ostream &
00034 enquote_string(ostream &out, const string &str, int indent_level,
00035                bool always_quote) {
00036   indent(out, indent_level);
00037 
00038   // First, see if we need to enquote it.
00039   bool legal = !always_quote;
00040   string::const_iterator p;
00041   for (p = str.begin(); p != str.end() && legal; ++p) {
00042     legal = (isalnum(*p) || *p=='-' || *p=='_' || *p=='#' || *p=='.');
00043   }
00044 
00045   if (legal) {
00046     out << str;
00047 
00048   } else {
00049     out << '"';
00050 
00051     for (p = str.begin(); p != str.end(); ++p) {
00052       switch (*p) {
00053       case '"':
00054         // Can't output nested quote marks at all.
00055         out << "'";
00056         break;
00057 
00058       case '\n':
00059         // A newline necessitates ending the quotes, newlining, and
00060         // beginning again.
00061         out << "\"\n";
00062         indent(out, indent_level) << '"';
00063         break;
00064 
00065       default:
00066         out << *p;
00067       }
00068     }
00069     out << '"';
00070   }
00071 
00072   return out;
00073 }
00074 
00075 
00076 ////////////////////////////////////////////////////////////////////
00077 //     Function: write_transform
00078 //  Description: A helper function to write out a 3x3 transform
00079 //               matrix.
00080 ////////////////////////////////////////////////////////////////////
00081 void
00082 write_transform(ostream &out, const LMatrix3d &mat, int indent_level) {
00083   indent(out, indent_level) << "<Transform> {\n";
00084 
00085   indent(out, indent_level+2) << "<Matrix3> {\n";
00086 
00087   for (int r = 0; r < 3; r++) {
00088     indent(out, indent_level+3);
00089     for (int c = 0; c < 3; c++) {
00090       out << " " << mat(r, c);
00091     }
00092     out << "\n";
00093   }
00094   indent(out, indent_level+2) << "}\n";
00095   indent(out, indent_level) << "}\n";
00096 }

Generated on Fri May 2 00:37:42 2003 for Panda by doxygen1.3