/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2008.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: include/sgx/filesystem/stlio.hpp

*/

#ifndef SGX_FILESYSTEM_STLIO_HPP
#define SGX_FILESYSTEM_STLIO_HPP	1

//
// Operator overloads
//
template<typename T> 
CSGXFile& operator<<(CSGXFile& file, std::vector<T>& val)
{
    tUINT32 size = (tUINT32)val.size();

    file << size;
    for (std::vector<T>::iterator it = val.begin(); it != val.end(); ++it) {
        file << *it;
    }
    return file;
}

// Loading code
template<typename T> 
CSGXFile& operator>>(CSGXFile& file, std::vector<T>& val)
{
tUINT32 size;

    file >> size;
    val.clear();
    val.reserve(size);

    for (tUINT32 i = 0; i < size; i++) {
        std::vector<T>::iterator it = val.insert(val.end(), T());
        file >> *it;
    }
    return file;
}

template<class T>
CSGXFile& operator|(CSGXFile& file, T& var)
{
    if (file.isSaving()) {
         return file << var;
    } else if (file.isLoading()) {
        return file >> var;
    }
    return file;
}


#endif /* SGX_FILESYSTEM_STLIO_HPP */
