简体   繁体   中英

STL Container, which is suitable?

I want to be able to store ID3DXFonts in an STL container, this needs to be done as some of the program will be made in a scripting language. However other parts of it need to be hard coded to be unmolested.

I need to be able to workout what font, is needed to render each item on the screen. Weather it hard coded or programed by a script.

I'd like to know which STL container would be suitable for this, as when it comes to time to draw the elements on screen. All the fonts may not have to be used, and I would need to pull say the nth element from the list.

As for tagging a font to a string of text I was thinking about using a template to hold the text and the font ID or placement from the STL.

There are two steps to the answer:

  1. You should probably use smart-pointers (probably std::unique_ptr , maybe std::shared_ptr , or even one of the dedicated com-pointers to store each interface-pointer.

  2. If you want random-access to a sequence, nothing beats a std::vector , but a std::array . If keys are more haphazardly distributed (or not integers), a std::map or even a std::unordered_map might be more appropriate though.

If you know the index of the font you need, then use std::vector . If you have to look up a key, then you might want to use std::unordered_map (which is the standard c++ hash map).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM