[mapguide-commits] r1062 - in trunk/MgDev/Common: MapGuideCommon/MapLayer PlatformBase/Services

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Fri Jan 19 09:29:23 EST 2007


Author: waltweltonlair
Date: 2007-01-19 09:29:22 -0500 (Fri, 19 Jan 2007)
New Revision: 1062

Modified:
   trunk/MgDev/Common/MapGuideCommon/MapLayer/Map.cpp
   trunk/MgDev/Common/MapGuideCommon/MapLayer/Map.h
   trunk/MgDev/Common/PlatformBase/Services/Resource.cpp
Log:
The logic for handling the layer / group blob in MgMap was flawed in the case
of an empty map (no layers / groups).  When an empty map was saved, the code
would not update the blob in the repository.  PackLayersAndGroups was assuming
that if there were no layers or groups then no changes had been made to the
map, and therefore saving the blob was unnecessary.  The case where that fails
is if you start with a non-empty map and then edit it to remove all the layers
and groups.

The fix is to add a flag to MgMap indicating whether the blob has been loaded.
This flag is now used as the check to prevent reloading of the blob.  It's also
used to detect if the blob needs to be saved.  If the blob waas loaded then it
will get saved.  For the non-empty map case this gives the same behavior.  A
user would access the layer or group, forcing a load of the blob, and then when
saving the map the code would save the blob if the layer or group collection
was non-empty.

Now if the map is empty a blob still gets saved, but it only contains the layer
and group counts, both zero.


Modified: trunk/MgDev/Common/MapGuideCommon/MapLayer/Map.cpp
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/MapLayer/Map.cpp	2007-01-19 03:55:32 UTC (rev 1061)
+++ trunk/MgDev/Common/MapGuideCommon/MapLayer/Map.cpp	2007-01-19 14:29:22 UTC (rev 1062)
@@ -34,10 +34,12 @@
 //
 MgMap::MgMap()
     : MgMapBase(),
-    m_inSave(false)
+    m_inSave(false),
+    m_unpackedLayersGroups(false)
 {
 }
 
+
 //////////////////////////////////////////////////////////////
 // Initializes a new Map object.
 // This method is used for Mg Viewers or for offline map production.
@@ -314,9 +316,13 @@
 
     m_trackChangesDisabled = false;
 
+    // there's nothing to unpack anymore in this case
+    m_unpackedLayersGroups = true;
+
     MG_CATCH_AND_THROW(L"MgMap.Create")
 }
 
+
 //////////////////////////////////////////////////////////////
 // Call down to base class implementation.  Ptr<> seems to be
 // messing this up.  Weird
@@ -356,11 +362,13 @@
     Ptr<MgResourceIdentifier> resId = new MgResourceIdentifier(L"Session:" + sessionId + L"//" + mapName + L"." + MgResourceType::Map);
     MgResource::Open(resourceService, resId);
 
-    //Note:  Layer and Groups are loaded on demand by UnpackLayerAndGroups
+    //Note: Layers and Groups are loaded on demand by UnpackLayersAndGroups
 
     m_trackChangesDisabled = false;
 }
 
+
+//////////////////////////////////////////////////////////////
 // Saves the resource using the specified resource service and resource identifier.
 // This method assumes a valid resource identifier has already been established
 // for this resource via either Open or Save
@@ -396,6 +404,8 @@
     m_inSave = false;
 }
 
+
+//////////////////////////////////////////////////////////////
 // Saves the resource using the specified resource service and resource identifier.
 //
 void MgMap::Save(MgResourceService* resourceService, MgResourceIdentifier* resourceId)
@@ -445,6 +455,7 @@
     delete this;
 }
 
+
 //////////////////////////////////////////////////////////////////
 /// \brief
 /// Unpacks layers and groups from memory stream - lazy initialization
