interrogate_datafile.I 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Filename: interrogate_datafile.I
  2. // Created by: drose (09Aug00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://www.panda3d.org/license.txt .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. ////////////////////////////////////////////////////////////////////
  19. // Function: idf_output_vector
  20. // Description: Writes the indicated vector to the output file. Each
  21. // component is written using its normal ostream output
  22. // operator.
  23. ////////////////////////////////////////////////////////////////////
  24. template<class Element>
  25. void
  26. idf_output_vector(ostream &out, const vector<Element> &vec) {
  27. out << vec.size() << " ";
  28. vector<Element>::const_iterator vi;
  29. for (vi = vec.begin(); vi != vec.end(); ++vi) {
  30. out << (*vi) << " ";
  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. vec.clear();
  49. vec.reserve(length);
  50. while (length > 0) {
  51. Element elem;
  52. in >> elem;
  53. vec.push_back(elem);
  54. length--;
  55. }
  56. }