Manta Interactive Ray Tracer Development Mailing List

Text archives Help


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


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

Author: sparker
Date: Thu Sep 20 18:46:46 2007
New Revision: 1730

Modified:
   branches/persistent/Core/Persistent/ArchiveElement.h
   branches/persistent/Core/Persistent/ClassInfo.h
   branches/persistent/Core/Persistent/XMLArchive.cc
Log:
Work on document reading


Modified: branches/persistent/Core/Persistent/ArchiveElement.h
==============================================================================
--- branches/persistent/Core/Persistent/ArchiveElement.h        (original)
+++ branches/persistent/Core/Persistent/ArchiveElement.h        Thu Sep 20 
18:46:46 2007
@@ -39,7 +39,6 @@
 
   protected:
     virtual ArchiveElement* findObject(const std::string& fieldname,
-                                       ClassDatabaseInterface* db,
                                        std::string& classname,
                                        Persistent::StorageHint classhint,
                                        Persistent::StorageHint instancehint) 
= 0;
@@ -75,9 +74,7 @@
       if(classhint == Persistent::Default)
         classhint = Persistent::SimpleObject;
       std::string classname;
-      ArchiveElement* subelement = findObject(fieldname,
-                                              
ClassDatabase<T>::getInterface(),
-                                              classname, classhint, 
instancehint);
+      ArchiveElement* subelement = findObject(fieldname, classname, 
classhint, instancehint);
       if(!subelement)
         throw SerializationError("Cannot find field: " + 
std::string(fieldname) + " of type " + typeid(T).name());
 
@@ -108,14 +105,17 @@
         Persistent::StorageHint classhint = ClassInfo<T>::storageHint();
         std::string classname;
         ArchiveElement* subelement = findObject(fieldname,
-                                                
ClassDatabase<T>::getInterface(),
                                                 classname, classhint, 
instancehint);
         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");
