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