Panda3D

interrogate_datafile.I

00001 // Filename: interrogate_datafile.I
00002 // Created by:  drose (09Aug00)
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 ////////////////////////////////////////////////////////////////////
00017 //     Function: idf_output_vector
00018 //  Description: Writes the indicated vector to the output file.  Each
00019 //               component is written using its normal ostream output
00020 //               operator.
00021 ////////////////////////////////////////////////////////////////////
00022 template<class Element>
00023 void
00024 idf_output_vector(ostream &out, const vector<Element> &vec) {
00025   out << vec.size() << " ";
00026   TYPENAME vector<Element>::const_iterator vi;
00027   for (vi = vec.begin(); vi != vec.end(); ++vi) {
00028     out << (*vi) << " ";
00029   }
00030 }
00031 
00032 
00033 ////////////////////////////////////////////////////////////////////
00034 //     Function: idf_input_vector
00035 //  Description: Reads the given vector from the input file, as
00036 //               previously written by output_string().  Each
00037 //               component is read using its normal istream input
00038 //               operator.
00039 ////////////////////////////////////////////////////////////////////
00040 template<class Element>
00041 void
00042 idf_input_vector(istream &in, vector<Element> &vec) {
00043   int length;
00044   in >> length;
00045   if (in.fail()) {
00046     return;
00047   }
00048 
00049   vec.clear();
00050   vec.reserve(length);
00051   while (length > 0) {
00052     Element elem;
00053     in >> elem;
00054     vec.push_back(elem);
00055     length--;
00056   }
00057 }
 All Classes Functions Variables Enumerations