Move ostream operators into global namespace

This commit is contained in:
Danny Robson 2013-08-05 16:37:11 +10:00
parent 63637768ce
commit b4dda9b9fa
2 changed files with 13 additions and 10 deletions

View File

@ -14,11 +14,13 @@
* You should have received a copy of the GNU General Public License
* along with libgim. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2010 Danny Robson <danny@nerdcruft.net>
* Copyright 2010-2013 Danny Robson <danny@nerdcruft.net>
*/
#include "colour.hpp"
#include "range.hpp"
#include "random.hpp"
//-----------------------------------------------------------------------------
@ -35,8 +37,12 @@ const util::colour util::colour::BLUE ({ 0.0, 0.0, 1.0, 1.0 });
//-----------------------------------------------------------------------------
//! Extract a colour object from a JSON node.
//!
//! Data must be an array or 3 or 4 numbers. Guarantees success, or throws a
//! json::type_error.
const json::node&
util::operator>> (const json::node &node, colour &c) {
operator>> (const json::node &node, colour &c) {
c.red = node[0].as_number ();
c.green = node[1].as_number ();
c.blue = node[2].as_number ();
@ -71,7 +77,7 @@ namespace util {
//-----------------------------------------------------------------------------
std::ostream&
util::operator<< (std::ostream &os, const util::colour &c) {
operator<< (std::ostream &os, const util::colour &c) {
os << "colour(" << c.red << ", " << c.green << ", " << c.blue << ", " << c.alpha << ")";
return os;
}

View File

@ -14,18 +14,18 @@
* You should have received a copy of the GNU General Public License
* along with libgim. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2010 Danny Robson <danny@nerdcruft.net>
* Copyright 2010-2013 Danny Robson <danny@nerdcruft.net>
*/
#ifndef __UTIL_COLOUR_HPP
#define __UTIL_COLOUR_HPP
#include "json.hpp"
#include "random.hpp"
#include <iostream>
namespace util {
/// An RGBA colour POD type.
struct colour {
double red;
double green;
@ -39,12 +39,9 @@ namespace util {
static const colour GREEN;
};
template <> colour& randomise (colour&);
template <> colour& random (void);
std::ostream& operator<< (std::ostream&, const util::colour&);
const json::node& operator>> (const json::node&, util::colour&);
}
std::ostream& operator<< (std::ostream&, const util::colour&);
const json::node& operator>> (const json::node&, util::colour&);
#endif