changed patch parser structures
authorJiri Srain <jsrain@suse.cz>
Mon, 21 Nov 2005 11:38:20 +0000 (11:38 +0000)
committerJiri Srain <jsrain@suse.cz>
Mon, 21 Nov 2005 11:38:20 +0000 (11:38 +0000)
zypp/parser/yum/YUMParserData.cc
zypp/parser/yum/YUMParserData.h
zypp/parser/yum/YUMPatchParser.cc

index 47d9808..c011739 100644 (file)
@@ -361,22 +361,38 @@ ostream& operator<<(ostream &out, const YUMPatchData& data)
     << "  affects package manager: " << data.packageManager << endl
     << "  update script: " << data.updateScript << endl
     << "  atoms:" << endl
+/*  for (std::list<shared_ptr<YUMPatchAtom> >::const_iterator it = data.atoms.begin();
+       it != data.atoms.end();
+       it++)
+  {
+    out << *it;
+  }*/
+// FIXME here
     << data.atoms;
   return out;
 }
 
-std::ostream& operator<<(std::ostream& out, const YUMPatchAtom& data)
+std::ostream& operator<<(std::ostream& out, const shared_ptr<YUMPatchAtom> data)
 {
-  out << "Atom data" << endl
-    << "  atom type: " << data.type << endl;
-  if (data.type == "message")
-    out << *data.message;
-  else if (data.type == "script")
-    out << *data.script;
-  else if (data.type == "package")
-    out << *data.package;
-  else
-    out << "Unknown atom type" << endl;
+  out << "Atom data" << endl;
+//  out << "  atom type: " << data->atomType() << endl;
+  switch (data->atomType())
+  {
+    case YUMPatchAtom::Package:
+      out << "  atom type: " << "package" << endl
+        << *dynamic_pointer_cast<YUMPatchPackage>(data);
+      break;
+    case YUMPatchAtom::Message:
+      out << "  atom type: " << "message" << endl
+        << *dynamic_pointer_cast<YUMPatchMessage>(data);
+      break;
+    case YUMPatchAtom::Script:
+      out << "  atom type: " << "script" << endl
+        << *dynamic_pointer_cast<YUMPatchScript>(data);
+      break;
+    default:
+      out << "Unknown atom type" << endl;
+  }
   return out;
 }
 
index bb920f8..3aa29d1 100644 (file)
 #include <string>
 #include <list>
 #include <iostream>
+#include <zypp/base/PtrTypes.h>
+
+using namespace zypp::base;
+
 
 namespace zypp {
   namespace parser {
@@ -156,16 +160,31 @@ namespace zypp {
         std::string source_info;
       };
     
-      class YUMPatchPackage : public base::ReferenceCounted, private base::NonCopyable {
+      class YUMPatchAtom : public base::ReferenceCounted, private base::NonCopyable {
       public:
-        YUMPatchPackage() {};
-        // data for primary
-        std::string type;
+
+       enum AtomType { Package, Script, Message };
+
+        virtual AtomType atomType() = 0;
         std::string name;
-        std::string arch;
+        std::string type;
         std::string epoch;
         std::string ver;
         std::string rel;
+        std::string arch;
+        std::list<YUMDependency> provides;
+        std::list<YUMDependency> conflicts;
+        std::list<YUMDependency> obsoletes;
+        std::list<YUMDependency> freshen;
+        std::list<YUMDependency> requires;
+      };
+
+      class YUMPatchPackage : public YUMPatchAtom {
+      public:
+        YUMPatchPackage() {};
+        virtual AtomType atomType() { return Package; };
+        // data for primary
+        std::string type;
         std::string checksumType;
         std::string checksumPkgid;
         std::string checksum;
@@ -186,17 +205,12 @@ namespace zypp {
         std::string sourcerpm;
         std::string headerStart;
         std::string headerEnd;
-        std::list<YUMDependency> provides;
-        std::list<YUMDependency> conflicts;
-        std::list<YUMDependency> obsoletes;
-        std::list<YUMDependency> requires;
         std::list<FileData> files;
         // SuSE specific data
         std::list<std::string> authors;
         std::list<std::string> keywords;
         std::string  media;
         std::list<YUMDirSize> dirSizes;
-        std::list<YUMDependency> freshen;
         bool installOnly;
         // Change Log
         std::list<ChangelogEntry> changelog;
@@ -226,48 +240,23 @@ namespace zypp {
         } deltaRpm;
       };
     
-      class YUMPatchScript : public base::ReferenceCounted, private base::NonCopyable {
+      class YUMPatchScript : public YUMPatchAtom {
       public:
         YUMPatchScript() {};
-        std::string name;
-        std::string epoch;
-        std::string ver;
-        std::string rel;
+        virtual AtomType atomType() { return Script; };
         std::string do_script;
         std::string undo_script;
-        std::list<YUMDependency> provides;
-        std::list<YUMDependency> conflicts;
-        std::list<YUMDependency> obsoletes;
-        std::list<YUMDependency> freshen;
-        std::list<YUMDependency> requires;
       };
     
-      class YUMPatchMessage : public base::ReferenceCounted, private base::NonCopyable {
+      class YUMPatchMessage : public YUMPatchAtom {
       public:
         YUMPatchMessage() {};
-        std::string name;
+        virtual AtomType atomType() { return Message; };
         std::string type;
-        std::string epoch;
-        std::string ver;
-        std::string rel;
-        std::list<YUMDependency> provides;
-        std::list<YUMDependency> conflicts;
-        std::list<YUMDependency> obsoletes;
-        std::list<YUMDependency> freshen;
-        std::list<YUMDependency> requires;
         std::string text;
       };
     
-      class YUMPatchAtom {
-      public:
-        std::string type;
-        // union not possibel due to constructors
-        // there is no common parent
-        YUMPatchPackagePtr package;
-        YUMPatchScriptPtr script;
-        YUMPatchMessagePtr message;
-      };
-    
+   
       /**
        * @short Holds the metadata about a YUM repository
        **/
@@ -407,7 +396,7 @@ namespace zypp {
         bool packageManager;
         std::string updateScript;
         // FIXME this copying of structures is inefective
-        std::list<YUMPatchAtom> atoms;
+        std::list<shared_ptr<YUMPatchAtom> > atoms;
       };
 
 
@@ -432,7 +421,7 @@ std::ostream& operator<<(std::ostream &out, const zypp::parser::yum::YUMGroupDat
 std::ostream& operator<<(std::ostream &out, const zypp::parser::yum::YUMFileListData& data);
 std::ostream& operator<<(std::ostream& out, const zypp::parser::yum::YUMOtherData& data);
 std::ostream& operator<<(std::ostream& out, const zypp::parser::yum::YUMPatchData& data);
-std::ostream& operator<<(std::ostream& out, const zypp::parser::yum::YUMPatchAtom& data);
+std::ostream& operator<<(std::ostream& out, const shared_ptr<zypp::parser::yum::YUMPatchAtom> data);
 std::ostream& operator<<(std::ostream& out, const zypp::parser::yum::YUMPatchMessage& data);
 std::ostream& operator<<(std::ostream& out, const zypp::parser::yum::YUMPatchScript& data);
 std::ostream& operator<<(std::ostream& out, const zypp::parser::yum::YUMPatchPackage& data);
index a4ae436..fcb1930 100644 (file)
@@ -365,11 +365,9 @@ namespace zypp {
       YUMPatchParser::parsePackageNode(YUMPatchDataPtr dataPtr,
                                      xmlNodePtr formatNode)
       {
-        YUMPatchAtom at;
-        at.type = "package";
-        at.package = new YUMPatchPackage;
-        at.package->type = _helper.attribute(formatNode,"type");
-        at.package->installOnly = false;
+       shared_ptr<YUMPatchPackage> package(new YUMPatchPackage);
+        package->type = _helper.attribute(formatNode,"type");
+        package->installOnly = false;
       
         // FIXME move the respective method to a common class, inherit it  
         YUMPrimaryParser prim;
@@ -380,51 +378,51 @@ namespace zypp {
           if (_helper.isElement(child)) {
             string name = _helper.name(child);
             if (name == "name") {
-       at.package->name = _helper.content(child);
+       package->name = _helper.content(child);
             }
             else if (name == "arch") {
-              at.package->arch = _helper.content(child);
+              package->arch = _helper.content(child);
             }
             else if (name == "version") {
-              at.package->epoch = _helper.attribute(child,"epoch");
-              at.package->ver = _helper.attribute(child,"ver");
-              at.package->rel = _helper.attribute(child,"rel");
+              package->epoch = _helper.attribute(child,"epoch");
+              package->ver = _helper.attribute(child,"ver");
+              package->rel = _helper.attribute(child,"rel");
             }
             else if (name == "checksum") {
-              at.package->checksumType = _helper.attribute(child,"type");
-              at.package->checksumPkgid = _helper.attribute(child,"pkgid");
-              at.package->checksum = _helper.content(child);
+              package->checksumType = _helper.attribute(child,"type");
+              package->checksumPkgid = _helper.attribute(child,"pkgid");
+              package->checksum = _helper.content(child);
             }
             else if (name == "summary") {
-              at.package->summary = _helper.content(child);
+              package->summary = _helper.content(child);
             }
             else if (name == "description") {
-              at.package->description = _helper.content(child);
+              package->description = _helper.content(child);
             }
             else if (name == "packager") {
-              at.package->packager = _helper.content(child);
+              package->packager = _helper.content(child);
             }
             else if (name == "url") {
-              at.package->url = _helper.content(child);
+              package->url = _helper.content(child);
             }
             else if (name == "time") {
-              at.package->timeFile = _helper.attribute(child,"file");
-              at.package->timeBuild = _helper.attribute(child,"build");
+              package->timeFile = _helper.attribute(child,"file");
+              package->timeBuild = _helper.attribute(child,"build");
             }
             else if (name == "size") {
-              at.package->sizePackage = _helper.attribute(child,"package");
-              at.package->sizeInstalled = _helper.attribute(child,"installed");
-              at.package->sizeArchive = _helper.attribute(child,"archive");
+              package->sizePackage = _helper.attribute(child,"package");
+              package->sizeInstalled = _helper.attribute(child,"installed");
+              package->sizeArchive = _helper.attribute(child,"archive");
             }
             else if (name == "location") {
-              at.package->location = _helper.attribute(child,"href");
+              package->location = _helper.attribute(child,"href");
             }
             else if (name == "format") {
-       parseFormatNode (&*at.package, child);
+       parseFormatNode (&*package, child);
             }
             else if (name == "pkgfiles")
             {
-       parsePkgFilesNode (&*at.package, child);
+       parsePkgFilesNode (&*package, child);
             }
             else {
               WAR << "YUM <atoms/package> contains the unknown element <"
@@ -433,16 +431,14 @@ namespace zypp {
             }
           }
         }
-        dataPtr->atoms.push_back(at);
+        dataPtr->atoms.push_back(package);
       }
       
       void
       YUMPatchParser::parseScriptNode(YUMPatchDataPtr dataPtr,
                                      xmlNodePtr formatNode)
       {
-        YUMPatchAtom at;
-        at.type = "script";
-        at.script = new YUMPatchScript;
+       shared_ptr<YUMPatchScript> script(new YUMPatchScript);
       
         // FIXME move the respective method to a common class, inherit it  
         YUMPrimaryParser prim;
@@ -453,33 +449,33 @@ namespace zypp {
           if (_helper.isElement(child)) {
             string name = _helper.name(child);
             if (name == "name") {
-       at.script->name = _helper.content(child);
+       script->name = _helper.content(child);
             }
             else if (name == "version") {
-              at.script->epoch = _helper.attribute(child,"epoch");
-              at.script->ver = _helper.attribute(child,"ver");
-              at.script->rel = _helper.attribute(child,"rel");
+              script->epoch = _helper.attribute(child,"epoch");
+              script->ver = _helper.attribute(child,"ver");
+              script->rel = _helper.attribute(child,"rel");
             }
             else if (name == "do") {
-       at.script->do_script = _helper.content(child);
+       script->do_script = _helper.content(child);
             }
             else if (name == "undo") {
-       at.script->undo_script = _helper.content(child);
+       script->undo_script = _helper.content(child);
             }
             else if (name == "provides") {
-              prim.parseDependencyEntries(& at.script->provides, child);
+              prim.parseDependencyEntries(& script->provides, child);
             }
             else if (name == "conflicts") {
-              prim.parseDependencyEntries(& at.script->conflicts, child);
+              prim.parseDependencyEntries(& script->conflicts, child);
             }
             else if (name == "obsoletes") {
-              prim.parseDependencyEntries(& at.script->obsoletes, child);
+              prim.parseDependencyEntries(& script->obsoletes, child);
             }
             else if (name == "requires") {
-              prim.parseDependencyEntries(& at.script->requires, child);
+              prim.parseDependencyEntries(& script->requires, child);
             }
             else if (name == "freshen") {
-              prim.parseDependencyEntries(& at.script->requires, child);
+              prim.parseDependencyEntries(& script->requires, child);
             }
             else {
               WAR << "YUM <atoms/script> contains the unknown element <"
@@ -488,17 +484,15 @@ namespace zypp {
             }
           }
         }
-        dataPtr->atoms.push_back(at);
+        dataPtr->atoms.push_back(script);
       }
       
       void
       YUMPatchParser::parseMessageNode(YUMPatchDataPtr dataPtr,
                                      xmlNodePtr formatNode)
       {
-        YUMPatchAtom at;
-        at.type = "message";
-        at.message = new YUMPatchMessage;
-        at.message->type = _helper.attribute(formatNode,"type");
+       shared_ptr<YUMPatchMessage> message(new YUMPatchMessage);
+        message->type = _helper.attribute(formatNode,"type");
       
         // FIXME move the respective method to a common class, inherit it  
         YUMPrimaryParser prim;
@@ -509,30 +503,30 @@ namespace zypp {
           if (_helper.isElement(child)) {
             string name = _helper.name(child);
             if (name == "name") {
-       at.message->name = _helper.content(child);
+       message->name = _helper.content(child);
             }
             else if (name == "version") {
-              at.message->epoch = _helper.attribute(child,"epoch");
-              at.message->ver = _helper.attribute(child,"ver");
-              at.message->rel = _helper.attribute(child,"rel");
+              message->epoch = _helper.attribute(child,"epoch");
+              message->ver = _helper.attribute(child,"ver");
+              message->rel = _helper.attribute(child,"rel");
             }
             else if (name == "text") {
-       at.message->text = _helper.content(child);
+       message->text = _helper.content(child);
             }
             else if (name == "provides") {
-              prim.parseDependencyEntries(& at.message->provides, child);
+              prim.parseDependencyEntries(& message->provides, child);
             }
             else if (name == "conflicts") {
-              prim.parseDependencyEntries(& at.message->conflicts, child);
+              prim.parseDependencyEntries(& message->conflicts, child);
             }
             else if (name == "obsoletes") {
-              prim.parseDependencyEntries(& at.message->obsoletes, child);
+              prim.parseDependencyEntries(& message->obsoletes, child);
             }
             else if (name == "requires") {
-              prim.parseDependencyEntries(& at.message->requires, child);
+              prim.parseDependencyEntries(& message->requires, child);
             }
             else if (name == "freshen") {
-              prim.parseDependencyEntries(& at.message->requires, child);
+              prim.parseDependencyEntries(& message->requires, child);
             }
             else {
               WAR << "YUM <atoms/message> contains the unknown element <"
@@ -541,7 +535,7 @@ namespace zypp {
             }
           }
         }
-        dataPtr->atoms.push_back(at);
+        dataPtr->atoms.push_back(message);
       }
 
     } // namespace yum