FormatStr changed to string
This commit is contained in:
parent
7a4ba04e94
commit
6709e83d94
@ -1,95 +1,95 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
This file is Part of the ZEngine Library for 2D game development.
|
This file is Part of the ZEngine Library for 2D game development.
|
||||||
Copyright (C) 2002, 2003 James Turk
|
Copyright (C) 2002, 2003 James Turk
|
||||||
|
|
||||||
Licensed under a BSD-style license.
|
Licensed under a BSD-style license.
|
||||||
|
|
||||||
The maintainer of this library is James Turk (james@conceptofzero.net)
|
The maintainer of this library is James Turk (james@conceptofzero.net)
|
||||||
and the home of this Library is http://www.zengine.sourceforge.net
|
and the home of this Library is http://www.zengine.sourceforge.net
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\file ZE_Utility.h
|
\file ZE_Utility.h
|
||||||
\brief Definition file for ZEngine Utilities.
|
\brief Definition file for ZEngine Utilities.
|
||||||
|
|
||||||
Definition file for ZEngine Utilities which are used throughout the engine and can be used in
|
Definition file for ZEngine Utilities which are used throughout the engine and can be used in
|
||||||
conjunction with ZEngine.
|
conjunction with ZEngine.
|
||||||
<br>$Id: ZE_Utility.h,v 1.9 2003/10/13 21:48:12 cozman Exp $<br>
|
<br>$Id: ZE_Utility.h,v 1.10 2003/11/24 02:02:25 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
|
||||||
#ifndef __ze_utility_h__
|
#ifndef __ze_utility_h__
|
||||||
#define __ze_utility_h__
|
#define __ze_utility_h__
|
||||||
|
|
||||||
#include "ZE_Includes.h"
|
#include "ZE_Includes.h"
|
||||||
|
|
||||||
namespace ZE
|
namespace ZE
|
||||||
{
|
{
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Parses a std::string and interprets variable arguments, similar to sprintf.
|
\brief Parses a std::string and interprets variable arguments, similar to sprintf.
|
||||||
|
|
||||||
Takes % identifiers out of fmtstr and parses them, replacing them with cooresponding values
|
Takes % identifiers out of fmtstr and parses them, replacing them with cooresponding values
|
||||||
in the variable arguments list. For more detail view stdarg documentation.
|
in the variable arguments list. For more detail view stdarg documentation.
|
||||||
\param fmtstr defines format of resulting std::string
|
\param fmtstr defines format of resulting std::string
|
||||||
\param ... variable number of arguments after fmtstr
|
\param ... variable number of arguments after fmtstr
|
||||||
\return std::string of parsed and combined std::string
|
\return std::string of parsed and combined std::string
|
||||||
**/
|
**/
|
||||||
std::string FormatStr(const char *fmtstr, ...);
|
std::string FormatStr(const std::string fmtstr, ...);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Extracts a SDL_RWops memory structure from a zip archive.
|
\brief Extracts a SDL_RWops memory structure from a zip archive.
|
||||||
|
|
||||||
Attempts to open a file from within a zipfile and return a SDL_RWops which can be used
|
Attempts to open a file from within a zipfile and return a SDL_RWops which can be used
|
||||||
to load a resource from memory.
|
to load a resource from memory.
|
||||||
Used internally, generally shouldn't be called by users.
|
Used internally, generally shouldn't be called by users.
|
||||||
\param zipname Name of zip-format archive to open.
|
\param zipname Name of zip-format archive to open.
|
||||||
\param filename Name of file within archive to access.
|
\param filename Name of file within archive to access.
|
||||||
\return On success, pointer to SDL_RWops, on failure, NULL.
|
\return On success, pointer to SDL_RWops, on failure, NULL.
|
||||||
\since 0.8.5
|
\since 0.8.5
|
||||||
**/
|
**/
|
||||||
SDL_RWops* RWFromZip(std::string zipname, std::string filename);
|
SDL_RWops* RWFromZip(std::string zipname, std::string filename);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Properly free SDL_Surface.
|
\brief Properly free SDL_Surface.
|
||||||
|
|
||||||
Safely free an SDL_Surface* and set it to NULL.
|
Safely free an SDL_Surface* and set it to NULL.
|
||||||
\param image Image to free and set to NULL.
|
\param image Image to free and set to NULL.
|
||||||
**/
|
**/
|
||||||
void FreeImage(SDL_Surface *&image);
|
void FreeImage(SDL_Surface *&image);
|
||||||
|
|
||||||
#ifdef USE_SDL_MIXER
|
#ifdef USE_SDL_MIXER
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Properly free Mix_Chunk.
|
\brief Properly free Mix_Chunk.
|
||||||
|
|
||||||
Safely free a Mix_Chunk* and set it to NULL.
|
Safely free a Mix_Chunk* and set it to NULL.
|
||||||
\param chunk Chunk to free and set to NULL.
|
\param chunk Chunk to free and set to NULL.
|
||||||
**/
|
**/
|
||||||
void FreeSound(Mix_Chunk *&chunk);
|
void FreeSound(Mix_Chunk *&chunk);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Properly free Mix_Music.
|
\brief Properly free Mix_Music.
|
||||||
|
|
||||||
Safely free a Mix_Music* and set it to NULL.
|
Safely free a Mix_Music* and set it to NULL.
|
||||||
\param music Music to free and set to NULL.
|
\param music Music to free and set to NULL.
|
||||||
**/
|
**/
|
||||||
void FreeMusic(Mix_Music *&music);
|
void FreeMusic(Mix_Music *&music);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_SDL_TTF
|
#ifdef USE_SDL_TTF
|
||||||
/*!
|
/*!
|
||||||
\brief Properly free TTF_Font.
|
\brief Properly free TTF_Font.
|
||||||
|
|
||||||
Safely free a TTF_Font* and set it to NULL.
|
Safely free a TTF_Font* and set it to NULL.
|
||||||
\param font Font to free and set to NULL.
|
\param font Font to free and set to NULL.
|
||||||
**/
|
**/
|
||||||
void FreeFont(TTF_Font *&font);
|
void FreeFont(TTF_Font *&font);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //__ze_utility_h__
|
#endif //__ze_utility_h__
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
\brief Source file for ZEngine utility functions.
|
\brief Source file for ZEngine utility functions.
|
||||||
|
|
||||||
Source file containing open utilities for use inside and alongside ZEngine.
|
Source file containing open utilities for use inside and alongside ZEngine.
|
||||||
<br>$Id: ZE_Utility.cpp,v 1.13 2003/10/13 21:48:13 cozman Exp $<br>
|
<br>$Id: ZE_Utility.cpp,v 1.14 2003/11/24 02:07:03 cozman Exp $<br>
|
||||||
\author James Turk
|
\author James Turk
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@ -22,57 +22,58 @@
|
|||||||
namespace ZE
|
namespace ZE
|
||||||
{
|
{
|
||||||
|
|
||||||
std::string FormatStr(const char *fmtstr, ...)
|
std::string FormatStr(const std::string fmtstr, ...)
|
||||||
{
|
{
|
||||||
char buf[512];
|
char buf[512];
|
||||||
va_list args;
|
va_list args;
|
||||||
//simply puts args into the buffer using standard parsing rules
|
//simply puts args into the buffer using standard parsing rules
|
||||||
va_start(args,fmtstr);
|
va_start(args,fmtstr);
|
||||||
vsprintf(buf, fmtstr, args);
|
vsprintf(buf, fmtstr.c_str(), args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_RWops* RWFromZip(std::string zipname, std::string filename)
|
SDL_RWops* RWFromZip(std::string zipname, std::string filename)
|
||||||
{
|
{
|
||||||
unzFile zip = unzOpen(zipname.c_str());
|
unzFile zip = unzOpen(zipname.c_str());
|
||||||
unz_file_info info;
|
unz_file_info info;
|
||||||
void *buffer;
|
void *buffer;
|
||||||
|
|
||||||
if(!zip) //failed to open zip
|
if(!zip) //failed to open zip
|
||||||
{
|
{
|
||||||
//log error
|
//log error
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
//locate the file and open it (last param means case sensitive comparison)
|
//locate the file and open it (last param means case sensitive comparison)
|
||||||
unzLocateFile(zip,filename.c_str(),0);
|
unzLocateFile(zip,filename.c_str(),0);
|
||||||
if(unzOpenCurrentFile(zip) != UNZ_OK) //failed to open file within zip
|
if(unzOpenCurrentFile(zip) != UNZ_OK) //failed to open file within zip
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
//find current file info (we are looking for uncompressed file size)
|
//find current file info (we are looking for uncompressed file size)
|
||||||
unzGetCurrentFileInfo(zip,&info,NULL,0,NULL,0,NULL,0);
|
unzGetCurrentFileInfo(zip,&info,NULL,0,NULL,0,NULL,0);
|
||||||
|
|
||||||
//create a buffer big enough to hold uncompressed file in memory
|
//create a buffer big enough to hold uncompressed file in memory
|
||||||
buffer = (void*)new char[info.uncompressed_size];
|
buffer = (void*)new char[info.uncompressed_size];
|
||||||
if(!buffer)
|
if(!buffer)
|
||||||
{
|
{
|
||||||
unzCloseCurrentFile(zip);
|
unzCloseCurrentFile(zip);
|
||||||
unzClose(zip);
|
unzClose(zip);
|
||||||
//log error (failed to allocate memory?!)
|
//log error (failed to allocate memory?!)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
//load into memory
|
//load into memory
|
||||||
unzReadCurrentFile(zip, buffer, info.uncompressed_size);
|
unzReadCurrentFile(zip, buffer, info.uncompressed_size);
|
||||||
|
|
||||||
//close archive
|
//close archive
|
||||||
unzCloseCurrentFile(zip);
|
unzCloseCurrentFile(zip);
|
||||||
unzClose(zip);
|
unzClose(zip);
|
||||||
|
|
||||||
return SDL_RWFromMem(buffer, info.uncompressed_size); //return buffer in RW form
|
return SDL_RWFromMem(buffer, info.uncompressed_size); //return buffer in RW form
|
||||||
}
|
}
|
||||||
|
|
||||||
//Each of the Free*s safely frees & NULLs the pointer
|
//Each of the Free*s safely frees & NULLs the pointer
|
||||||
|
Loading…
Reference in New Issue
Block a user