@@ -470,17 +481,15 @@
 ///
 void MgMap::UnpackLayersAndGroups()
 {
-    // Temporary byte array for on-demand loading
+    // check if we already unpacked things
+    if (m_unpackedLayersGroups)
+        return;
+
+    // Temporary byte array for on-demand loading.
     Ptr<MgByte> bytes;
 
     if (NULL == (MgMemoryStreamHelper*) m_layerGroupHelper)
     {
-        if (m_layers->GetCount() || m_groups->GetCount())
-        {
-            // Already unpacked, just return.
-            return;
-        }
-
         // Need to query from Resource Service
         if (NULL != (MgResourceService*) m_resourceService)
         {
@@ -565,17 +574,20 @@
     bytes = NULL;
 
     m_trackChangesDisabled = false;
+
+    m_unpackedLayersGroups = true;
 }
 
+
 //////////////////////////////////////////////////////////////////
 /// \brief
 /// Packs layers and groups to a memory stream (lazy initialization)
 ///
 MgMemoryStreamHelper* MgMap::PackLayersAndGroups()
 {
-    if (0 == m_layers->GetCount() && 0 == m_groups->GetCount())
+    if (!m_unpackedLayersGroups)
     {
-        // Nothing to pack, or data has not changed.  Return NULL;
+        // Nothing to pack if we haven't unpacked the data.  Return NULL.
         return NULL;
     }
 
@@ -818,4 +830,4 @@
 void MgMap::SetDelayedLoadResourceService(MgResourceService* service)
 {
     m_resourceService = SAFE_ADDREF(service);
-}
\ No newline at end of file
+}

Modified: trunk/MgDev/Common/MapGuideCommon/MapLayer/Map.h
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/MapLayer/Map.h	2007-01-19 03:55:32 UTC (rev 1061)
+++ trunk/MgDev/Common/MapGuideCommon/MapLayer/Map.h	2007-01-19 14:29:22 UTC (rev 1062)
@@ -419,7 +419,7 @@
     /// \param stream
     /// Stream.
     ///
-    virtual void Deserialize(MgStream* stream);  
+    virtual void Deserialize(MgStream* stream);
 
     //////////////////////////////////////////////////////////////////
     /// \brief
@@ -430,7 +430,6 @@
     ///
     void SetDelayedLoadResourceService(MgResourceService* service);
 
-  
 protected:
 
     //////////////////////////////////////////////////////////////////
@@ -470,15 +469,14 @@
 
 private:
 
-    // Version for serialization 
+    // Version for serialization
     static const int m_serializeVersion = (3<<16) + 0;
 
     static STRING m_layerGroupTag;
     Ptr<MgMemoryStreamHelper> m_layerGroupHelper;
     Ptr<MgResourceService> m_resourceService;
     bool m_inSave;
-
-
+    bool m_unpackedLayersGroups;
 };
 /// \}
 

Modified: trunk/MgDev/Common/PlatformBase/Services/Resource.cpp
===================================================================
--- trunk/MgDev/Common/PlatformBase/Services/Resource.cpp	2007-01-19 03:55:32 UTC (rev 1061)
+++ trunk/MgDev/Common/PlatformBase/Services/Resource.cpp	2007-01-19 14:29:22 UTC (rev 1062)
@@ -42,11 +42,11 @@
     SAFE_ADDREF((MgResourceIdentifier*)m_resId);
 
     Ptr<MgByteReader> breader = resourceService->GetResourceData(m_resId, m_resourceDataTag);
-   
+
     //get the byte reader content into a memory stream
     MgByteSink sink(breader);
     Ptr<MgByte> bytes = sink.ToBuffer();
-    Ptr<MgMemoryStreamHelper> streamHelper = 
+    Ptr<MgMemoryStreamHelper> streamHelper =
         new MgMemoryStreamHelper((INT8*) bytes->Bytes(), bytes->GetLength(), false);
     Ptr<MgStream> stream = new MgStream(streamHelper);
 
@@ -81,7 +81,7 @@
 {
     //let the object serialize itself in a memory stream
     Ptr<MgMemoryStreamHelper> streamHelper = new MgMemoryStreamHelper();
-    
+
     Ptr<MgStream> stream = new MgStream(streamHelper);
 
     Serialize(stream);
@@ -92,7 +92,7 @@
 
     if(create)
     {
-        //create a fake content for this resource, needed for ading the resource
+        //create fake content for this resource, needed for adding the resource
         const char* resTypeName = GetResourceTypeName();
         string xmlContent = string("<?xml version=\"1.0\" encoding=\"UTF-8\"?><") + resTypeName + "></" + resTypeName + ">";
         Ptr<MgByteSource> bsource1 = new MgByteSource((BYTE_ARRAY_IN)xmlContent.c_str(), (INT32)xmlContent.length());
@@ -100,8 +100,8 @@
 
         resourceService->SetResource(m_resId, content, NULL);
     }
+
     resourceService->SetResourceData(m_resId, m_resourceDataTag, L"Stream", resourceData);
-
 }
 
 // Destruct a MgResource object



More information about the mapguide-commits mailing list