stream_loader.h File Reference

Declare some functions to help with loading information from c++ stream objects. More...

#include <vector>
#include <istream>
#include "Drawable.h"
#include <boost/shared_ptr.hpp>
#include <LinearMath/btTransform.h>
#include <Debug.h>

Go to the source code of this file.

Functions

template<class T>
void fill_vector_from_stream (std::vector< boost::shared_ptr< T > > &vector, std::istream &stream)
 Fill a std::vector<boost::shared_ptr<T> > with refernce counted pointers to T objects created from a stream object.
template<class T, class S>
void fill_vector_from_stream (std::vector< boost::shared_ptr< T > > &vector, std::istream &stream, S &additional)
 Fill a std::vector<boost::shared_ptr<T> > with refernce counted pointers to T objects created from a stream object.
template<class T>
void write_vector_to_stream (const std::vector< boost::shared_ptr< T > > &vector, std::ostream &stream)
 Write a std::vector<boost::shared_ptr<T> >'s contents to a stream.
int int_from_stream (std::istream &stream)
 get an int from a stream.
btTransform transform_from_stream (std::istream &stream)
 get a btTransform from a stream.
std::ostream & operator<< (std::ostream &stream, btTransform transform)
 Write a btTransform to a stream.
void string_to_stream (std::ostream &stream, std::string string)
 Write a string to a stream with known whitespace surrounding it.
std::string string_from_stream (std::istream &stream)
 Read a string written with string_to_stream().
std::ostream & operator<< (std::ostream &destination, const btVector3 &vector)
std::istream & operator>> (std::istream &source, btVector3 &vector)
std::ostream & operator<< (std::ostream &destination, const btQuadWord &word)
 Write a btQuaternion to a stream. Useful for btQuaternion too.
std::istream & operator>> (std::istream &source, btQuadWord &word)
 Read a btQuadWord from a stream. Useful for btQuaternion too.


Detailed Description

Declare some functions to help with loading information from c++ stream objects.

Author:
James Legg

Definition in file stream_loader.h.


Function Documentation

template<class T, class S>
void fill_vector_from_stream ( std::vector< boost::shared_ptr< T > > &  vector,
std::istream &  stream,
S &  additional 
)

Fill a std::vector<boost::shared_ptr<T> > with refernce counted pointers to T objects created from a stream object.

If the constructor of T takes the stream output from the objects' operator<<, then Track::write_vector_to_stream and Track::fill_vector_from_stream can be used to save and restore the state of a std::vector of objects. T The type of object listed in the file. It must have a constructor that takes a std::istream and pulls from it the information it needs.

Parameters:
vector The vector to fill.
stream The stream containing the information about the vector. S Type of the additional data to pass to the constructor of T objects.
additional Additional data to pass to the constructor of T objects.

Definition at line 71 of file stream_loader.h.

template<class T>
void fill_vector_from_stream ( std::vector< boost::shared_ptr< T > > &  vector,
std::istream &  stream 
)

Fill a std::vector<boost::shared_ptr<T> > with refernce counted pointers to T objects created from a stream object.

If the constructor of T takes the stream output from the objects' operator<<, then Track::write_vector_to_stream and Track::fill_vector_from_stream can be used to save and restore the state of a std::vector of objects.

Warning:
This breaks on strings with separators. Use
 fill_string_vector_from_stream 
instead. T The type of object listed in the file. It must have a constructor that takes a std::istream and pulls from it the information it needs.
Parameters:
vector The vector to fill.
stream The stream containing the information about the vector.

Definition at line 40 of file stream_loader.h.

int int_from_stream ( std::istream &  stream  )  [inline]

get an int from a stream.

Useful for constructors. Reads an int from a stream, advancing it to the end of the int.

Parameters:
stream The stream to get the int from.
Returns:
first integer found after the stream's position.

Definition at line 117 of file stream_loader.h.

std::ostream& operator<< ( std::ostream &  destination,
const btQuadWord &  word 
)

Write a btQuaternion to a stream. Useful for btQuaternion too.

Definition at line 97 of file stream_loader.cpp.

std::ostream& operator<< ( std::ostream &  destination,
const btVector3 &  vector 
)

Definition at line 79 of file stream_loader.cpp.

std::ostream& operator<< ( std::ostream &  stream,
btTransform  transform 
)

Write a btTransform to a stream.

Parameters:
stream The stream to write data to.
transform The btTransform write to the stream.
Returns:
The same stream that was passed in.

Definition at line 30 of file stream_loader.cpp.

std::istream& operator>> ( std::istream &  source,
btQuadWord &  word 
)

Read a btQuadWord from a stream. Useful for btQuaternion too.

Definition at line 106 of file stream_loader.cpp.

std::istream& operator>> ( std::istream &  source,
btVector3 &  vector 
)

Definition at line 87 of file stream_loader.cpp.

std::string string_from_stream ( std::istream &  stream  ) 

Read a string written with string_to_stream().

Parameters:
stream a stream either at the beginning of a string written with string_to_stream(), or with only whitespace before one.
Returns:
the string passed to write_string_vector

Definition at line 54 of file stream_loader.cpp.

void string_to_stream ( std::ostream &  stream,
std::string  string 
)

Write a string to a stream with known whitespace surrounding it.

You can get the string back with string_from_stream, no matter what whitespace was placed around the string. The string is allowed to contain any characters.

Parameters:
stream The stream to write to.
string the string to record.

Definition at line 47 of file stream_loader.cpp.

btTransform transform_from_stream ( std::istream &  stream  ) 

get a btTransform from a stream.

Parameters:
stream The stream to extract data from. It is advanced to the end of the btTransform.
Returns:
The btTransform read.

Definition at line 16 of file stream_loader.cpp.

template<class T>
void write_vector_to_stream ( const std::vector< boost::shared_ptr< T > > &  vector,
std::ostream &  stream 
)

Write a std::vector<boost::shared_ptr<T> >'s contents to a stream.

If the constructor of T takes the stream output from the objects' operator<<, then Track::write_vector_to_stream and Track::fill_vector_from_stream can be used to save and restore the state of a std::vector of objects.

Warning:
This breaks on strings with separators. Use
 write_string_vector_to_stream 
instead. T The type of object pointed to by shared pointers in the vector. It must have an operator<< that writes information about to a stream.
Parameters:
vector The vector to get the objects from.
stream The stream to insert the information.

Definition at line 102 of file stream_loader.h.


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

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