Panda3D
 All Classes Functions Variables Enumerations
interrogate_datafile.I
1 // Filename: interrogate_datafile.I
2 // Created by: drose (09Aug00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: idf_output_vector
18 // Description: Writes the indicated vector to the output file. Each
19 // component is written using its normal ostream output
20 // operator.
21 ////////////////////////////////////////////////////////////////////
22 template<class Element>
23 void
24 idf_output_vector(ostream &out, const vector<Element> &vec) {
25  out << vec.size() << " ";
26  TYPENAME vector<Element>::const_iterator vi;
27  for (vi = vec.begin(); vi != vec.end(); ++vi) {
28  out << (*vi) << " ";
29  }
30 }
31 
32 
33 ////////////////////////////////////////////////////////////////////
34 // Function: idf_input_vector
35 // Description: Reads the given vector from the input file, as
36 // previously written by output_string(). Each
37 // component is read using its normal istream input
38 // operator.
39 ////////////////////////////////////////////////////////////////////
40 template<class Element>
41 void
42 idf_input_vector(istream &in, vector<Element> &vec) {
43  int length;
44  in >> length;
45  if (in.fail()) {
46  return;
47  }
48 
49  vec.clear();
50  vec.reserve(length);
51  while (length > 0) {
52  Element elem;
53  in >> elem;
54  vec.push_back(elem);
55  length--;
56  }
57 }