Changeset - r12499:2e177e6e0453
[Not reviewed]
master
0 2 0
alberth - 15 years ago 2009-07-25 07:49:49
alberth@openttd.org
(svn r16946) -Doc: Adding docs for some string parameter manipulation functions.
2 files changed with 41 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/strings.cpp
Show inline comments
 
@@ -32,14 +32,14 @@
 
#include "strgen/strgen.h"
 
#include "gfx_func.h"
 

	
 
#include "table/strings.h"
 
#include "table/control_codes.h"
 

	
 
DynamicLanguages _dynlang;
 
uint64 _decode_parameters[20];
 
DynamicLanguages _dynlang;     ///< Language information of the program.
 
uint64 _decode_parameters[20]; ///< Global array of string parameters. To access, use #SetDParam.
 

	
 
static char *StationGetSpecialString(char *buff, int x, const char *last);
 
static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed, const char *last);
 
static char *GetSpecialNameString(char *buff, int ind, int64 *argv, const char *last);
 

	
 
static char *FormatString(char *buff, const char *str, int64 *argv, uint casei, const char *last);
 
@@ -168,12 +168,16 @@ char *InlineString(char *buf, StringID s
 
 */
 
void SetDParamStr(uint n, const char *str)
 
{
 
	SetDParam(n, (uint64)(size_t)str);
 
}
 

	
 
/**
 
 * Shift the string parameters in the global string parameter array by \a amount positions, making room at the beginning.
 
 * @param amount Number of positions to shift.
 
 */
 
void InjectDParam(uint amount)
 
{
 
	assert((uint)amount < lengthof(_decode_parameters));
 
	memmove(_decode_parameters + amount, _decode_parameters, sizeof(_decode_parameters) - amount * sizeof(uint64));
 
}
 

	
src/strings_func.h
Show inline comments
 
@@ -10,46 +10,81 @@
 
char *InlineString(char *buf, StringID string);
 
char *GetString(char *buffr, StringID string, const char *last);
 
const char *GetStringPtr(StringID string);
 

	
 
void InjectDParam(uint amount);
 

	
 
/**
 
 * Set a string parameter \a v at index \a n in a given array \a s.
 
 * @param s Array of string parameters.
 
 * @param n Index of the string parameter.
 
 * @param v Value of the string parameter.
 
 */
 
static inline void SetDParamX(uint64 *s, uint n, uint64 v)
 
{
 
	s[n] = v;
 
}
 

	
 
/**
 
 * Set a string parameter \a v at index \a n in the global string parameter array.
 
 * @param n Index of the string parameter.
 
 * @param v Value of the string parameter.
 
 */
 
static inline void SetDParam(uint n, uint64 v)
 
{
 
	extern uint64 _decode_parameters[20];
 

	
 
	assert(n < lengthof(_decode_parameters));
 
	_decode_parameters[n] = v;
 
}
 

	
 
void SetDParamStr(uint n, const char *str);
 

	
 
/**
 
 * Get the current string parameter at index \a n from parameter array \a s.
 
 * @param s Array of string parameters.
 
 * @param n Index of the string parameter.
 
 * @return Value of the requested string parameter.
 
 */
 
static inline uint64 GetDParamX(const uint64 *s, uint n)
 
{
 
	return s[n];
 
}
 

	
 
/**
 
 * Get the current string parameter at index \a n from the global string parameter array.
 
 * @param s Array of string parameters.
 
 * @param n Index of the string parameter.
 
 * @return Value of the requested string parameter.
 
 */
 
static inline uint64 GetDParam(uint n)
 
{
 
	extern uint64 _decode_parameters[20];
 

	
 
	assert(n < lengthof(_decode_parameters));
 
	return _decode_parameters[n];
 
}
 

	
 
/**
 
 * Copy \a num string parameters from array \a src into the global string parameter array.
 
 * @param offs Index in the global array to copy the first string parameter to.
 
 * @param src  Source array of string parameters.
 
 * @param num  Number of string parameters to copy.
 
 */
 
static inline void CopyInDParam(int offs, const uint64 *src, int num)
 
{
 
	extern uint64 _decode_parameters[20];
 
	memcpy(_decode_parameters + offs, src, sizeof(uint64) * (num));
 
}
 

	
 
/**
 
 * Copy \a num string parameters from the global string parameter array to the \a dst array.
 
 * @param dst  Destination array of string parameters.
 
 * @param offs Index in the global array to copy the first string parameter from.
 
 * @param num  Number of string parameters to copy.
 
 */
 
static inline void CopyOutDParam(uint64 *dst, int offs, int num)
 
{
 
	extern uint64 _decode_parameters[20];
 
	memcpy(dst, _decode_parameters + offs, sizeof(uint64) * (num));
 
}
 

	
0 comments (0 inline, 0 general)