Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[Manta] r1731 - branches/persistent/Core/Persistent


Chronological Thread 
  • From: sparker@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [Manta] r1731 - branches/persistent/Core/Persistent
  • Date: Thu, 20 Sep 2007 23:03:28 -0600 (MDT)

Author: sparker
Date: Thu Sep 20 23:03:27 2007
New Revision: 1731

Modified:
   branches/persistent/Core/Persistent/ArchiveElement.h
   branches/persistent/Core/Persistent/XMLArchive.cc
Log:
Debugging and further progress on reading


Modified: branches/persistent/Core/Persistent/ArchiveElement.h
==============================================================================
--- branches/persistent/Core/Persistent/ArchiveElement.h        (original)
+++ branches/persistent/Core/Persistent/ArchiveElement.h        Thu Sep 20 
23:03:27 2007
@@ -78,9 +78,6 @@
       if(!subelement)
         throw SerializationError("Cannot find field: " + 
std::string(fieldname) + " of type " + typeid(T).name());
 
-      typename ClassDatabase<T>::Entry* dbentry = 
ClassDatabase<T>::getEntry(classname);
-      if(!dbentry)
-        throw SerializationError("Cannot create class: " + classname + " due 
to missing ClassInfo");
       ClassInfo<T>::readwrite(subelement, data);
       delete subelement;
     } else {
@@ -111,6 +108,7 @@
 
         typename ClassDatabase<T>::Entry* dbentry = 
ClassDatabase<T>::getEntry(classname);
         if(!dbentry){
+          dbentry = ClassDatabase<T>::getEntry(typeid(T));
           if(classname == dbentry->getPublicClassname())
             throw SerializationError("Class: " + classname + " does not have 
persistent object information");
           else

Modified: branches/persistent/Core/Persistent/XMLArchive.cc
==============================================================================
--- branches/persistent/Core/Persistent/XMLArchive.cc   (original)
+++ branches/persistent/Core/Persistent/XMLArchive.cc   Thu Sep 20 23:03:27 
2007
@@ -115,6 +115,7 @@
     bool tagUsed;
     void writeProperty(const std::string& fieldname, const std::string& 
value,
                        Persistent::StorageHint hint);
+    std::string readProperty(const std::string& fieldname, 
Persistent::StorageHint hint);
 
     typedef XMLArchive::refmaptype refmaptype;
     typedef XMLArchive::countmaptype countmaptype;
@@ -228,6 +229,27 @@
   }
 }
 
+std::string XMLArchiveElement::readProperty(const std::string& fieldname, 
Persistent::StorageHint hint)
+{
+  if(isTagElement){
+    xmlChar* prop = xmlGetProp(node, to_xml_ch_ptr(tagname.c_str()));
+    if(!prop)
+      throw SerializationError(std::string("Missing tag: ") + 
to_char_ptr(prop));
+    return to_char_ptr(prop);
+  } else {
+    xmlChar* prop = xmlGetProp(node, to_xml_ch_ptr(fieldname.c_str()));
+    if(prop)
+      return to_char_ptr(prop);
+
+    xmlNode* child = node->children;
+    while(child && child->type != XML_TEXT_NODE)
+      child = child->next;
+    if(!child)
+      throw SerializationError("No data in element for field: " + fieldname);
+    return to_char_ptr(XML_GET_CONTENT(child));
+  }
+}
+
 void XMLArchiveElement::readwrite(const std::string& fieldname, bool& data, 
Persistent::StorageHint hint)
 {
   if(reading()){
@@ -252,7 +274,10 @@
 void XMLArchiveElement::readwrite(const std::string& fieldname, float& data, 
Persistent::StorageHint hint)
 {
   if(reading()){
-    NOT_FINISHED("XMLArchiveElement::readwrite");
+    istringstream in(readProperty(fieldname, hint));
+    in >> data;
+    if(!in)
+      throw SerializationError("Error parsing float: " + in.str());
   } else {
     ostringstream datastring;
     datastring.precision(8);
@@ -264,7 +289,11 @@
 void XMLArchiveElement::readwrite(const std::string& fieldname, float* data, 
int numelements, Persistent::StorageHint hint)
 {
   if(reading()){
-    NOT_FINISHED("XMLArchiveElement::readwrite");
+    istringstream in(readProperty(fieldname, hint));
+    for(int i=0;i<numelements;i++)
+      in >> data[i];
+    if(!in)
+      throw SerializationError("Error parsing float array: " + in.str());
   } else {
     ostringstream datastring;
     datastring.precision(8);
@@ -280,7 +309,10 @@
 void XMLArchiveElement::readwrite(const std::string& fieldname, int& data, 
Persistent::StorageHint hint)
 {
   if(reading()){
-    NOT_FINISHED("XMLArchiveElement::readwrite");
+    istringstream in(readProperty(fieldname, hint));
+    in >> data;
+    if(!in)
+      throw SerializationError("Error parsing integer: " + in.str());
   } else {
     ostringstream datastring;
     datastring << data;
@@ -302,7 +334,6 @@
                                               Persistent::StorageHint 
classhint,
                                               Persistent::StorageHint 
instancehint)
 {
-  NOT_FINISHED("templates and name mangling for findObject");
   if(isTagElement)
     throw SerializationError("Object cannot be stored in a property: " + 
fieldname);
   // First look for a property with the fieldname
@@ -323,7 +354,7 @@
       // Make sure that there are no other children with the same name
       for(xmlNode* child2 = child->next; child2 != 0; child2 = child2->next){
         if(child2->type == XML_ELEMENT_NODE && 
strcmp(to_char_ptr(child2->name), fieldname.c_str()) == 0)
-          throw SerializationError("Ambigious field: " + fieldname);
+          throw SerializationError("Ambiguous field: " + fieldname);
       }
 
       // The classname can be in one of several locations:
@@ -342,13 +373,20 @@
       }
 
       xmlNode* child2 = child->children;
-      while(child2 && child2->type == XML_ELEMENT_NODE)
+      while(child2 && child2->type != XML_ELEMENT_NODE)
         child2 = child2->next;
       if(child2){
-        classname = to_char_ptr(child2->name);
+        if(strcmp(to_char_ptr(child2->name), "template") == 0){
+          xmlChar* templname = xmlGetProp(child2, to_xml_ch_ptr("type"));
+          if(!templname)
+            throw SerializationError("Unspecified type for template: " + 
fieldname);
+          classname = to_char_ptr(templname);
+        } else {
+          classname = get_classname(child2->name);
+        }
         for(xmlNode* child3 = child2->next; child3 != 0; child3 = 
child3->next){
-          if(child2->type == XML_ELEMENT_NODE)
-            throw SerializationError("Ambiguous type for field: " + 
fieldname);
+          if(child3->type == XML_ELEMENT_NODE)
+            throw SerializationError("Ambiguous value for field: " + 
fieldname + "(" + classname + " and " + to_char_ptr(child3->name) + ")");
         }
         return new XMLArchiveElement(archive, child2);
       }
@@ -358,11 +396,18 @@
 
   // Finally, we could have an anonymous field
   if(instancehint == Persistent::AnonymousField){
-    xmlNode* child = child->children;
+    xmlNode* child = node->children;
     while(child && child->type != XML_ELEMENT_NODE)
       child = child->next;
     if(child){
-      classname = to_char_ptr(child->name);
+      if(strcmp(to_char_ptr(child->name), "template") == 0){
+        xmlChar* templname = xmlGetProp(child, to_xml_ch_ptr("type"));
+        if(!templname)
+          throw SerializationError("Unspecified type for template: " + 
fieldname);
+        classname = to_char_ptr(templname);
+      } else {
+        classname = get_classname(child->name);
+      }
       return new XMLArchiveElement(archive, child);
     }
   }




  • [Manta] r1731 - branches/persistent/Core/Persistent, sparker, 09/21/2007

Archive powered by MHonArc 2.6.16.

Top of page