summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorsten Behrens <tbehrens@suse.com>2013-03-20 13:26:37 +0100
committerThorsten Behrens <tbehrens@suse.com>2013-03-20 13:29:20 +0100
commit46b56dd6d422dfae325dee2b47b395e62817db1a (patch)
tree4f3e7eb6d819c1a027fe6f081b4196e3b9a1e751
parent62344016de056965a58ea2016d912a68eac0d6b0 (diff)
Fix loplugin warning.
Unused mutices in basegfx, turns out that was a rather broken attempt to guard lazy-init statics. Implemented properly with rtl::Static now. Change-Id: Icefe82a53ef6ed33114732a6bb70f9aa0c28b55e
-rw-r--r--basegfx/source/polygon/b2dpolygontools.cxx116
-rw-r--r--basegfx/source/polygon/b3dpolypolygontools.cxx240
2 files changed, 182 insertions, 174 deletions
diff --git a/basegfx/source/polygon/b2dpolygontools.cxx b/basegfx/source/polygon/b2dpolygontools.cxx
index 56176e5755de..24affdfb84c9 100644
--- a/basegfx/source/polygon/b2dpolygontools.cxx
+++ b/basegfx/source/polygon/b2dpolygontools.cxx
@@ -32,7 +32,6 @@
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <basegfx/curve/b2dbeziertools.hxx>
#include <basegfx/matrix/b2dhommatrixtools.hxx>
-#include <osl/mutex.hxx>
#include <numeric>
#include <limits>
@@ -1769,31 +1768,65 @@ namespace basegfx
return aUnitCircle;
}
+ namespace
+ {
+ struct theUnitHalfCircle :
+ public rtl::StaticWithInit<B2DPolygon, theUnitHalfCircle>
+ {
+ B2DPolygon operator()()
+ {
+ B2DPolygon aUnitHalfCircle;
+ const double fKappa((M_SQRT2 - 1.0) * 4.0 / 3.0);
+ const double fScaledKappa(fKappa * (1.0 / STEPSPERQUARTER));
+ const B2DHomMatrix aRotateMatrix(createRotateB2DHomMatrix(F_PI2 / STEPSPERQUARTER));
+ B2DPoint aPoint(1.0, 0.0);
+ B2DPoint aForward(1.0, fScaledKappa);
+ B2DPoint aBackward(1.0, -fScaledKappa);
+
+ aUnitHalfCircle.append(aPoint);
+
+ for(sal_uInt32 a(0); a < STEPSPERQUARTER * 2; a++)
+ {
+ aPoint *= aRotateMatrix;
+ aBackward *= aRotateMatrix;
+ aUnitHalfCircle.appendBezierSegment(aForward, aBackward, aPoint);
+ aForward *= aRotateMatrix;
+ }
+ return aUnitHalfCircle;
+ }
+ };
+ }
+
B2DPolygon createHalfUnitCircle()
{
- static B2DPolygon aUnitHalfCircle;
+ return theUnitHalfCircle::get();
+ }
- if(!aUnitHalfCircle.count())
+ namespace
+ {
+ struct theUnitCircleStartQuadrantOne :
+ public rtl::StaticWithInit<B2DPolygon, theUnitCircleStartQuadrantOne>
{
- const double fKappa((M_SQRT2 - 1.0) * 4.0 / 3.0);
- const double fScaledKappa(fKappa * (1.0 / STEPSPERQUARTER));
- const B2DHomMatrix aRotateMatrix(createRotateB2DHomMatrix(F_PI2 / STEPSPERQUARTER));
- B2DPoint aPoint(1.0, 0.0);
- B2DPoint aForward(1.0, fScaledKappa);
- B2DPoint aBackward(1.0, -fScaledKappa);
+ B2DPolygon operator()() { return impCreateUnitCircle(1); }
+ };
- aUnitHalfCircle.append(aPoint);
+ struct theUnitCircleStartQuadrantTwo :
+ public rtl::StaticWithInit<B2DPolygon, theUnitCircleStartQuadrantTwo>
+ {
+ B2DPolygon operator()() { return impCreateUnitCircle(2); }
+ };
- for(sal_uInt32 a(0); a < STEPSPERQUARTER * 2; a++)
- {
- aPoint *= aRotateMatrix;
- aBackward *= aRotateMatrix;
- aUnitHalfCircle.appendBezierSegment(aForward, aBackward, aPoint);
- aForward *= aRotateMatrix;
- }
- }
+ struct theUnitCircleStartQuadrantThree :
+ public rtl::StaticWithInit<B2DPolygon, theUnitCircleStartQuadrantThree>
+ {
+ B2DPolygon operator()() { return impCreateUnitCircle(3); }
+ };
- return aUnitHalfCircle;
+ struct theUnitCircleStartQuadrantZero :
+ public rtl::StaticWithInit<B2DPolygon, theUnitCircleStartQuadrantZero>
+ {
+ B2DPolygon operator()() { return impCreateUnitCircle(0); }
+ };
}
B2DPolygon createPolygonFromUnitCircle(sal_uInt32 nStartQuadrant)
@@ -1801,53 +1834,16 @@ namespace basegfx
switch(nStartQuadrant % 4)
{
case 1 :
- {
- static B2DPolygon aUnitCircleStartQuadrantOne;
-
- if(!aUnitCircleStartQuadrantOne.count())
- {
- ::osl::Mutex m_mutex;
- aUnitCircleStartQuadrantOne = impCreateUnitCircle(1);
- }
+ return theUnitCircleStartQuadrantOne::get();
- return aUnitCircleStartQuadrantOne;
- }
case 2 :
- {
- static B2DPolygon aUnitCircleStartQuadrantTwo;
-
- if(!aUnitCircleStartQuadrantTwo.count())
- {
- ::osl::Mutex m_mutex;
- aUnitCircleStartQuadrantTwo = impCreateUnitCircle(2);
- }
+ return theUnitCircleStartQuadrantTwo::get();
- return aUnitCircleStartQuadrantTwo;
- }
case 3 :
- {
- static B2DPolygon aUnitCircleStartQuadrantThree;
-
- if(!aUnitCircleStartQuadrantThree.count())
- {
- ::osl::Mutex m_mutex;
- aUnitCircleStartQuadrantThree = impCreateUnitCircle(3);
- }
+ return theUnitCircleStartQuadrantThree::get();
- return aUnitCircleStartQuadrantThree;
- }
default : // case 0 :
- {
- static B2DPolygon aUnitCircleStartQuadrantZero;
-
- if(!aUnitCircleStartQuadrantZero.count())
- {
- ::osl::Mutex m_mutex;
- aUnitCircleStartQuadrantZero = impCreateUnitCircle(0);
- }
-
- return aUnitCircleStartQuadrantZero;
- }
+ return theUnitCircleStartQuadrantZero::get();
}
}
diff --git a/basegfx/source/polygon/b3dpolypolygontools.cxx b/basegfx/source/polygon/b3dpolypolygontools.cxx
index 660d43288ae2..dd7fa412235e 100644
--- a/basegfx/source/polygon/b3dpolypolygontools.cxx
+++ b/basegfx/source/polygon/b3dpolypolygontools.cxx
@@ -17,6 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <rtl/instance.hxx>
#include <basegfx/polygon/b3dpolypolygontools.hxx>
#include <basegfx/range/b3drange.hxx>
#include <basegfx/polygon/b3dpolypolygon.hxx>
@@ -25,7 +26,6 @@
#include <numeric>
#include <basegfx/matrix/b3dhommatrix.hxx>
#include <basegfx/numeric/ftools.hxx>
-#include <osl/mutex.hxx>
//////////////////////////////////////////////////////////////////////////////
// predefines
@@ -53,127 +53,139 @@ namespace basegfx
return aRetval;
}
- B3DPolyPolygon createUnitCubePolyPolygon()
+ namespace
{
- static B3DPolyPolygon aRetval;
- ::osl::Mutex m_mutex;
-
- if(!aRetval.count())
+ struct theUnitCubePolyPolygon : public rtl::StaticWithInit<B3DPolyPolygon,
+ theUnitCubePolyPolygon>
{
- B3DPolygon aTemp;
- aTemp.append(B3DPoint(0.0, 0.0, 1.0));
- aTemp.append(B3DPoint(0.0, 1.0, 1.0));
- aTemp.append(B3DPoint(1.0, 1.0, 1.0));
- aTemp.append(B3DPoint(1.0, 0.0, 1.0));
- aTemp.setClosed(true);
- aRetval.append(aTemp);
-
- aTemp.clear();
- aTemp.append(B3DPoint(0.0, 0.0, 0.0));
- aTemp.append(B3DPoint(0.0, 1.0, 0.0));
- aTemp.append(B3DPoint(1.0, 1.0, 0.0));
- aTemp.append(B3DPoint(1.0, 0.0, 0.0));
- aTemp.setClosed(true);
- aRetval.append(aTemp);
-
- aTemp.clear();
- aTemp.append(B3DPoint(0.0, 0.0, 0.0));
- aTemp.append(B3DPoint(0.0, 0.0, 1.0));
- aRetval.append(aTemp);
-
- aTemp.clear();
- aTemp.append(B3DPoint(0.0, 1.0, 0.0));
- aTemp.append(B3DPoint(0.0, 1.0, 1.0));
- aRetval.append(aTemp);
-
- aTemp.clear();
- aTemp.append(B3DPoint(1.0, 1.0, 0.0));
- aTemp.append(B3DPoint(1.0, 1.0, 1.0));
- aRetval.append(aTemp);
-
- aTemp.clear();
- aTemp.append(B3DPoint(1.0, 0.0, 0.0));
- aTemp.append(B3DPoint(1.0, 0.0, 1.0));
- aRetval.append(aTemp);
- }
-
- return aRetval;
+ B3DPolyPolygon operator()()
+ {
+ B3DPolyPolygon aRetval;
+ B3DPolygon aTemp;
+ aTemp.append(B3DPoint(0.0, 0.0, 1.0));
+ aTemp.append(B3DPoint(0.0, 1.0, 1.0));
+ aTemp.append(B3DPoint(1.0, 1.0, 1.0));
+ aTemp.append(B3DPoint(1.0, 0.0, 1.0));
+ aTemp.setClosed(true);
+ aRetval.append(aTemp);
+
+ aTemp.clear();
+ aTemp.append(B3DPoint(0.0, 0.0, 0.0));
+ aTemp.append(B3DPoint(0.0, 1.0, 0.0));
+ aTemp.append(B3DPoint(1.0, 1.0, 0.0));
+ aTemp.append(B3DPoint(1.0, 0.0, 0.0));
+ aTemp.setClosed(true);
+ aRetval.append(aTemp);
+
+ aTemp.clear();
+ aTemp.append(B3DPoint(0.0, 0.0, 0.0));
+ aTemp.append(B3DPoint(0.0, 0.0, 1.0));
+ aRetval.append(aTemp);
+
+ aTemp.clear();
+ aTemp.append(B3DPoint(0.0, 1.0, 0.0));
+ aTemp.append(B3DPoint(0.0, 1.0, 1.0));
+ aRetval.append(aTemp);
+
+ aTemp.clear();
+ aTemp.append(B3DPoint(1.0, 1.0, 0.0));
+ aTemp.append(B3DPoint(1.0, 1.0, 1.0));
+ aRetval.append(aTemp);
+
+ aTemp.clear();
+ aTemp.append(B3DPoint(1.0, 0.0, 0.0));
+ aTemp.append(B3DPoint(1.0, 0.0, 1.0));
+ aRetval.append(aTemp);
+ return aRetval;
+ }
+ };
}
- B3DPolyPolygon createUnitCubeFillPolyPolygon()
+ B3DPolyPolygon createUnitCubePolyPolygon()
{
- static B3DPolyPolygon aRetval;
- ::osl::Mutex m_mutex;
+ return theUnitCubePolyPolygon::get();
+ }
- if(!aRetval.count())
+ namespace
+ {
+ struct theUnitCubeFillPolyPolygon : public rtl::StaticWithInit<B3DPolyPolygon,
+ theUnitCubeFillPolyPolygon>
{
- B3DPolygon aTemp;
-
- // all points
- const B3DPoint A(0.0, 0.0, 0.0);
- const B3DPoint B(0.0, 1.0, 0.0);
- const B3DPoint C(1.0, 1.0, 0.0);
- const B3DPoint D(1.0, 0.0, 0.0);
- const B3DPoint E(0.0, 0.0, 1.0);
- const B3DPoint F(0.0, 1.0, 1.0);
- const B3DPoint G(1.0, 1.0, 1.0);
- const B3DPoint H(1.0, 0.0, 1.0);
-
- // create bottom
- aTemp.append(D);
- aTemp.append(A);
- aTemp.append(E);
- aTemp.append(H);
- aTemp.setClosed(true);
- aRetval.append(aTemp);
-
- // create front
- aTemp.clear();
- aTemp.append(B);
- aTemp.append(A);
- aTemp.append(D);
- aTemp.append(C);
- aTemp.setClosed(true);
- aRetval.append(aTemp);
-
- // create left
- aTemp.clear();
- aTemp.append(E);
- aTemp.append(A);
- aTemp.append(B);
- aTemp.append(F);
- aTemp.setClosed(true);
- aRetval.append(aTemp);
-
- // create top
- aTemp.clear();
- aTemp.append(C);
- aTemp.append(G);
- aTemp.append(F);
- aTemp.append(B);
- aTemp.setClosed(true);
- aRetval.append(aTemp);
-
- // create right
- aTemp.clear();
- aTemp.append(H);
- aTemp.append(G);
- aTemp.append(C);
- aTemp.append(D);
- aTemp.setClosed(true);
- aRetval.append(aTemp);
-
- // create back
- aTemp.clear();
- aTemp.append(F);
- aTemp.append(G);
- aTemp.append(H);
- aTemp.append(E);
- aTemp.setClosed(true);
- aRetval.append(aTemp);
- }
+ B3DPolyPolygon operator()()
+ {
+ B3DPolyPolygon aRetval;
+ B3DPolygon aTemp;
+
+ // all points
+ const B3DPoint A(0.0, 0.0, 0.0);
+ const B3DPoint B(0.0, 1.0, 0.0);
+ const B3DPoint C(1.0, 1.0, 0.0);
+ const B3DPoint D(1.0, 0.0, 0.0);
+ const B3DPoint E(0.0, 0.0, 1.0);
+ const B3DPoint F(0.0, 1.0, 1.0);
+ const B3DPoint G(1.0, 1.0, 1.0);
+ const B3DPoint H(1.0, 0.0, 1.0);
+
+ // create bottom
+ aTemp.append(D);
+ aTemp.append(A);
+ aTemp.append(E);
+ aTemp.append(H);
+ aTemp.setClosed(true);
+ aRetval.append(aTemp);
+
+ // create front
+ aTemp.clear();
+ aTemp.append(B);
+ aTemp.append(A);
+ aTemp.append(D);
+ aTemp.append(C);
+ aTemp.setClosed(true);
+ aRetval.append(aTemp);
+
+ // create left
+ aTemp.clear();
+ aTemp.append(E);
+ aTemp.append(A);
+ aTemp.append(B);
+ aTemp.append(F);
+ aTemp.setClosed(true);
+ aRetval.append(aTemp);
+
+ // create top
+ aTemp.clear();
+ aTemp.append(C);
+ aTemp.append(G);
+ aTemp.append(F);
+ aTemp.append(B);
+ aTemp.setClosed(true);
+ aRetval.append(aTemp);
+
+ // create right
+ aTemp.clear();
+ aTemp.append(H);
+ aTemp.append(G);
+ aTemp.append(C);
+ aTemp.append(D);
+ aTemp.setClosed(true);
+ aRetval.append(aTemp);
+
+ // create back
+ aTemp.clear();
+ aTemp.append(F);
+ aTemp.append(G);
+ aTemp.append(H);
+ aTemp.append(E);
+ aTemp.setClosed(true);
+ aRetval.append(aTemp);
+ return aRetval;
+ }
+ };
+ }
- return aRetval;
+ B3DPolyPolygon createUnitCubeFillPolyPolygon()
+ {
+ return theUnitCubeFillPolyPolygon::get();
}
B3DPolyPolygon createCubePolyPolygonFromB3DRange( const B3DRange& rRange)