Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

inputsource_memory.cpp

Go to the documentation of this file.
00001 /*
00002         $Id: inputsource_memory.cpp,v 1.1.1.1 2000/04/09 12:18:01 mbn Exp $
00003 
00004         ------------------------------------------------------------------------
00005         ClanLib, the platform independent game SDK.
00006 
00007         This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00008         version 2. See COPYING for details.
00009 
00010         For a total list of contributers see CREDITS.
00011 
00012         ------------------------------------------------------------------------
00013 */
00014 
00015 #include "Core/precomp.h"
00016 #include <API/Core/System/error.h>
00017 #include <API/Core/System/clanstring.h>
00018 #include <API/Core/IOData/inputsource.h>
00019 #include <API/Core/IOData/inputsource_memory.h>
00020 #include <API/Core/IOData/inputsource_provider.h>
00021 #include <Core/IOData/Generic/datafile_inputprovider.h>
00022 
00023 CL_InputSource_Memory::CL_InputSource_Memory(std::string data)
00024 {
00025         m_data = data;
00026         m_pos = 0;
00027 }
00028 
00029 CL_InputSource_Memory::~CL_InputSource_Memory()
00030 {
00031 }
00032 
00033 void CL_InputSource_Memory::set_system_mode()
00034 {
00035         cl_assert(false); // not implemented yet.
00036 }
00037 
00038 void CL_InputSource_Memory::set_big_endian_mode()
00039 {
00040         cl_assert(false); // not implemented yet.
00041 }
00042 
00043 void CL_InputSource_Memory::set_little_endian_mode()
00044 {
00045         cl_assert(false); // not implemented yet.
00046 }
00047 
00048 int CL_InputSource_Memory::read_int32()
00049 {
00050         cl_assert(m_pos+sizeof(int) <= m_data.size());
00051 
00052         int a = *((int *)(m_data.data()+m_pos));
00053         m_pos += sizeof(int);
00054         return a;
00055 }
00056 
00057 unsigned int CL_InputSource_Memory::read_uint32()
00058 {
00059         cl_assert(m_pos+sizeof(unsigned int) <= m_data.size());
00060 
00061         unsigned int a = *((unsigned int *)(m_data.data()+m_pos));
00062         m_pos += sizeof(unsigned int);
00063         return a;
00064 }
00065 
00066 short CL_InputSource_Memory::read_short16()
00067 {
00068         cl_assert(m_pos+sizeof(short) <= m_data.size());
00069 
00070         short a = *((short *)(m_data.data()+m_pos));
00071         m_pos += sizeof(short);
00072         return a;
00073 }
00074 
00075 unsigned short CL_InputSource_Memory::read_ushort16()
00076 {
00077         cl_assert(m_pos+sizeof(unsigned short) <= m_data.size());
00078 
00079         unsigned short a = *((unsigned short *)(m_data.data()+m_pos));
00080         m_pos += sizeof(unsigned short);
00081         return a;
00082 }
00083 
00084 char CL_InputSource_Memory::read_char8()
00085 {
00086         cl_assert(m_pos+1 <= m_data.size());
00087         return ((char *) m_data.data())[m_pos++];
00088 }
00089 
00090 unsigned char CL_InputSource_Memory::read_uchar8()
00091 {
00092         cl_assert(m_pos+1 <= m_data.size());
00093         return m_data[m_pos++];
00094 }
00095 
00096 bool CL_InputSource_Memory::read_bool()
00097 {
00098         cl_assert(m_pos+sizeof(bool) <= m_data.size());
00099 
00100         bool a = *((bool *)(m_data.data()+m_pos));
00101         m_pos += sizeof(bool);
00102         return a;
00103 }
00104 
00105 float CL_InputSource_Memory::read_float32()
00106 {
00107         cl_assert(m_pos+sizeof(float) <= m_data.size());
00108 
00109         float a = *((float *)(m_data.data()+m_pos));
00110         m_pos += sizeof(float);
00111         return a;
00112 }
00113 
00114 int CL_InputSource_Memory::read(void *data, int size)
00115 {
00116         cl_assert(m_pos+size <= m_data.size());
00117         
00118         memcpy(data, m_data.data()+m_pos, size);
00119         m_pos += size;
00120 
00121         return size;
00122 }
00123 
00124 void CL_InputSource_Memory::open()
00125 {
00126         m_pos = 0;
00127 }
00128 
00129 void CL_InputSource_Memory::close()
00130 {
00131 }
00132 
00133 CL_InputSource *CL_InputSource_Memory::clone() const
00134 {
00135         return new CL_InputSource_Memory(m_data);
00136 }
00137 
00138 int CL_InputSource_Memory::tell() const
00139 {
00140         return m_pos;
00141 }
00142 
00143 void CL_InputSource_Memory::seek(int pos, SeekEnum seek_type)
00144 {
00145         switch (seek_type)
00146         {
00147         case seek_set:
00148                 m_pos = pos;
00149                 break;
00150         
00151         case seek_cur:
00152                 m_pos += pos;
00153                 break;
00154         
00155         case seek_end:
00156                 m_pos = m_data.size()+pos;
00157                 break;
00158         
00159         default: // invalid seek type!
00160                 cl_assert(false);
00161         }
00162 }
00163 
00164 int CL_InputSource_Memory::size() const
00165 {
00166         return m_data.size();
00167 }
00168 
00169 std::string CL_InputSource_Memory::read_string()
00170 {
00171         int size = read_int32();
00172         CL_String str((char *) (m_data.data()+m_pos), size);
00173         m_pos += size;
00174         return str;
00175 }
00176 
00177 void CL_InputSource_Memory::push_position()
00178 {
00179         cl_assert(false); // not implemented yet.
00180 }
00181 
00182 void CL_InputSource_Memory::pop_position()
00183 {
00184         cl_assert(false); // not implemented yet.
00185 }

Generated at Wed Apr 4 19:54:01 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001