[mapguide-commits] r1186 - in trunk/MgDev/Common: Geometry Geometry/CoordinateSystem Geometry/Parse Geometry/Spatial PlatformBase/MapLayer

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Thu Mar 8 19:12:31 EST 2007


Author: waltweltonlair
Date: 2007-03-08 19:12:31 -0500 (Thu, 08 Mar 2007)
New Revision: 1186

Modified:
   trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystem.cpp
   trunk/MgDev/Common/Geometry/GeometryUtil.cpp
   trunk/MgDev/Common/Geometry/GeosUtil.cpp
   trunk/MgDev/Common/Geometry/Parse/ParseAwkt.cpp
   trunk/MgDev/Common/Geometry/Parse/ParseAwktUtil.cpp
   trunk/MgDev/Common/Geometry/Spatial/SpatialUtility.cpp
   trunk/MgDev/Common/PlatformBase/MapLayer/SelectionBase.cpp
Log:
Some smart pointer cleanup.

Silly code:
    Ptr<MyClass*> myClass = (MyClass*)NULL;
Better code:
    Ptr<MyClass*> myClass;

Silly code:
    Ptr<MyClass*> myClass = ...;
    ...
    return SAFE_ADDREF((MyClass*)myClass);
Better code:
    Ptr<MyClass*> myClass = ...;
    ...
    return myClass.Detach();


