0

I have an unordered map that is supposed to check if a pen exists given the color, and the width of the pen. I'm currently trying to do a lookup by string. If it’s already in the map, that means I already created a Pen of that type. If it isn’t already in the map, I want to create a new Pen and set the color and weight, and add that to the unordered_map.

 std::unordered_map<std::string, std::shared_ptr<Gdiplus::Pen>> mymap;

The properties of the pen that i want are the color and the width... as you can see the color comes in the format(0,0,0) and the width is just a float number. I was thinking about doing a string as such: "(R,G,B);W" where R, G, B correspond to the colors and W corresponds to the width of the Pen, but that seems too complex.

 Gdiplus::Pen pen(Color(0, 0, 0));
 pen.getWidth();

I was wondering if there is a simple way to pass those properties as a single string or if there is a better way to go around my problem.

My string is supposed to see if the pen exists. it checks the pen color and the width.

4

1 回答 1

0

我的假设是你正在检查一支笔是否存在。

与其将事物放入字符串中,不如将它们放入结构中并在容器中使用该结构。

struct Pen_Properties
{
  unsigned int r,g, b;
  unsigned int width;

  bool operator<(const Pen_Properties& p)
  {
     bool result = true;
     if (r != p.r)
     {
       result = r < p.r;
     }
     else
     {
        if (g != p.g)
        {
          result = g < p.g;
        }
        else
        {
           // And so on.
        }
     }
};
于 2013-03-29T20:40:40.393 回答