I am using a va_list to construct a string that is rendered.
void Text2D::SetText(const char *szText, ...)
This is all fine and good, but now the user has the ability to change the language while the application is running. I need to regenerate all the text strings and re-cache the text bitmaps after initialization. I would like to store the va_list and use it whenever the text needs to be generated.
To give you some more background, this needs to happen in the case where the key string that I'm translating has a dynamic piece of data in it.
"Player Score:%d"
That is the key string I need to translate. I would like to hold the number(s) provided in the va_list for later use (outside the scope of the function that initializes the text) in the case that it needs to be re-translated after initialization. Preferably I would like to hold a copy of the va_list for use with vsnprintf.
I've done some research into doing this and have found a few ways. Some of which I question whether it is a appropriate method (in terms of being stable and portable).
Storing the va_list
itself is not a great idea; the standard only requires that the va_list
argument work with va_start()
, va_arg()
and va_end()
. As far as I can tell, the va_list
is not guaranteed to be copy constructable.
But you don't need to store the va_list
. Copy the supplied arguments into another data structure, such as a vector (of void*, probably), and retrieve them later in the usual way. You'll need to be careful about the types, but that's always the case for printf-style functions in C++.