Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51136 - sandbox/SOC/2007/visualization/boost/svg_plot
From: pbristow_at_[hidden]
Date: 2009-02-09 09:43:16


Author: pbristow
Date: 2009-02-09 09:43:15 EST (Mon, 09 Feb 2009)
New Revision: 51136
URL: http://svn.boost.org/trac/boost/changeset/51136

Log:
operator== != corrections.
Text files modified:
   sandbox/SOC/2007/visualization/boost/svg_plot/svg_color.hpp | 145 +++++++++++++++++++++++++++++++++++++++
   1 files changed, 144 insertions(+), 1 deletions(-)

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg_color.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg_color.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg_color.hpp 2009-02-09 09:43:15 EST (Mon, 09 Feb 2009)
@@ -1,6 +1,7 @@
 /*!
   \file svg_color.hpp
   \brief SVG standard names of colors, and functions to create and output colors.
+ \date 9 Feb 2009
   \author Jacob Voytko & Paul A. Bristow
 */
 // Copyright Jacob Voytko 2007
@@ -66,7 +67,149 @@
     blank // 'NotAColor' == 147
   }; // enum svg_color_constant
 
- // Forward declarations in this module (see svg_fwd): struct svg_color; void constant_to_rgb(svg_color_constant c, unsigned char& r, unsigned char& g, unsigned char& b); std::ostream& operator<< (std::ostream&, const svg_color&); // -------------------------------------------------------------------- // svg_color is the struct that contains information about RGB colors. // // For the constructor, the SVG standard specifies that numbers // outside the normal rgb range are to be accepted, // but are constrained to acceptable range of integer values [0, 255]. // -------------------------------------------------------------------- struct svg_color //!< SVG standard colors, see also enum \#boost::svg::svg_color_constant. { friend std::ostream& operator<< (std::ostream& os, const svg_color& rhs); unsigned char r; //!< unsigned char provides range [0 to 255]. unsigned char g; unsigned char b; bool is_blank; // true means "Not to be displayed" a 'pseudo-color'. // If true should d
isplay & write as "none". svg_color(int red, int green, int blue) : is_blank(false) { /*! \brief Construct a color from RGB values. \details Constrain rgb to [0 .. 255]. Default is to construct a blank 'pseudo-color'. */ red = ( red < 0 ) ? 0 : red; green = ( green < 0 ) ? 0 : green; blue = ( blue < 0 ) ? 0 : blue; r = (unsigned char)(( red > 255 ) ? 255 : red); g = (unsigned char)(( green > 255 ) ? 255 : green); b = (unsigned char)(( blue > 255 ) ? 255 : blue); } // svg_color(int red, int green, int blue) svg_color(bool is) : is_blank(!is) { //! Constructor from bool permits svg_color my_blank(false) as a (non-)color. /*! \details with same effect as svg_color my_blank(blank); svg_color(true) means default (black?) svg_color(false) means blank. For example: plot.area_fill(false) will be a blank == no fill. plot.area_fill(true) will be a default(black) fill. */ r = 0; // Safer to assi
gn *some* value to rgb: zero, or 255 or something, g = 0; // rather than leaving them random. b = 0; // Default 'blank' color 0,0,0 is black. } // svg_color(bool is) svg_color(svg_color_constant col) { //! Set a color, including blank. if (col == blank) { // NotAColor. is_blank = true; r = 255; // Safer to assign *some* value to rgb: zero, or 255 or something, g = 255; // rather than leaving them random. b = 255; // Default 'blank' color here is white. } else { // Proper color. is_blank = false; constant_to_rgb(col, r, g, b); } } void write(std::ostream& os) { //! Write to ostream a color in svg format.. if(!is_blank) { os << "rgb(" << (unsigned int)r << "," << (unsigned int) g << "," << (unsigned int)b << ")" ; } else { os << "none"; } //! \details Usage: my_color.write(cout); cout << endl; outputs: rgb(127,255,212) } // void write(std::
ostream& os) bool operator== (const svg_color& rhs) { //! Compare colors (for equal) if ((is_blank) && (rhs.is_blank == true)) { // Both blank return true; } return (r == rhs.r) && (g == rhs.g) && (b == rhs.b); } bool operator!= (const svg_color& rhs) { //! Compare colors (for not equal). if ((is_blank) || (rhs.is_blank == true)) { return true; } return (r != rhs.r) || (g != rhs.g) || (b != rhs.b); } }; // struct svg_color // Note operator== and operator<< are both needed to use Boost.Test. bool operator== (const svg_color& lhs, const svg_color& rhs) { //! Compare colors (for equal) // Note operator== and operator << both needed to use Boost.Test. if ((rhs.is_blank == true) && (rhs.is_blank == true)) { // Both blank. return true; } return (lhs.r == rhs.r) && (lhs.g == rhs.g) && (lhs.b == rhs.b); } bool operator!= (const svg_color& lhs, const svg_color& rhs) { //! Compare colors (for not equal). // Note oper
ator== and operator << both needed to use Boost.Test. if ((rhs.is_blank == true) || (rhs.is_blank == true)) { return true; } return (lhs.r == rhs.r) || (lhs.g == rhs.g) || (lhs.b == rhs.b); } std::ostream& operator<< (std::ostream& os, const svg_color& color) { //! Output color to stream. if(!color.is_blank) { os << "RGB(" // Note deliberate uppercase to show difference between write and operator<< << (unsigned int)color.r << "," << (unsigned int)color.g << "," << (unsigned int)color.b << ")" ; } else { os << "blank"; } /*! Usage: svg_color my_color(127, 255, 212); cout << "my_color " << my_color << endl; Outputs: my_color RGB(127,255,212) cout << "magenta " << svg_color(magenta) << endl; but caution! cout << magenta << endl; outputs 85 because magenta is an enum! */ return os; } // std::ostream& operator<< svg_color color_array[] = { //! SVG standard colors, see also enum svg_color_constant. svg_color(24
0, 248, 255), // aliceblue
+ // Forward declarations in this module (see svg_fwd):
+
+ struct svg_color;
+ void constant_to_rgb(svg_color_constant c, unsigned char& r, unsigned char& g, unsigned char& b);
+ std::ostream& operator<< (std::ostream&, const svg_color&);
+ // --------------------------------------------------------------------
+ // svg_color is the struct that contains information about RGB colors.
+ // // For the constructor, the SVG standard specifies that numbers
+ // outside the normal rgb range are to be accepted,
+ // but are constrained to acceptable range of integer values [0, 255].
+ // --------------------------------------------------------------------
+
+ struct svg_color
+ //!< SVG standard colors, see also enum \#boost::svg::svg_color_constant.
+ {
+ friend std::ostream& operator<< (std::ostream& os, const svg_color& rhs);
+
+ unsigned char r; //!< unsigned char provides range [0 to 255].
+
+ unsigned char g; unsigned char b;
+
+ bool is_blank; // true means "Not to be displayed" a 'pseudo-color'.
+ // If true should display & write as "none".
+ svg_color(int red, int green, int blue) : is_blank(false)
+ { /*! \brief Construct a color from RGB values.
+ \details Constrain rgb to [0 .. 255].
+ Default is to construct a blank 'pseudo-color'.
+ */
+ red = ( red < 0 ) ? 0 : red;
+ green = ( green < 0 ) ? 0 : green;
+ blue = ( blue < 0 ) ? 0 : blue;
+ r = (unsigned char)(( red > 255 ) ? 255 : red);
+ g = (unsigned char)(( green > 255 ) ? 255 : green);
+ b = (unsigned char)(( blue > 255 ) ? 255 : blue);
+ } // svg_color(int red, int green, int blue)
+
+ svg_color(bool is) : is_blank(!is)
+ { //! Constructor from bool permits svg_color my_blank(false) as a (non-)color.
+ /*! \details with same effect as svg_color my_blank(blank);
+ svg_color(true) means default (black?)
+ svg_color(false) means blank.
+ For example:
+ plot.area_fill(false) will be a blank == no fill.
+ plot.area_fill(true) will be a default(black) fill.
+ */ r = 0; // Safer to assign *some* value to rgb: zero, or 255 or something,
+ g = 0; // rather than leaving them random.
+ b = 0; // Default 'blank' color 0,0,0 is black.
+ } // svg_color(bool is)
+
+ svg_color(svg_color_constant col)
+ { //! Set a color, including blank.
+ if (col == blank)
+ { // NotAColor.
+ is_blank = true;
+ r = 255; // Safer to assign *some* value to rgb: zero, or 255 or something,
+ g = 255; // rather than leaving them random.
+ b = 255; // Default 'blank' color here is white.
+ }
+ else
+ { // Proper color.
+ is_blank = false;
+ constant_to_rgb(col, r, g, b);
+ }
+ }
+ void write(std::ostream& os)
+ { //! Write to ostream a color in svg format..
+ if(!is_blank)
+ {
+ os << "rgb(" << (unsigned int)r << ","
+ << (unsigned int) g << ","
+ << (unsigned int)b << ")" ;
+ }
+ else
+ {
+ os << "none";
+ }
+
+ //! \details Usage: my_color.write(cout); cout << endl; outputs: rgb(127,255,212)
+ } // void write(std::ostream& os)
+
+ bool operator== (const svg_color& rhs)
+ {
+ //! Compare colors (for equal)
+ if ((is_blank) && (rhs.is_blank == true))
+ { // Both blank
+ return true;
+ }
+ return (r == rhs.r) && (g == rhs.g) && (b == rhs.b);
+ }
+
+ bool operator!= (const svg_color& rhs)
+ { //! Compare colors (for not equal).
+ if ((is_blank) || (rhs.is_blank == true))
+ {
+ return true;
+ }
+ return (r != rhs.r) || (g != rhs.g) || (b != rhs.b);
+ }
+ }; // struct svg_color
+
+ // Note operator== and operator<< are both needed to use Boost.Test.
+ bool operator== (const svg_color& lhs, const svg_color& rhs)
+ { //! Compare colors (for equal)
+ // Note operator== and operator << both needed to use Boost.Test.
+ if ((rhs.is_blank == true) && (rhs.is_blank == true))
+ {
+ // Both blank.
+ return true;
+ }
+ return (lhs.r == rhs.r) && (lhs.g == rhs.g) && (lhs.b == rhs.b);
+ }
+
+ bool operator!= (const svg_color& lhs, const svg_color& rhs)
+ { //! Compare colors (for not equal).
+ // Note operator== and operator << both needed to use Boost.Test.
+ if ((rhs.is_blank == true) || (rhs.is_blank == true))
+ {
+ return true;
+ }
+ return (lhs.r == rhs.r) || (lhs.g == rhs.g) || (lhs.b == rhs.b);
+ }
+
+ std::ostream& operator<< (std::ostream& os, const svg_color& color)
+ { //! Output color to stream.
+ if(!color.is_blank)
+ {
+ os << "RGB(" // Note deliberate uppercase to show difference between write and operator<<
+ << (unsigned int)color.r << ","
+ << (unsigned int)color.g << ","
+ << (unsigned int)color.b << ")" ;
+ }
+ else
+ {
+ os << "blank";
+ } /*! Usage: svg_color my_color(127, 255, 212); cout << "my_color " << my_color << endl;
+ Outputs: my_color RGB(127,255,212) cout << "magenta " << svg_color(magenta) << endl;
+ but caution! cout << magenta << endl; outputs 85 because magenta is an enum! */
+ return os;
+ } // std::ostream& operator<<
+
+ svg_color color_array[] =
+ { //! SVG standard colors, see also enum svg_color_constant.
+ svg_color(240, 248, 255), // aliceblue
     svg_color(250, 235, 215), // antiquewhite
     svg_color(0 , 255, 255), // aqua
     svg_color(127, 255, 212), // aquamarine [4]


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk