00001 #ifndef H_SDLPP_IO
00002 #define H_SDLPP_IO
00003
00004 #include "sdlpp_llio.h"
00005 #include "xml.h"
00006 #include <boost/iterator/transform_iterator.hpp>
00007
00008 namespace SDLPP
00009 {
00010
00011 template<class K, class T>
00012 struct pair_first : public std::unary_function<std::pair<K,T>,K>
00013 {
00014 const K& operator() (const std::pair<K,T>& p) const
00015 {
00016 return p.first;
00017 }
00018 };
00019
00024 class ResourceFile
00025 {
00026 struct Resource { int position; int size; };
00027 typedef std::map<xstring,Resource> rsc_map;
00028 rsc_map m_Resources;
00029 xstring m_Filename;
00030 ResourceFile(const ResourceFile& rhs) {}
00031 ResourceFile& operator= (const ResourceFile& rhs) { return *this; }
00032 public:
00038 ResourceFile(const char* filename);
00039 virtual ~ResourceFile() {}
00040
00043 std::istream* get(const xstring& resource_name);
00044
00045 typedef rsc_map::const_iterator base_iterator;
00046 typedef pair_first<xstring,Resource> pf_sr;
00047 typedef boost::transform_iterator<pf_sr,base_iterator> const_iterator;
00048 const_iterator begin() const { return const_iterator(m_Resources.begin(),pf_sr()); }
00049 const_iterator end() const { return const_iterator(m_Resources.end(),pf_sr()); }
00050 };
00051
00058 class ResourceFileWriter
00059 {
00060 std::ofstream m_File;
00061 ResourceFileWriter(const ResourceFileWriter& rhs) {}
00062 ResourceFileWriter& operator= (const ResourceFileWriter& rhs) { return *this; }
00063 public:
00068 ResourceFileWriter(const char* filename, bool append=true);
00069 virtual ~ResourceFileWriter() {}
00070
00072 void add_resource(const char* filename);
00073
00075 void add_resource(const char* name, const char* buffer, int length);
00076 };
00077
00085 SDL_RWops *SDL_RWFromStream(std::istream* input);
00086
00087 bool read_contents(const xstring& name, char_vec& cv, ResourceFile* rf=0);
00088 xstring read_contents_as_string(const xstring& name, ResourceFile* rf=0);
00089
00090 void handle_xml_eol(xstring& s);
00091 xml_element* load_xml(const xstring& name, ResourceFile* rf);
00092
00093 }
00094
00095 #endif // H_SDLPP_IO
00096