Color,ColorPair: always pass by copy

This commit is contained in:
Maxime Coste 2013-07-26 00:26:43 +02:00
parent 8f73d3c173
commit d5453152b3
4 changed files with 12 additions and 13 deletions

View File

@ -30,7 +30,7 @@ Color str_to_color(const String& color)
return Colors::Default; return Colors::Default;
} }
String color_to_str(const Color& color) String color_to_str(Color color)
{ {
switch (color.color) switch (color.color)
{ {
@ -54,7 +54,7 @@ String color_to_str(const Color& color)
return "default"; return "default";
} }
String option_to_string(const Color& color) String option_to_string(Color color)
{ {
return color_to_str(color); return color_to_str(color);
} }

View File

@ -34,21 +34,20 @@ struct Color
Color(unsigned char r, unsigned char g, unsigned char b) Color(unsigned char r, unsigned char g, unsigned char b)
: color{Colors::RGB}, r{r}, g{g}, b{b} {} : color{Colors::RGB}, r{r}, g{g}, b{b} {}
bool operator==(const Color& c) const bool operator==(Color c) const
{ return color == c.color and r == c.r and g == c.g and b == c.b; } { return color == c.color and r == c.r and g == c.g and b == c.b; }
bool operator!=(const Color& c) const bool operator!=(Color c) const
{ return color != c.color or r != c.r or g != c.g or b != c.b; } { return color != c.color or r != c.r or g != c.g or b != c.b; }
}; };
using ColorPair = std::pair<Color, Color>; using ColorPair = std::pair<Color, Color>;
Color str_to_color(const String& color); Color str_to_color(const String& color);
String color_to_str(const Color& color); String color_to_str(Color color);
String option_to_string(const Color& color); String option_to_string(Color color);
void option_from_string(const String& str, Color& color); void option_from_string(const String& str, Color& color);
} }
#endif // color_hh_INCLUDED #endif // color_hh_INCLUDED

View File

@ -29,7 +29,7 @@ static void set_attribute(int attribute, bool on)
attroff(attribute); attroff(attribute);
} }
static bool operator<(const Color& lhs, const Color& rhs) static bool operator<(Color lhs, Color rhs)
{ {
if (lhs.color == rhs.color and lhs.color == Colors::RGB) if (lhs.color == rhs.color and lhs.color == Colors::RGB)
return lhs.r == rhs.r ? (lhs.g == rhs.g ? lhs.b < rhs.b return lhs.r == rhs.r ? (lhs.g == rhs.g ? lhs.b < rhs.b
@ -38,7 +38,7 @@ static bool operator<(const Color& lhs, const Color& rhs)
return lhs.color < rhs.color; return lhs.color < rhs.color;
} }
static int nc_color(const Color& color) static int nc_color(Color color)
{ {
static std::map<Color, int> colors = { static std::map<Color, int> colors = {
{ Colors::Default, -1 }, { Colors::Default, -1 },
@ -99,7 +99,7 @@ static int nc_color(const Color& color)
} }
} }
static int get_color_pair(const ColorPair& colors) static int get_color_pair(ColorPair colors)
{ {
static std::map<ColorPair, int> colorpairs; static std::map<ColorPair, int> colorpairs;
static int next_pair = 1; static int next_pair = 1;
@ -115,7 +115,7 @@ static int get_color_pair(const ColorPair& colors)
} }
} }
static void set_color(WINDOW* window, const ColorPair colors) static void set_color(WINDOW* window, ColorPair colors)
{ {
static int current_pair = -1; static int current_pair = -1;

View File

@ -75,7 +75,7 @@ public:
write(memoryview<T>(vec)); write(memoryview<T>(vec));
} }
void write(const Color& color) void write(Color color)
{ {
write(color.color); write(color.color);
if (color.color == Colors::RGB) if (color.color == Colors::RGB)
@ -86,7 +86,7 @@ public:
} }
} }
void write(const ColorPair& colors) void write(ColorPair colors)
{ {
write(colors.first); write(colors.first);
write(colors.second); write(colors.second);