Time for action β using STL containers
Let's now replace raw arrays with standard STL containers by following these steps:
- Open the
jni/GraphicsManager.hpp
header and include the headers:Vector
, which defines an STL container encapsulating C arrays (with a few more interesting features such as dynamic resizing)Map
, which encapsulates the equivalent of a Java HashMap (that is, an associative array)
Then, remove the
textureResource
member in theTextureProperties
structure. Use amap
container instead of a raw array formTextures
(prefixed with thestd
namespace). The first parameter is the key type and the second the value type.Finally, replace all the other raw arrays with a
vector
, as shown in the following:... #include <android_native_app_glue.h> #include <GLES2/gl2.h> #include <EGL/egl.h> #include <map> #include <vector> ... struct TextureProperties { GLuint texture; int32_t width; int32_t height; }; class GraphicsManager { ....