Modified: trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystem.cpp
===================================================================
--- trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystem.cpp	2007-03-08 22:58:19 UTC (rev 1185)
+++ trunk/MgDev/Common/Geometry/CoordinateSystem/CoordinateSystem.cpp	2007-03-09 00:12:31 UTC (rev 1186)
@@ -1086,7 +1086,7 @@
                     if(coordSysInfo)
                     {
                         // Add the coodinate system properties to the collection
-                        Ptr<MgProperty> pProperty = (MgProperty*)NULL;
+                        Ptr<MgProperty> pProperty;
                         Ptr<MgPropertyCollection> coordSysProperties = new MgPropertyCollection();
 
                         // Coordinate system properties

Modified: trunk/MgDev/Common/Geometry/GeometryUtil.cpp
===================================================================
--- trunk/MgDev/Common/Geometry/GeometryUtil.cpp	2007-03-08 22:58:19 UTC (rev 1185)
+++ trunk/MgDev/Common/Geometry/GeometryUtil.cpp	2007-03-09 00:12:31 UTC (rev 1186)
@@ -116,7 +116,7 @@
 //
 MgCurveSegment* MgGeometryUtil::ReadCurveSegment(MgStream* stream, MgCoordinate* startCoord, INT32 dimension)
 {
-    Ptr<MgCurveSegment> curveSeg = (MgCurveSegment*)NULL;
+    Ptr<MgCurveSegment> curveSeg;
 
     INT32 type;
     ((MgStreamReader*)stream)->GetInt32(type);

Modified: trunk/MgDev/Common/Geometry/GeosUtil.cpp
===================================================================
--- trunk/MgDev/Common/Geometry/GeosUtil.cpp	2007-03-08 22:58:19 UTC (rev 1185)
+++ trunk/MgDev/Common/Geometry/GeosUtil.cpp	2007-03-09 00:12:31 UTC (rev 1186)
@@ -45,12 +45,11 @@
 bool MgGeosUtil::Contains(MgGeometry* geom1, MgGeometry* geom2)
 {
     bool contains = false;
+    PrecisionModel* pm = NULL;
+    GeometryFactory* gf = NULL;
+    Geometry* g1 = NULL;
+    Geometry* g2 = NULL;
 
-    PrecisionModel* pm = (PrecisionModel*)NULL;
-    GeometryFactory* gf =(GeometryFactory*)NULL;
-    Geometry* g1 = (Geometry*)NULL;
-    Geometry* g2 = (Geometry*)NULL;
-
     MG_GEOMETRY_TRY()
 
     pm = new PrecisionModel();
@@ -83,10 +82,10 @@
 bool MgGeosUtil::Intersects(MgGeometry* geom1, MgGeometry* geom2)
 {
     bool intersects = false;
-    PrecisionModel* pm = (PrecisionModel*)NULL;
-    GeometryFactory* gf =(GeometryFactory*)NULL;
-    Geometry* g1 = (Geometry*)NULL;
-    Geometry* g2 = (Geometry*)NULL;
+    PrecisionModel* pm = NULL;
+    GeometryFactory* gf = NULL;
+    Geometry* g1 = NULL;
+    Geometry* g2 = NULL;
 
     MG_GEOMETRY_TRY()
 
@@ -120,10 +119,10 @@
 bool MgGeosUtil::Crosses(MgGeometry* geom1, MgGeometry* geom2)
 {
     bool crosses = false;
-    PrecisionModel* pm = (PrecisionModel*)NULL;
-    GeometryFactory* gf =(GeometryFactory*)NULL;
-    Geometry* g1 = (Geometry*)NULL;
-    Geometry* g2 = (Geometry*)NULL;
+    PrecisionModel* pm = NULL;
+    GeometryFactory* gf = NULL;
+    Geometry* g1 = NULL;
+    Geometry* g2 = NULL;
 
     MG_GEOMETRY_TRY()
 
@@ -157,10 +156,10 @@
 bool MgGeosUtil::Disjoint(MgGeometry* geom1, MgGeometry* geom2)
 {
     bool disjoint = false;
-    PrecisionModel* pm = (PrecisionModel*)NULL;
-    GeometryFactory* gf =(GeometryFactory*)NULL;
-    Geometry* g1 = (Geometry*)NULL;
-    Geometry* g2 = (Geometry*)NULL;
+    PrecisionModel* pm = NULL;
+    GeometryFactory* gf = NULL;
+    Geometry* g1 = NULL;
+    Geometry* g2 = NULL;
 
     MG_GEOMETRY_TRY()
 
@@ -194,12 +193,11 @@
 bool MgGeosUtil::Equals(MgGeometry* geom1, MgGeometry* geom2)
 {
     bool equals = false;
+    PrecisionModel* pm = NULL;
+    GeometryFactory* gf = NULL;
+    Geometry* g1 = NULL;
+    Geometry* g2 = NULL;
 
-    PrecisionModel* pm = (PrecisionModel*)NULL;
-    GeometryFactory* gf =(GeometryFactory*)NULL;
-    Geometry* g1 = (Geometry*)NULL;
-    Geometry* g2 = (Geometry*)NULL;
-
     MG_GEOMETRY_TRY()
 
     pm = new PrecisionModel();
@@ -232,10 +230,10 @@
 bool MgGeosUtil::Overlaps(MgGeometry* geom1, MgGeometry* geom2)
 {
     bool overlaps = false;
-    PrecisionModel* pm = (PrecisionModel*)NULL;
-    GeometryFactory* gf =(GeometryFactory*)NULL;
-    Geometry* g1 = (Geometry*)NULL;
-    Geometry* g2 = (Geometry*)NULL;
+    PrecisionModel* pm = NULL;
+    GeometryFactory* gf = NULL;
+    Geometry* g1 = NULL;
+    Geometry* g2 = NULL;
 
     MG_GEOMETRY_TRY()
 
@@ -269,12 +267,11 @@
 bool MgGeosUtil::Touches(MgGeometry* geom1, MgGeometry* geom2)
 {
     bool touches = false;
+    PrecisionModel* pm = NULL;
+    GeometryFactory* gf = NULL;
+    Geometry* g1 = NULL;
+    Geometry* g2 = NULL;
 
-    PrecisionModel* pm = (PrecisionModel*)NULL;
-    GeometryFactory* gf =(GeometryFactory*)NULL;
-    Geometry* g1 = (Geometry*)NULL;
-    Geometry* g2 = (Geometry*)NULL;
-
     MG_GEOMETRY_TRY()
 
     pm = new PrecisionModel();
@@ -307,12 +304,11 @@
 bool MgGeosUtil::Within(MgGeometry* geom1, MgGeometry* geom2)
 {
     bool within = false;
+    PrecisionModel* pm = NULL;
+    GeometryFactory* gf = NULL;
+    Geometry* g1 = NULL;
+    Geometry* g2 = NULL;
 
-    PrecisionModel* pm = (PrecisionModel*)NULL;
-    GeometryFactory* gf =(GeometryFactory*)NULL;
-    Geometry* g1 = (Geometry*)NULL;
-    Geometry* g2 = (Geometry*)NULL;
-
     MG_GEOMETRY_TRY()
 
     pm = new PrecisionModel();
@@ -344,13 +340,12 @@
 
 MgGeometry* MgGeosUtil::Boundary(MgGeometry* geom1)
 {
-    Ptr<MgGeometry> bndGeom = (MgGeometry*)NULL;
+    Ptr<MgGeometry> bndGeom;
+    PrecisionModel* pm = NULL;
+    GeometryFactory* gf = NULL;
+    Geometry* g1 = NULL;
+    Geometry* g3 = NULL;
 
-    PrecisionModel* pm = (PrecisionModel*)NULL;
-    GeometryFactory* gf =(GeometryFactory*)NULL;
-    Geometry* g1 = (Geometry*)NULL;
-    Geometry* g3 = (Geometry*)NULL;
-
     MG_GEOMETRY_TRY()
 
     pm = new PrecisionModel();
@@ -386,13 +381,12 @@
 
 MgGeometry* MgGeosUtil::ConvexHull(MgGeometry* geom1)
 {
-    Ptr<MgGeometry> convexHull = (MgGeometry*)NULL;
+    Ptr<MgGeometry> convexHull;
+    PrecisionModel* pm = NULL;
+    GeometryFactory* gf = NULL;
+    Geometry* g1 = NULL;
+    Geometry* g3 = NULL;
 
-    PrecisionModel* pm = (PrecisionModel*)NULL;
-    GeometryFactory* gf =(GeometryFactory*)NULL;
-    Geometry* g1 = (Geometry*)NULL;
-    Geometry* g3 = (Geometry*)NULL;
-
     MG_GEOMETRY_TRY()
 
     pm = new PrecisionModel();
@@ -428,12 +422,12 @@
 
 MgGeometry* MgGeosUtil::Difference(MgGeometry* geom1, MgGeometry* geom2)
 {
-    Ptr<MgGeometry> difference = (MgGeometry*)NULL;
-    PrecisionModel* pm = (PrecisionModel*)NULL;
-    GeometryFactory* gf =(GeometryFactory*)NULL;
-    Geometry* g1 = (Geometry*)NULL;
-    Geometry* g2 = (Geometry*)NULL;
-    Geometry* g3 = (Geometry*)NULL;
+    Ptr<MgGeometry> difference;
+    PrecisionModel* pm = NULL;
+    GeometryFactory* gf = NULL;
+    Geometry* g1 = NULL;
+    Geometry* g2 = NULL;
+    Geometry* g3 = NULL;
 
     MG_GEOMETRY_TRY()
 
@@ -477,10 +471,10 @@
 double MgGeosUtil::Distance(MgGeometry* geom1, MgGeometry* geom2)
 {
     double distance = 0.0;
-    PrecisionModel* pm = (PrecisionModel*)NULL;
-    GeometryFactory* gf =(GeometryFactory*)NULL;
-    Geometry* g1 = (Geometry*)NULL;
-    Geometry* g2 = (Geometry*)NULL;
+    PrecisionModel* pm = NULL;
+    GeometryFactory* gf = NULL;
+    Geometry* g1 = NULL;
+    Geometry* g2 = NULL;
 
     MG_GEOMETRY_TRY()
 
@@ -513,12 +507,12 @@
 
 MgGeometry* MgGeosUtil::Intersection(MgGeometry* geom1, MgGeometry* geom2)
 {
-    Ptr<MgGeometry> intersection = (MgGeometry*)NULL;
-    PrecisionModel* pm = (PrecisionModel*)NULL;
-    GeometryFactory* gf =(GeometryFactory*)NULL;
-    Geometry* g1 = (Geometry*)NULL;
-    Geometry* g2 = (Geometry*)NULL;
-    Geometry* g3 = (Geometry*)NULL;
+    Ptr<MgGeometry> intersection;
+    PrecisionModel* pm = NULL;
+    GeometryFactory* gf = NULL;
+    Geometry* g1 = NULL;
+    Geometry* g2 = NULL;
+    Geometry* g3 = NULL;
 
     MG_GEOMETRY_TRY()
 
@@ -560,14 +554,13 @@
 
 MgGeometry* MgGeosUtil::SymetricDifference(MgGeometry* geom1, MgGeometry* geom2)
 {
-    Ptr<MgGeometry> symetricDifference = (MgGeometry*)NULL;
-    PrecisionModel* pm = (PrecisionModel*)NULL;
-    GeometryFactory* gf =(GeometryFactory*)NULL;
+    Ptr<MgGeometry> symetricDifference;
+    PrecisionModel* pm = NULL;
+    GeometryFactory* gf = NULL;
+    Geometry* g1 = NULL;
+    Geometry* g2 = NULL;
+    Geometry* g3 = NULL;
 
-    Geometry* g1 = (Geometry*)NULL;
-    Geometry* g2 = (Geometry*)NULL;
-    Geometry* g3 = (Geometry*)NULL;
-
     MG_GEOMETRY_TRY()
 
     pm = new PrecisionModel();
@@ -608,14 +601,13 @@
 
 MgGeometry* MgGeosUtil::Union(MgGeometry* geom1, MgGeometry* geom2)
 {
-    Ptr<MgGeometry> unionGeom = (MgGeometry*)NULL;
-    PrecisionModel* pm = (PrecisionModel*)NULL;
-    GeometryFactory* gf =(GeometryFactory*)NULL;
+    Ptr<MgGeometry> unionGeom;
+    PrecisionModel* pm = NULL;
+    GeometryFactory* gf = NULL;
+    Geometry* g1 = NULL;
+    Geometry* g2 = NULL;
+    Geometry* g3 = NULL;
 
-    Geometry* g1 = (Geometry*)NULL;
-    Geometry* g2 = (Geometry*)NULL;
-    Geometry* g3 = (Geometry*)NULL;
-
     MG_GEOMETRY_TRY()
 
     pm = new PrecisionModel();
@@ -657,11 +649,10 @@
 bool MgGeosUtil::IsValid(MgGeometricEntity* geom1)
 {
     bool isValid = false;
+    PrecisionModel* pm = NULL;
+    GeometryFactory* gf = NULL;
+    Geometry* g1 = NULL;
 
-    PrecisionModel* pm = (PrecisionModel*)NULL;
-    GeometryFactory* gf =(GeometryFactory*)NULL;
-    Geometry* g1 = (Geometry*)NULL;
-
     MG_GEOMETRY_TRY()
 
     pm = new PrecisionModel();
@@ -687,11 +678,10 @@
 bool MgGeosUtil::IsSimple(MgGeometricEntity* geom1)
 {
     bool isSimple = false;
+    PrecisionModel* pm = NULL;
+    GeometryFactory* gf = NULL;
+    Geometry* g1 = NULL;
 
-    PrecisionModel* pm = (PrecisionModel*)NULL;
-    GeometryFactory* gf =(GeometryFactory*)NULL;
-    Geometry* g1 = (Geometry*)NULL;
-
     MG_GEOMETRY_TRY()
 
     pm = new PrecisionModel();
@@ -717,11 +707,10 @@
 bool MgGeosUtil::IsEmpty(MgGeometricEntity* geom1)
 {
     bool isEmpty = false;
+    PrecisionModel* pm = NULL;
+    GeometryFactory* gf = NULL;
+    Geometry* g1 = NULL;
 
-    PrecisionModel* pm = (PrecisionModel*)NULL;
-    GeometryFactory* gf =(GeometryFactory*)NULL;
-    Geometry* g1 = (Geometry*)NULL;
-
     MG_GEOMETRY_TRY()
 
     pm = new PrecisionModel();
@@ -747,11 +736,10 @@
 bool MgGeosUtil::IsClosed(MgGeometricEntity* geom1)
 {
     bool isClosed = false;
+    PrecisionModel* pm = NULL;
+    GeometryFactory* gf = NULL;
+    Geometry* g1 = NULL;
 
-    PrecisionModel* pm = (PrecisionModel*)NULL;
-    GeometryFactory* gf =(GeometryFactory*)NULL;
-    Geometry* g1 = (Geometry*)NULL;
-
     MG_GEOMETRY_TRY()
 
     pm = new PrecisionModel();
@@ -777,11 +765,10 @@
 double MgGeosUtil::Area(MgGeometricEntity* geom1)
 {
     double area = 0.0;
+    PrecisionModel* pm = NULL;
+    GeometryFactory* gf = NULL;
+    Geometry* g1 = NULL;
 
-    PrecisionModel* pm = (PrecisionModel*)NULL;
-    GeometryFactory* gf =(GeometryFactory*)NULL;
-    Geometry* g1 = (Geometry*)NULL;
-
     MG_GEOMETRY_TRY()
 
     pm = new PrecisionModel();
@@ -807,11 +794,10 @@
 double MgGeosUtil::Length(MgGeometricEntity* geom1)
 {
     double length = 0.0;
+    PrecisionModel* pm = NULL;
+    GeometryFactory* gf = NULL;
+    Geometry* g1 = NULL;
 
-    PrecisionModel* pm = (PrecisionModel*)NULL;
-    GeometryFactory* gf =(GeometryFactory*)NULL;
-    Geometry* g1 = (Geometry*)NULL;
-
     MG_GEOMETRY_TRY()
 
     pm = new PrecisionModel();
@@ -836,13 +822,12 @@
 
 MgPoint* MgGeosUtil::Centroid(MgGeometricEntity* geom1)
 {
-    Ptr<MgPoint> point = (MgPoint*)NULL;
+    Ptr<MgPoint> point;
+    PrecisionModel* pm = NULL;
+    GeometryFactory* gf = NULL;
+    Geometry* g1 = NULL;
+    Point* g2 = NULL;
 
-    PrecisionModel* pm = (PrecisionModel*)NULL;
-    GeometryFactory* gf =(GeometryFactory*)NULL;
-    Geometry* g1 = (Geometry*)NULL;
-    Point* g2 = (Point*)NULL;
-
     MG_GEOMETRY_TRY()
 
     pm = new PrecisionModel();
@@ -875,13 +860,12 @@
 
 MgPoint*  MgGeosUtil::GetPointInRegion(MgGeometry* geom1)
 {
-    Ptr<MgPoint> point = (MgPoint*)NULL;
+    Ptr<MgPoint> point;
+    PrecisionModel* pm = NULL;
+    GeometryFactory* gf = NULL;
+    Geometry* g1 = NULL;
+    Point* g2 = NULL;
 
-    PrecisionModel* pm = (PrecisionModel*)NULL;
-    GeometryFactory* gf =(GeometryFactory*)NULL;
-    Geometry* g1 = (Geometry*)NULL;
-    Point* g2 = (Point*)NULL;
-
     MG_GEOMETRY_TRY()
 
     pm = new PrecisionModel();
@@ -914,13 +898,12 @@
 
 MgPoint*  MgGeosUtil::GetPointInRing(MgGeometryComponent* geom1)
 {
-    Ptr<MgPoint> point = (MgPoint*)NULL;
+    Ptr<MgPoint> point;
+    PrecisionModel* pm = NULL;
+    GeometryFactory* gf = NULL;
+    Geometry* g1 = NULL;
+    Point* g2 = NULL;
 
-    PrecisionModel* pm = (PrecisionModel*)NULL;
-    GeometryFactory* gf =(GeometryFactory*)NULL;
-    Geometry* g1 = (Geometry*)NULL;
-    Point* g2 = (Point*)NULL;
-
     MG_GEOMETRY_TRY()
 
     pm = new PrecisionModel();

Modified: trunk/MgDev/Common/Geometry/Parse/ParseAwkt.cpp
===================================================================
--- trunk/MgDev/Common/Geometry/Parse/ParseAwkt.cpp	2007-03-08 22:58:19 UTC (rev 1185)
+++ trunk/MgDev/Common/Geometry/Parse/ParseAwkt.cpp	2007-03-09 00:12:31 UTC (rev 1186)
@@ -89,15 +89,15 @@
             __LINE__, __WFILE__, &arguments, L"MgInvalidAgfText", NULL);
     }
 
-    return SAFE_ADDREF((MgGeometry*)m_geometry);
+    return SAFE_ADDREF(m_geometry.p);
 }
 
 // count how many of the same type, starting at iContext and counting it
 // but don't move iContext forward (call by value)
 INT32 MgParseAwkt::CountSame(INT32 iContext, _types type)
 {
-    INT32   iResult = 0;
-    INT32   countContext = m_types->GetCount();
+    INT32 iResult = 0;
+    INT32 countContext = m_types->GetCount();
     while (iContext < countContext && (*m_types)[iContext] == type)
     {
         iResult++;
@@ -108,22 +108,19 @@
 
 MgPoint* MgParseAwkt::DoPoint(INT32& iContext, double* doubles)
 {
-    Ptr<MgPoint> geom = (MgPoint*)NULL;
-
     _dims dim = (_dims) (*m_dims)[iContext];
 
     INT32 index = 0;
-    geom = MgParseAwktUtil::CreatePoint(DimToDimensionality(dim), &doubles[(*m_starts)[iContext]], index);
+    Ptr<MgPoint> geom = MgParseAwktUtil::CreatePoint(DimToDimensionality(dim), &doubles[(*m_starts)[iContext]], index);
     iContext++;
 
-    return SAFE_ADDREF((MgPoint*)geom);
+    return geom.Detach();
 }
 
 MgLineString* MgParseAwkt::DoLineString(INT32& iContext, double* doubles, _types type)
 {
     // line strings can have multiple context entries and corresponding n-values per point
     MgGeometryFactory factory;
-    Ptr<MgLineString> geom = (MgLineString*)NULL;
 
     _dims dim = (_dims) (*m_dims)[iContext];
 
@@ -131,20 +128,17 @@
     INT32 countValues = countSame*DimToCount(dim);
 
     INT32 index = 0;
-    geom = MgParseAwktUtil::CreateLineString(DimToDimensionality(dim), countSame, &doubles[(*m_starts)[iContext]], index);
-
+    Ptr<MgLineString> geom = MgParseAwktUtil::CreateLineString(DimToDimensionality(dim),
+        countSame, &doubles[(*m_starts)[iContext]], index);
     iContext += countSame;
 
-    return SAFE_ADDREF((MgLineString*)geom);
+    return geom.Detach();
 }
 
 MgPolygon* MgParseAwkt::DoPolygon(INT32& iContext, double* doubles, _types type)
 {
     // polygons have 1 exterior ring and 0 or more interior rings
     MgGeometryFactory factory;
-    Ptr<MgPolygon>  geom = (MgPolygon*)NULL;
-    Ptr<MgLinearRing> extRing = (MgLinearRing*)NULL;
-    Ptr<MgLinearRingCollection> intRings = (MgLinearRingCollection*)NULL;
 
     _dims dim = (_dims) (*m_dims)[iContext];
 
@@ -153,13 +147,13 @@
     INT32 countValues = countSame*DimToCount(dim);
     INT32 index = 0;
 
-    extRing = MgParseAwktUtil::CreateLinearRing(DimToDimensionality(dim),
+    Ptr<MgLinearRing> extRing = MgParseAwktUtil::CreateLinearRing(DimToDimensionality(dim),
         countSame, &doubles[(*m_starts)[iContext]], index);
 
     iContext += countSame;
 
     // interior ring
-    intRings = new MgLinearRingCollection();
+    Ptr<MgLinearRingCollection> intRings = new MgLinearRingCollection();
     while (iContext < m_types->GetCount() && (*m_types)[iContext] == -type)
     {
         (*m_types)[iContext] = type;
@@ -171,29 +165,24 @@
             countSame, &doubles[(*m_starts)[iContext]], index);
 
         if (intRing != NULL)
-        {
             intRings->Add(intRing);
-        }
 
         iContext += countSame;
     }
 
-    geom = factory.CreatePolygon(extRing, intRings);
+    Ptr<MgPolygon> geom = factory.CreatePolygon(extRing, intRings);
 
-    return SAFE_ADDREF((MgPolygon*)geom);
+    return geom.Detach();
 }
 
 MgMultiPoint* MgParseAwkt::DoMultiPoint(INT32& iContext, double* doubles)
 {
     MgGeometryFactory factory;
+    Ptr<MgPointCollection> pnts = new MgPointCollection();
 
-    Ptr<MgMultiPoint> geom = (MgMultiPoint*)NULL;
-    Ptr<MgPointCollection> pnts = (MgPointCollection*)NULL;
-
     _dims dim = (_dims) (*m_dims)[iContext];
 
     // there can be n-context entries for each point
-    pnts = new MgPointCollection();
     INT32 countContext = CountSame(iContext, kMultiPoint);
 
     for (int i=0; i < countContext; i++)
@@ -204,32 +193,25 @@
         INT32 index = 0;
         Ptr<MgPoint> pnt = MgParseAwktUtil::CreatePoint(DimToDimensionality(dim), &doubles[(*m_starts)[iContext]], index);
         if (pnt != NULL)
-        {
             pnts->Add(pnt);
-        }
         iContext++;
     }
 
-    geom = factory.CreateMultiPoint(pnts);
+    Ptr<MgMultiPoint> geom = factory.CreateMultiPoint(pnts);
 
-    return SAFE_ADDREF((MgMultiPoint*)geom);
+    return geom.Detach();
 }
 
 MgMultiLineString* MgParseAwkt::DoMultiLineString(INT32& iContext, double* doubles)
 {
     MgGeometryFactory factory;
-
-    Ptr<MgMultiLineString>  geom = (MgMultiLineString*)NULL;
     Ptr<MgLineStringCollection> lineStrings = new MgLineStringCollection();
 
     _dims dim = (_dims) (*m_dims)[iContext];
 
     Ptr<MgLineString> lineString = (MgLineString*)DoLineString(iContext, doubles, kMultiLineString);
-
     if (lineString != NULL)
-    {
         lineStrings->Add(lineString);
-    }
 
     while (iContext < m_types->GetCount() && (*m_types)[iContext] == -kMultiLineString)
     {
@@ -241,25 +223,21 @@
         }
     }
 
-    geom = factory.CreateMultiLineString(lineStrings);
+    Ptr<MgMultiLineString> geom = factory.CreateMultiLineString(lineStrings);
 
-    return SAFE_ADDREF((MgMultiLineString*)geom);
+    return geom.Detach();
 }
 
 MgMultiPolygon* MgParseAwkt::DoMultiPolygon(INT32& iContext, double* doubles)
 {
     MgGeometryFactory factory;
-
-    Ptr<MgMultiPolygon> geom = (MgMultiPolygon*)NULL;
     Ptr<MgPolygonCollection> polygons = new MgPolygonCollection();
 
     _dims dim = (_dims) (*m_dims)[iContext];
 
     Ptr<MgPolygon> polygon = DoPolygon(iContext, doubles, kMultiPolygon);
     if (polygon != NULL)
-    {
         polygons->Add(polygon);
-    }
 
     while (iContext < m_types->GetCount() && (*m_types)[iContext] == kRing)
     {
@@ -267,20 +245,17 @@
         iContext++;
         Ptr<MgPolygon> polygon1 = DoPolygon(iContext, doubles, kMultiPolygon);
         if (polygon1 != NULL)
-        {
             polygons->Add(polygon1);
-        }
     }
 
-    geom = factory.CreateMultiPolygon(polygons);
+    Ptr<MgMultiPolygon> geom = factory.CreateMultiPolygon(polygons);
 
-    return SAFE_ADDREF((MgMultiPolygon*)geom);
+    return geom.Detach();
 }
 
 MgCurveSegmentCollection* MgParseAwkt::DoCurveSegmentCollection(INT32& iContext, double* doubles)
 {
     MgGeometryFactory factory;
-
     Ptr<MgCurveSegmentCollection> segs = new MgCurveSegmentCollection();
 
     _dims dim = (_dims) (*m_dims)[iContext];
@@ -319,8 +294,8 @@
         }
         else if (typeSegment == kLineStringSegment)
         {
-            INT32   countSame = CountSame(iContext, kLineStringSegment);
-            INT32   countValues = countSame*DimToCount(dim);
+            INT32 countSame = CountSame(iContext, kLineStringSegment);
+            INT32 countValues = countSame*DimToCount(dim);
 
             //Ptr<MgLinearSegment> linearSeg = m_gf->CreateLineStringSegment(DimToDimensionality(dim),
                 // countValues+DimToCount(dim), &doubles[(*m_starts)[iContext-1]]);
@@ -336,37 +311,29 @@
             break;
     }
 
-    return SAFE_ADDREF((MgCurveSegmentCollection*)segs);
+    return segs.Detach();
 }
 
 MgCurveString* MgParseAwkt::DoCurveString(INT32& iContext, double* doubles)
 {
     MgGeometryFactory factory;
 
-    Ptr<MgCurveSegmentCollection> segs = (MgCurveSegmentCollection*)NULL;
-    Ptr<MgCurveString> geom = (MgCurveString*)NULL;
+    Ptr<MgCurveSegmentCollection> segs = DoCurveSegmentCollection(iContext, doubles);
+    Ptr<MgCurveString> geom = factory.CreateCurveString(segs);
 
-    segs = DoCurveSegmentCollection(iContext, doubles);
-    geom = factory.CreateCurveString(segs);
-
-    return SAFE_ADDREF((MgCurveString*)geom);
+    return geom.Detach();
 }
 
 MgCurvePolygon* MgParseAwkt::DoCurvePolygon(INT32& iContext, double* doubles)
 {
     MgGeometryFactory factory;
-
-    Ptr<MgCurvePolygon> geom = (MgCurvePolygon*)NULL;
-    Ptr<MgCurveSegmentCollection> extSegs = (MgCurveSegmentCollection*)NULL;
-
-    Ptr<MgCurveRing> extRing = (MgCurveRing*)NULL;
     Ptr<MgCurveRingCollection> intRings = new MgCurveRingCollection();
 
     _dims dim = (_dims) (*m_dims)[iContext];
 
     // exterior ring
-    extSegs = DoCurveSegmentCollection(iContext, doubles);
-    extRing = factory.CreateCurveRing(extSegs);
+    Ptr<MgCurveSegmentCollection> extSegs = DoCurveSegmentCollection(iContext, doubles);
+    Ptr<MgCurveRing> extRing = factory.CreateCurveRing(extSegs);
 
     // interior rings
     _types typeSegment;
@@ -384,30 +351,26 @@
         {
             Ptr<MgCurveRing> intRing = factory.CreateCurveRing(intSegs);
             if (intRing != NULL)
-            {
                 intRings->Add(intRing);
-            }
         }
     }
 
-    geom = factory.CreateCurvePolygon(extRing, intRings);
+    Ptr<MgCurvePolygon> geom = factory.CreateCurvePolygon(extRing, intRings);
 
-    return SAFE_ADDREF((MgCurvePolygon*)geom);
+    return geom.Detach();
 }
 
 MgMultiCurveString* MgParseAwkt::DoMultiCurveString(INT32& iContext, double* doubles)
 {
     MgGeometryFactory factory;
 
-    Ptr<MgMultiCurveString> geom = (MgMultiCurveString*)NULL;
     Ptr<MgCurveStringCollection> curveStrings = new MgCurveStringCollection();
 
     _dims dim = (_dims) (*m_dims)[iContext];
+
     Ptr<MgCurveString> curveString = (MgCurveString*)DoCurveString(iContext, doubles);
     if (curveString != NULL)
-    {
         curveStrings->Add(curveString);
-    }
 
     _types typeSegment;
     while (iContext < m_types->GetCount())
@@ -419,30 +382,25 @@
         (*m_types)[iContext] = -typeSegment;
         Ptr<MgCurveString> curveString1 = DoCurveString(iContext, doubles);
         if (curveString1 != NULL)
-        {
             curveStrings->Add(curveString1);
-        }
     }
 
-    geom = factory.CreateMultiCurveString(curveStrings);
+    Ptr<MgMultiCurveString> geom = factory.CreateMultiCurveString(curveStrings);
 
-    return SAFE_ADDREF((MgMultiCurveString*)geom);
+    return geom.Detach();
 }
 
 
 MgMultiCurvePolygon* MgParseAwkt::DoMultiCurvePolygon(INT32& iContext, double* doubles)
 {
     MgGeometryFactory factory;
-
-    Ptr<MgMultiCurvePolygon> geom = (MgMultiCurvePolygon*)NULL;
     Ptr<MgCurvePolygonCollection> polygons = new MgCurvePolygonCollection();
 
     _dims dim = (_dims) (*m_dims)[iContext];
+
     Ptr<MgCurvePolygon> polygon = DoCurvePolygon(iContext, doubles);
     if (polygon != NULL)
-    {
         polygons->Add(polygon);
-    }
 
     _types typeSegment;
     while (iContext < m_types->GetCount())
@@ -455,30 +413,27 @@
         iContext++;
         Ptr<MgCurvePolygon> polygon1 = DoCurvePolygon(iContext, doubles);
         if (polygon1 != NULL)
-        {
             polygons->Add(polygon1);
-        }
     }
-    geom = factory.CreateMultiCurvePolygon(polygons);
 
-    return SAFE_ADDREF((MgMultiCurvePolygon*)geom);
+    Ptr<MgMultiCurvePolygon> geom = factory.CreateMultiCurvePolygon(polygons);
+
+    return geom.Detach();
 }
 
 MgGeometry* MgParseAwkt::DoGeometryCollection(INT32 iContextStart, bool bCollect)
 {
     _types type = kNone;
 
-    Ptr<MgGeometry> geom = (MgGeometry*)NULL;
-    Ptr<MgGeometryCollection> geomCollection = (MgGeometryCollection*)NULL;
+    Ptr<MgGeometry> geom;
+    Ptr<MgGeometryCollection> geomCollection;
 
     // take the value and try to constuct the geometry
     double* doubles = m_values->GetData();
     INT32 countContext = m_types->GetCount();
 
     if (bCollect)
-    {
         geomCollection = new MgGeometryCollection();
-    }
 
     INT32 iCurrent = iContextStart;
 
@@ -537,7 +492,6 @@
             return NULL;
         }
 
-
         if (geom == NULL)
         {
             // some error occured constructing geometry so give up
@@ -555,12 +509,10 @@
     {
         MgGeometryFactory factory;
         Ptr<MgMultiGeometry> multiGeom = factory.CreateMultiGeometry(geomCollection);
-        return SAFE_ADDREF((MgMultiGeometry*)multiGeom);
+        return multiGeom.Detach();
     }
-    else
-    {
-        return SAFE_ADDREF((MgGeometry*)geom);
-    }
+
+    return geom.Detach();
 }
 
 void MgParseAwkt::Done()
@@ -586,9 +538,9 @@
         throw new MgInvalidArgumentException(L"MgParseAwkt.ParseAwkt", __LINE__, __WFILE__, NULL, L"", NULL);
     }
 
-    _types      type = (_types) (*m_types)[0];
-    bool        bMultiGeometry = type == kMultiGeometry;
-    INT32   iContextStart = 0;
+    _types type = (_types) (*m_types)[0];
+    bool bMultiGeometry = type == kMultiGeometry;
+    INT32 iContextStart = 0;
     if (bMultiGeometry)
         iContextStart++;
 

Modified: trunk/MgDev/Common/Geometry/Parse/ParseAwktUtil.cpp
===================================================================
--- trunk/MgDev/Common/Geometry/Parse/ParseAwktUtil.cpp	2007-03-08 22:58:19 UTC (rev 1185)
+++ trunk/MgDev/Common/Geometry/Parse/ParseAwktUtil.cpp	2007-03-09 00:12:31 UTC (rev 1186)
@@ -22,7 +22,7 @@
 MgCoordinate* MgParseAwktUtil::CreateCoordinate(INT32 dimension, double* doubles, INT32& index)
 {
     MgGeometryFactory factory;
-    Ptr<MgCoordinate> coord = (MgCoordinate*)NULL;
+    Ptr<MgCoordinate> coord;
 
     switch(dimension)
     {
@@ -52,7 +52,7 @@
         }
     }
 
-    return SAFE_ADDREF((MgCoordinate*)coord);
+    return coord.Detach();
 }
 
 MgCoordinateCollection* MgParseAwktUtil::CreateCoordinateCollection(INT32 dimensionType, INT32 numOfCoordinates, double* ordinates, INT32& index)
@@ -73,7 +73,7 @@
         coordCol->Add(coord);
     }
 
-    return SAFE_ADDREF((MgCoordinateCollection*)coordCol);
+    return coordCol.Detach();
 }
 
 MgPoint* MgParseAwktUtil::CreatePoint(INT32 dimension, double* doubles, INT32& index)

Modified: trunk/MgDev/Common/Geometry/Spatial/SpatialUtility.cpp
===================================================================
--- trunk/MgDev/Common/Geometry/Spatial/SpatialUtility.cpp	2007-03-08 22:58:19 UTC (rev 1185)
+++ trunk/MgDev/Common/Geometry/Spatial/SpatialUtility.cpp	2007-03-09 00:12:31 UTC (rev 1186)
@@ -324,9 +324,7 @@
     bool zIsNan = ( MgMathUtility::IsNan(z1) || MgMathUtility::IsNan(z2) );
     double dz = ( zIsNan ? 0.0 : z2 - z1 );
 
-    double distance = sqrt (dx*dx + dy*dy + dz*dz);
-
-    return distance;
+    return sqrt(dx*dx + dy*dy + dz*dz);
 }
 
 
@@ -483,7 +481,7 @@
 {
     CHECKNULL(curve, L"MgSpatialUtility.TesselateCurve")
 
-    Ptr<MgGeometryComponent> retGeomComp = (MgGeometryComponent*)NULL;
+    Ptr<MgGeometryComponent> retGeomComp;
     Ptr<MgEnvelope> env = curve->Envelope();
     double maxdim = max(env->GetWidth(), env->GetHeight());
 
@@ -514,5 +512,5 @@
         }
     }
 
-    return SAFE_ADDREF((MgGeometryComponent*)retGeomComp);
+    return retGeomComp.Detach();
 }

Modified: trunk/MgDev/Common/PlatformBase/MapLayer/SelectionBase.cpp
===================================================================
--- trunk/MgDev/Common/PlatformBase/MapLayer/SelectionBase.cpp	2007-03-08 22:58:19 UTC (rev 1185)
+++ trunk/MgDev/Common/PlatformBase/MapLayer/SelectionBase.cpp	2007-03-09 00:12:31 UTC (rev 1186)
@@ -636,7 +636,7 @@
 {
     CHECKNULL((MgFeatureService*)featureService, L"MgSelection.GetExtents");
 
-    Ptr<MgEnvelope> env = (MgEnvelope*)NULL;
+    Ptr<MgEnvelope> env;
     Ptr<MgReadOnlyLayerCollection> roLayerCol = this->GetLayers();
 
     if (roLayerCol != NULL)
@@ -658,11 +658,11 @@
             }
             else
             {
-                env = SAFE_ADDREF((MgEnvelope*)clsEnv);
+                env = clsEnv.Detach();
             }
         }
     }
-    return SAFE_ADDREF((MgEnvelope*)env);
+    return env.Detach();
 }
 
 
@@ -682,8 +682,8 @@
     Ptr<MgResourceIdentifier> featureResId = new MgResourceIdentifier(resId);
     Ptr<MgDataReader> geomDataReader = featureService->SelectAggregate(featureResId, clsName, geomQryOptions);
 
-    Ptr<MgGeometry> geomFilter = (MgGeometry*)NULL;
-    Ptr<MgEnvelope> env = (MgEnvelope*)NULL;
+    Ptr<MgGeometry> geomFilter;
+    Ptr<MgEnvelope> env;
     while (geomDataReader->ReadNext())
     {
         Ptr<MgByteReader> byteReader = geomDataReader->GetGeometry(L"EXTENT_PROP");
@@ -693,7 +693,7 @@
         Ptr<MgEnvelope> geomExtn = geom->Envelope();
         if (env == NULL)
         {
-            env = SAFE_ADDREF((MgEnvelope*)geomExtn);
+            env = geomExtn.Detach();
         }
         else
         {
@@ -705,7 +705,7 @@
     }
     geomDataReader->Close();
 
-    return SAFE_ADDREF((MgEnvelope*)env);
+    return env.Detach();
 }
 
 



More information about the mapguide-commits mailing list