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

outputsource_memory_generic.cpp

Go to the documentation of this file.
00001 /*
00002         $Id: outputsource_memory_generic.cpp,v 1.3 2001/03/13 21:43:00 sphair 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 
00017 #include <stdio.h>
00018 #include "API/Core/System/cl_assert.h"
00019 #include <API/Core/IOData/outputsource.h>
00020 #include "outputsource_memory_generic.h"
00021 
00022 CL_OutputSource_MemoryGeneric::CL_OutputSource_MemoryGeneric(unsigned int blocksize)
00023 {
00024         m_blocksize = blocksize;
00025         m_size = m_blocksize;
00026         m_data = new unsigned char[m_blocksize];
00027         m_pos = 0;
00028 }
00029 
00030 CL_OutputSource_MemoryGeneric::~CL_OutputSource_MemoryGeneric()
00031 {
00032         delete[] m_data;
00033 }
00034 
00035 void *CL_OutputSource_MemoryGeneric::get_data() const
00036 {
00037         return (void *) m_data;
00038 }
00039 
00040 void CL_OutputSource_MemoryGeneric::set_system_mode()
00041 {
00042         cl_assert(false); // not implemented yet.
00043 }
00044 
00045 void CL_OutputSource_MemoryGeneric::set_big_endian_mode()
00046 {
00047         cl_assert(false); // not implemented yet.
00048 }
00049 
00050 void CL_OutputSource_MemoryGeneric::set_little_endian_mode()
00051 {
00052         cl_assert(false); // not implemented yet.
00053 }
00054 
00055 void CL_OutputSource_MemoryGeneric::write_int32(int data)
00056 {
00057         write(&data, sizeof(int));
00058 }
00059 
00060 void CL_OutputSource_MemoryGeneric::write_uint32(unsigned int data)
00061 {
00062         write(&data, sizeof(unsigned int));
00063 }
00064 
00065 void CL_OutputSource_MemoryGeneric::write_short16(short data)
00066 {
00067         write(&data, sizeof(short));
00068 }
00069 
00070 void CL_OutputSource_MemoryGeneric::write_ushort16(unsigned short data)
00071 {
00072         write(&data, sizeof(unsigned short));
00073 }
00074 
00075 void CL_OutputSource_MemoryGeneric::write_char8(char data)
00076 {
00077         write(&data, sizeof(char));
00078 }
00079 
00080 void CL_OutputSource_MemoryGeneric::write_uchar8(unsigned char data)
00081 {
00082         write(&data, sizeof(unsigned char));
00083 }
00084 
00085 void CL_OutputSource_MemoryGeneric::write_float32(float data)
00086 {
00087         write(&data, sizeof(float));
00088 }
00089 
00090 void CL_OutputSource_MemoryGeneric::write_bool(bool data)
00091 {
00092         write(&data, sizeof(bool));
00093 }
00094 
00095 int CL_OutputSource_MemoryGeneric::write(const void *data, int size)
00096 {
00097         if (m_pos + size > m_size) // extend array with blocksize
00098         {
00099                 int new_size = m_size + size + m_blocksize;
00100 
00101                 unsigned char *old = m_data;
00102                 m_data = new unsigned char[new_size];
00103 
00104                 memcpy(m_data, old, m_pos);
00105                 delete[] old;
00106                 m_size = new_size;
00107         }
00108         
00109         memcpy(m_data + m_pos, data, size);
00110         m_pos += size;
00111         
00112         return size;
00113 }
00114 
00115 void CL_OutputSource_MemoryGeneric::open()
00116 {
00117 }
00118 
00119 void CL_OutputSource_MemoryGeneric::close()
00120 {
00121 }
00122 
00123 CL_OutputSource *CL_OutputSource_MemoryGeneric::clone()
00124 {
00125         cl_assert(false); // not implemented yet.
00126         return NULL;
00127 }
00128 
00129 int CL_OutputSource_MemoryGeneric::tell()
00130 {
00131         return m_pos;
00132 }
00133 
00134 int CL_OutputSource_MemoryGeneric::size()
00135 {
00136         return m_pos;
00137 }
00138 
00139 void CL_OutputSource_MemoryGeneric::write_string(const char *string)
00140 {
00141         int len = strlen(string)+1;
00142         write_int32(len);
00143         write((char*) string, len);
00144 }
00145 
00146 void CL_OutputSource_MemoryGeneric::purge()
00147 {
00148         memcpy(m_data,0,m_size);
00149 }

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