+        if(!dbentry){
+          if(classname == dbentry->getPublicClassname())
+            throw SerializationError("Class: " + classname + " does not have 
persistent object information");
+          else
+            throw SerializationError("Class: " + classname + " is not a 
known subclass of " + dbentry->getPublicClassname());
+        }
         data = dbentry->createInstance();
         dbentry->readwrite(subelement, data);
         delete subelement;

Modified: branches/persistent/Core/Persistent/ClassInfo.h
==============================================================================
--- branches/persistent/Core/Persistent/ClassInfo.h     (original)
+++ branches/persistent/Core/Persistent/ClassInfo.h     Thu Sep 20 18:46:46 
2007
@@ -34,16 +34,8 @@
       static void registerClassAndParents(const std::string& classname);
   };
 
-  class ClassDatabaseInterface {
-  public:
-    virtual ~ClassDatabaseInterface() {};
-
-    virtual bool isa(const std::string& classname) const = 0;
-    virtual std::string getPublicClassname() const = 0;
-  };
-
   template<class T>
-  class ClassDatabase : public ClassDatabaseInterface {
+  class ClassDatabase {
   public:
     class Entry {
     public:
@@ -126,15 +118,8 @@
       return singleton()->_getEntry(ti);
     }
 
-    virtual bool isa(const std::string& classname) const {
-      return _getEntry(classname) != 0;
-    }
-
     virtual std::string getPublicClassname() const {
       return _getEntry(typeid(T))->getPublicClassname();
-    }
-    static ClassDatabaseInterface* getInterface() {
-      return singleton();
     }
 
   private:

Modified: branches/persistent/Core/Persistent/XMLArchive.cc
==============================================================================
--- branches/persistent/Core/Persistent/XMLArchive.cc   (original)
+++ branches/persistent/Core/Persistent/XMLArchive.cc   Thu Sep 20 18:46:46 
2007
@@ -91,7 +91,6 @@
                            Persistent::StorageHint hint = 
Persistent::Default);
 
     virtual ArchiveElement* findObject(const std::string& fieldname,
-                                       ClassDatabaseInterface* db,
                                        std::string& classname,
                                        Persistent::StorageHint classhint,
                                        Persistent::StorageHint instancehint);
@@ -299,43 +298,75 @@
 }
 
 ArchiveElement* XMLArchiveElement::findObject(const std::string& fieldname,
-                                              ClassDatabaseInterface* db,
                                               std::string& classname,
                                               Persistent::StorageHint 
classhint,
                                               Persistent::StorageHint 
instancehint)
 {
-#if 0
-  if(hint == AnonymousField){
+  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
+  xmlChar* prop = xmlGetProp(node, to_xml_ch_ptr(fieldname.c_str()));
+  if(prop){
+    // Make sure that there are no children with the same name
     for(xmlNode* child = node->children; child != 0; child = child->next){
-      if(strcmp(to_char_ptr(child->name), "template")){
-        xmlChar* prop = xmlGetProp(child, to_xml_ch_ptr("type"));
-        if(prop && db->isa(to_char_ptr(prop))){
-          classname = to_char_ptr(prop);
-          return new XMLArchiveElement(archive, child);
-        }
-      } else {
-        classname = get_classname(child->name);
-        if(db->isa(classname))
-          return new XMLArchiveElement(archive, child);
-      }
+      if(child->type == XML_ELEMENT_NODE && strcmp(to_char_ptr(child->name), 
fieldname.c_str()) == 0)
+        throw SerializationError("Ambigious field: " + fieldname);
     }
-  } else {
-    for(xmlNode* child = node->children; child != 0; child = child->next){
-      if(strcmp(to_char_ptr(child->name), fieldname.c_str()) == 0){
-        xmlNode* c2 = child->children;
-        // There should only be one child of those node
-        if(c2->next){
-          ostringstream msg;
-          msg << "Multiple objects in one field: " << fieldname;
-          msg << "(" << to_char_ptr(c2->name) << " and " << 
to_char_ptr(c2->next->name) << ")";
+    classname = "<unknown>";
+    return new XMLArchiveElement(archive, node, fieldname);
+  }
+
+  // Then look for a node with the fieldname
+  for(xmlNode* child = node->children; child != 0; child = child->next){
+    if(child->type == XML_ELEMENT_NODE && strcmp(to_char_ptr(child->name), 
fieldname.c_str()) == 0){
+      // 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);
+      }
+
+      // The classname can be in one of several locations:
+      // 1. As a property of the field with the tag "type"
+      // 2. The sole child of the element
+      // 3. Implied, but only if the classhint is ContainerObject or 
SimpleObject
+      xmlChar* type = xmlGetProp(child, to_xml_ch_ptr("type"));
+      if(type){
+        classname = to_char_ptr(type);
+        return new XMLArchiveElement(archive, child);
+      }
+
+      if(classhint == Persistent::ContainerObject || classhint == 
Persistent::SimpleObject){
+        classname = "<unknown>";
+        return new XMLArchiveElement(archive, child);
+      }
+
+      xmlNode* child2 = child->children;
+      while(child2 && child2->type == XML_ELEMENT_NODE)
+        child2 = child2->next;
+      if(child2){
+        classname = to_char_ptr(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);
         }
-        return new XMLArchiveElement(archive, c2);
+        return new XMLArchiveElement(archive, child2);
       }
+      throw SerializationError("Empty field named: " + fieldname);
     }
   }
-#else
-  NOT_FINISHED("New findObject");
-#endif
+
+  // Finally, we could have an anonymous field
+  if(instancehint == Persistent::AnonymousField){
+    xmlNode* child = child->children;
+    while(child && child->type != XML_ELEMENT_NODE)
+      child = child->next;
+    if(child){
+      classname = to_char_ptr(child->name);
+      return new XMLArchiveElement(archive, child);
+    }
+  }
+
   return 0;
 }
 




  • [Manta] r1730 - branches/persistent/Core/Persistent, sparker, 09/20/2007

Archive powered by MHonArc 2.6.16.

Top of page