stream_loader.h

Go to the documentation of this file.
00001 
00006 /* Copyright © 2009 James Legg.
00007     This program is free software: you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation, either version 3 of the License, or
00010     (at your option) any later version.
00011 */
00012 #ifndef LIBTRACK_STREAM_LOADER_H_
00013 #define LIBTRACK_STREAM_LOADER_H_
00014 
00015 #include <vector>
00016 #include <istream>
00017 
00018 #include  "Drawable.h"
00019 
00020 #include <boost/shared_ptr.hpp>
00021 
00022 #include <LinearMath/btTransform.h>
00023 
00024 #include <Debug.h>
00025 
00039 template <class T>
00040 void fill_vector_from_stream(std::vector<boost::shared_ptr<T> > & vector,
00041                              std::istream & stream)
00042 {
00043     std::size_t number_of_elements;
00044     stream >> number_of_elements;
00045     DEBUG_MESSAGE("Reading vector of " << number_of_elements << " starting at " << stream.tellg());
00046     vector.reserve(number_of_elements);
00047     DEBUG_MESSAGE("Reading elements");
00048     for (unsigned int i = 0; i < number_of_elements; i++)
00049     {
00050         boost::shared_ptr<T> element(new T(stream));
00051         DEBUG_MESSAGE("Read element " << i << ", now at " << stream.tellg());
00052         vector.push_back(element);
00053     }
00054     DEBUG_MESSAGE("Finished reading vector");
00055 }
00056 
00070 template <class T, class S>
00071 void fill_vector_from_stream(std::vector<boost::shared_ptr<T> > & vector,
00072                              std::istream & stream,
00073                              S & additional)
00074 {
00075     std::size_t number_of_elements;
00076     stream >> number_of_elements;
00077     DEBUG_MESSAGE("Reading vector of " << number_of_elements << " starting at " << stream.tellg());
00078     vector.reserve(number_of_elements);
00079     DEBUG_MESSAGE("Reading elements");
00080     for (unsigned int i = 0; i < number_of_elements; i++)
00081     {
00082         boost::shared_ptr<T> element(new T(stream, additional));
00083         DEBUG_MESSAGE("Read element " << i << ", now at " << stream.tellg());
00084         vector.push_back(element);
00085     }
00086     DEBUG_MESSAGE("Finished reading vector");
00087 }
00088 
00101 template <class T>
00102 void write_vector_to_stream(const std::vector<boost::shared_ptr<T> > & vector, std::ostream & stream)
00103 {
00104     std::size_t number_of_elements = vector.size();
00105     stream << number_of_elements << "\n";
00106     for (unsigned int i = 0; i < number_of_elements; i++)
00107     {
00108         stream << *(vector[i]) << "\n";
00109     }
00110 }
00111 
00117 inline int int_from_stream(std::istream & stream)
00118 {
00119     int i;
00120     stream >> i;
00121     return i;
00122 }
00123 
00129 btTransform transform_from_stream(std::istream & stream);
00130 
00136 std::ostream & operator<<(std::ostream & stream, btTransform transform);
00137 
00146 void string_to_stream(std::ostream & stream, std::string string);
00147 
00153 std::string string_from_stream(std::istream & stream);
00154 
00155 
00156 std::ostream & operator<<(std::ostream & destination, const btVector3 & vector);
00157 std::istream & operator>>(std::istream & source, btVector3 & vector);
00158 
00160 std::ostream & operator<<(std::ostream & destination, const btQuadWord & word);
00162 std::istream & operator>>(std::istream & source, btQuadWord & word);
00163 
00164 #endif /*LIBTRACK_STREAM_LOADER_H_*/

Get Racer at SourceForge.net. Fast, secure and Free Open Source software downloads

Generated at Mon Sep 6 00:41:12 2010 by Doxygen version 1.4.7 for Racer version svn335.