Stream support for FPoint and FRect

This commit is contained in:
Markus Gans 2018-04-16 02:24:37 +02:00
parent 73ba1bc219
commit 06627f6737
8 changed files with 133 additions and 8 deletions

View File

@ -1,5 +1,7 @@
2017-04-15 Markus Gans <guru.mail@muenster.de> 2017-04-15 Markus Gans <guru.mail@muenster.de>
* Fake-reverse bugfix in FOptiAttr * Fake-reverse bugfix in FOptiAttr
* Strict use of fc::colornames in FOptiAttr
* Stream support for FPoint and FRect
2017-04-11 Markus Gans <guru.mail@muenster.de> 2017-04-11 Markus Gans <guru.mail@muenster.de>
* Remove Cygwin bold color quirks fix in FOptiAttr * Remove Cygwin bold color quirks fix in FOptiAttr

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * 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 * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -35,6 +35,8 @@
#error "Only <final/final.h> can be included directly." #error "Only <final/final.h> can be included directly."
#endif #endif
#include <iostream>
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// class FPoint // 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&, const FPoint&); friend inline FPoint operator - (const FPoint&, const FPoint&);
friend inline FPoint operator - (const FPoint&); friend inline FPoint operator - (const FPoint&);
friend std::ostream& operator << (std::ostream&, const FPoint&);
friend std::istream& operator >> (std::istream&, FPoint&);
// Accessors // Accessors
virtual const char* getClassName(); virtual const char* getClassName();

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * 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 * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * 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 FRect operator - (const FRect&, const FPoint&);
friend bool operator == (const FRect&, const FRect&); friend bool operator == (const FRect&, const FRect&);
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 // Accessors
virtual const char* getClassName(); virtual const char* getClassName();

View File

@ -205,10 +205,10 @@ class FString
friend const FString operator + (const char, const FString&); friend const FString operator + (const char, const FString&);
friend const FString operator + (const FString&, const char); friend const FString operator + (const FString&, const char);
friend std::ostream& operator << (std::ostream& outstr, const FString& s); friend std::ostream& operator << (std::ostream&, const FString&);
friend std::istream& operator >> (std::istream& instr, FString& s); friend std::istream& operator >> (std::istream&, FString& s);
friend std::wostream& operator << (std::wostream& outstr, const FString& s); friend std::wostream& operator << (std::wostream&, const FString&);
friend std::wistream& operator >> (std::wistream& instr, FString& s); friend std::wistream& operator >> (std::wistream&, FString&);
// Accessor // Accessor
virtual const char* getClassName(); virtual const char* getClassName();

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * 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 * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * 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; 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;
}

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * 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 * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * 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.X2 != r2.X2
|| r1.Y2 != r2.Y2; || 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;
}

View File

@ -55,6 +55,8 @@ class FPointTest : public CPPUNIT_NS::TestFixture
void additionTest(); void additionTest();
void subtractionTest(); void subtractionTest();
void referenceTest(); void referenceTest();
void streamInsertionTest();
void streamExtractionTest();
private: private:
// Adds code needed to register the test suite // Adds code needed to register the test suite
@ -72,6 +74,8 @@ class FPointTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST (additionTest); CPPUNIT_TEST (additionTest);
CPPUNIT_TEST (subtractionTest); CPPUNIT_TEST (subtractionTest);
CPPUNIT_TEST (referenceTest); CPPUNIT_TEST (referenceTest);
CPPUNIT_TEST (streamInsertionTest);
CPPUNIT_TEST (streamExtractionTest);
// End of test suite definition // End of test suite definition
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
@ -278,6 +282,39 @@ void FPointTest::referenceTest()
CPPUNIT_ASSERT ( p1.getY() == 4 ); 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 // Put the test suite in the registry
CPPUNIT_TEST_SUITE_REGISTRATION (FPointTest); CPPUNIT_TEST_SUITE_REGISTRATION (FPointTest);

View File

@ -58,6 +58,8 @@ class FRectTest : public CPPUNIT_NS::TestFixture
void overlapTest(); void overlapTest();
void intersectTest(); void intersectTest();
void combinedTest(); void combinedTest();
void streamInsertionTest();
void streamExtractionTest();
private: private:
// Adds code needed to register the test suite // Adds code needed to register the test suite
@ -78,6 +80,8 @@ class FRectTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST (overlapTest); CPPUNIT_TEST (overlapTest);
CPPUNIT_TEST (intersectTest); CPPUNIT_TEST (intersectTest);
CPPUNIT_TEST (combinedTest); CPPUNIT_TEST (combinedTest);
CPPUNIT_TEST (streamInsertionTest);
CPPUNIT_TEST (streamExtractionTest);
// End of test suite definition // End of test suite definition
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
@ -480,6 +484,43 @@ void FRectTest::combinedTest()
CPPUNIT_ASSERT ( r3.getY2() == 7 ); 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 // Put the test suite in the registry
CPPUNIT_TEST_SUITE_REGISTRATION (FRectTest); CPPUNIT_TEST_SUITE_REGISTRATION (FRectTest);