diff --git a/ChangeLog b/ChangeLog index 9281e14e..04861213 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2017-04-15 Markus Gans * Fake-reverse bugfix in FOptiAttr + * Strict use of fc::colornames in FOptiAttr + * Stream support for FPoint and FRect 2017-04-11 Markus Gans * Remove Cygwin bold color quirks fix in FOptiAttr diff --git a/include/final/fpoint.h b/include/final/fpoint.h index e623c052..08c06b1c 100644 --- a/include/final/fpoint.h +++ b/include/final/fpoint.h @@ -3,7 +3,7 @@ * * * This file is part of the Final Cut widget toolkit * * * -* Copyright 2014-2017 Markus Gans * +* Copyright 2014-2018 Markus Gans * * * * The Final Cut is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public License * @@ -35,6 +35,8 @@ #error "Only can be included directly." #endif +#include + //---------------------------------------------------------------------- // class FPoint @@ -64,6 +66,8 @@ class FPoint friend inline FPoint operator + (const FPoint&, const FPoint&); friend inline FPoint operator - (const FPoint&, const FPoint&); friend inline FPoint operator - (const FPoint&); + friend std::ostream& operator << (std::ostream&, const FPoint&); + friend std::istream& operator >> (std::istream&, FPoint&); // Accessors virtual const char* getClassName(); diff --git a/include/final/frect.h b/include/final/frect.h index b073a5be..89a64c01 100644 --- a/include/final/frect.h +++ b/include/final/frect.h @@ -3,7 +3,7 @@ * * * This file is part of the Final Cut widget toolkit * * * -* Copyright 2014-2017 Markus Gans * +* Copyright 2014-2018 Markus Gans * * * * The Final Cut is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public License * @@ -65,6 +65,8 @@ class FRect friend FRect operator - (const FRect&, const FPoint&); friend bool operator == (const FRect&, const FRect&); friend bool operator != (const FRect&, const FRect&); + friend std::ostream& operator << (std::ostream&, const FRect&); + friend std::istream& operator >> (std::istream&, FRect&); // Accessors virtual const char* getClassName(); diff --git a/include/final/fstring.h b/include/final/fstring.h index ec5106be..fa637b59 100644 --- a/include/final/fstring.h +++ b/include/final/fstring.h @@ -205,10 +205,10 @@ class FString friend const FString operator + (const char, const FString&); friend const FString operator + (const FString&, const char); - friend std::ostream& operator << (std::ostream& outstr, const FString& s); - friend std::istream& operator >> (std::istream& instr, FString& s); - friend std::wostream& operator << (std::wostream& outstr, const FString& s); - friend std::wistream& operator >> (std::wistream& instr, FString& s); + friend std::ostream& operator << (std::ostream&, const FString&); + friend std::istream& operator >> (std::istream&, FString& s); + friend std::wostream& operator << (std::wostream&, const FString&); + friend std::wistream& operator >> (std::wistream&, FString&); // Accessor virtual const char* getClassName(); diff --git a/src/fpoint.cpp b/src/fpoint.cpp index 7ed43224..d3b66aa4 100644 --- a/src/fpoint.cpp +++ b/src/fpoint.cpp @@ -3,7 +3,7 @@ * * * This file is part of the Final Cut widget toolkit * * * -* Copyright 2014-2017 Markus Gans * +* Copyright 2014-2018 Markus Gans * * * * The Final Cut is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public License * @@ -79,3 +79,20 @@ bool FPoint::isNull() const { return xpos == 0 && ypos == 0; } + +//---------------------------------------------------------------------- +std::ostream& operator << (std::ostream& outstr, const FPoint& p) +{ + outstr << p.getX() << " " << p.getY(); + return outstr; +} + +//---------------------------------------------------------------------- +std::istream& operator >> (std::istream& instr, FPoint& p) +{ + short x, y; + instr >> x; + instr >> y; + p.setPoint (x, y); + return instr; +} diff --git a/src/frect.cpp b/src/frect.cpp index e9a53094..34d3a72c 100644 --- a/src/frect.cpp +++ b/src/frect.cpp @@ -3,7 +3,7 @@ * * * This file is part of the Final Cut widget toolkit * * * -* Copyright 2014-2017 Markus Gans * +* Copyright 2014-2018 Markus Gans * * * * The Final Cut is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public License * @@ -275,3 +275,25 @@ bool operator != (const FRect& r1, const FRect& r2) || r1.X2 != r2.X2 || r1.Y2 != r2.Y2; } + +//---------------------------------------------------------------------- +std::ostream& operator << (std::ostream& outstr, const FRect& r) +{ + outstr << r.getX1() << " " + << r.getY1() << " " + << r.getX2() << " " + << r.getY2(); + return outstr; +} + +//---------------------------------------------------------------------- +std::istream& operator >> (std::istream& instr, FRect& r) +{ + short x1, y1, x2, y2; + instr >> x1; + instr >> y1; + instr >> x2; + instr >> y2; + r.setCoordinates (x1, y1, x2, y2); + return instr; +} diff --git a/src/test/fpoint-test.cpp b/src/test/fpoint-test.cpp index e24d97d6..4f9295b8 100644 --- a/src/test/fpoint-test.cpp +++ b/src/test/fpoint-test.cpp @@ -55,6 +55,8 @@ class FPointTest : public CPPUNIT_NS::TestFixture void additionTest(); void subtractionTest(); void referenceTest(); + void streamInsertionTest(); + void streamExtractionTest(); private: // Adds code needed to register the test suite @@ -72,6 +74,8 @@ class FPointTest : public CPPUNIT_NS::TestFixture CPPUNIT_TEST (additionTest); CPPUNIT_TEST (subtractionTest); CPPUNIT_TEST (referenceTest); + CPPUNIT_TEST (streamInsertionTest); + CPPUNIT_TEST (streamExtractionTest); // End of test suite definition CPPUNIT_TEST_SUITE_END(); @@ -278,6 +282,39 @@ void FPointTest::referenceTest() CPPUNIT_ASSERT ( p1.getY() == 4 ); } +//---------------------------------------------------------------------- +void FPointTest::streamInsertionTest() +{ + FPoint out; + std::stringstream stream; + stream.str("10 5"); + stream >> out; + CPPUNIT_ASSERT ( out.getX() == 10 ); + CPPUNIT_ASSERT ( out.getY() == 5 ); + + stream.clear(); + stream.str("-3 -9"); + stream >> out; + CPPUNIT_ASSERT ( out.getX() == -3 ); + CPPUNIT_ASSERT ( out.getY() == -9 ); +} + +//---------------------------------------------------------------------- +void FPointTest::streamExtractionTest() +{ + FPoint in; + in.setPoint (-7, 5); + std::stringstream stream; + stream << in; + CPPUNIT_ASSERT ( stream.str() == "-7 5" ); + + in.setPoint (127, 150); + stream.clear(); + stream.str(""); + stream << in; + CPPUNIT_ASSERT ( stream.str() == "127 150" ); +} + // Put the test suite in the registry CPPUNIT_TEST_SUITE_REGISTRATION (FPointTest); diff --git a/src/test/frect-test.cpp b/src/test/frect-test.cpp index 0a5e8505..157e90a7 100644 --- a/src/test/frect-test.cpp +++ b/src/test/frect-test.cpp @@ -58,6 +58,8 @@ class FRectTest : public CPPUNIT_NS::TestFixture void overlapTest(); void intersectTest(); void combinedTest(); + void streamInsertionTest(); + void streamExtractionTest(); private: // Adds code needed to register the test suite @@ -78,6 +80,8 @@ class FRectTest : public CPPUNIT_NS::TestFixture CPPUNIT_TEST (overlapTest); CPPUNIT_TEST (intersectTest); CPPUNIT_TEST (combinedTest); + CPPUNIT_TEST (streamInsertionTest); + CPPUNIT_TEST (streamExtractionTest); // End of test suite definition CPPUNIT_TEST_SUITE_END(); @@ -480,6 +484,43 @@ void FRectTest::combinedTest() CPPUNIT_ASSERT ( r3.getY2() == 7 ); } +//---------------------------------------------------------------------- +void FRectTest::streamInsertionTest() +{ + FRect out; + std::stringstream stream; + stream.str("10 5 60 20"); + stream >> out; + CPPUNIT_ASSERT ( out.getX1() == 10 ); + CPPUNIT_ASSERT ( out.getY1() == 5 ); + CPPUNIT_ASSERT ( out.getX2() == 60 ); + CPPUNIT_ASSERT ( out.getY2() == 20 ); + + stream.clear(); + stream.str("-3 -9 5 7"); + stream >> out; + CPPUNIT_ASSERT ( out.getX1() == -3 ); + CPPUNIT_ASSERT ( out.getY1() == -9 ); + CPPUNIT_ASSERT ( out.getX2() == 5 ); + CPPUNIT_ASSERT ( out.getY2() == 7 ); +} + +//---------------------------------------------------------------------- +void FRectTest::streamExtractionTest() +{ + FRect in; + in.setCoordinates (-7, 5, -1, 10); + std::stringstream stream; + stream << in; + CPPUNIT_ASSERT ( stream.str() == "-7 5 -1 10" ); + + in.setCoordinates (50, 100, 127, 150); + stream.clear(); + stream.str(""); + stream << in; + CPPUNIT_ASSERT ( stream.str() == "50 100 127 150" ); +} + // Put the test suite in the registry CPPUNIT_TEST_SUITE_REGISTRATION (FRectTest);