← Back to team overview

wintermute-devel team mailing list archive

[Merge] lp:~gentoolx/wintermute/database-xml into lp:~wintermute-devel/wintermute/database

 

Adrian Borucki has proposed merging lp:~gentoolx/wintermute/database-xml into lp:~wintermute-devel/wintermute/database with lp:~gentoolx/wintermute/database-archives as a prerequisite.

Requested reviews:
  Wintermute Developers (wintermute-devel): feature-add

For more details, see:
https://code.launchpad.net/~gentoolx/wintermute/database-xml/+merge/60847

This branch contains changes enabling Boost XML archives as a read/write backend. Also, XmlNodeWriter is now enabled and working (tested).
-- 
https://code.launchpad.net/~gentoolx/wintermute/database-xml/+merge/60847
Your team Wintermute Developers is requested to review the proposed merge of lp:~gentoolx/wintermute/database-xml into lp:~wintermute-devel/wintermute/database.
=== modified file 'include/wntr/data/linguistics.hpp'
--- include/wntr/data/linguistics.hpp	2011-05-12 22:24:35 +0000
+++ include/wntr/data/linguistics.hpp	2011-05-12 22:24:35 +0000
@@ -25,6 +25,8 @@
 #define	LINGUISTICS_HPP
 
 #include <boost/signals.hpp>
+#include <boost/serialization/nvp.hpp>
+
 #include <jsoncpp/json.hpp>
 #include <libxml++/libxml++.h>
 
@@ -518,8 +520,10 @@
 
             /**
              */
-            class XmlNode {
+            class XmlNode 
+            {
                 typedef map<const string, Document*> XmlDataSources;
+                
             protected:
                 /**
                  *
@@ -563,7 +567,8 @@
             /**
              *
              */
-            class XmlNodeReader : public NodeReader, protected XmlNode {
+            class XmlNodeReader : public NodeReader, protected XmlNode, protected LocalNode
+            {
             protected:
                 /**
                  *
@@ -578,24 +583,28 @@
                  * @param
                  * @return
                  */
+                
                 static XmlNodeReader* obtain(const string&, const string&);
                 /**
                  *
                  * @return
                  */
-                virtual void read(Lexical& out);
+                virtual void read(Lexical& data);
             };
 
             /**
              */
-            class XmlNodeWriter : public NodeWriter, protected XmlNode {
+            class XmlNodeWriter : public NodeWriter, protected XmlNode, protected LocalNode
+            {
             protected:
                 /**
                  *
                  * @param
                  * @param
                  */
-                XmlNodeWriter(const string&, const string&);
+                XmlNodeWriter(const string& nodeID, const string& nodeLocale)
+                 : NodeWriter(nodeID, nodeLocale) {}
+                
             public:
                 /**
                  *
@@ -604,9 +613,10 @@
                  * @return
                  */
                 static XmlNodeWriter* obtain(const string&, const string&);
+                
                 /**
-                 *
-                 * @param
+                 * Write data in the XML format.
+                 * @param Lexical The reference to the Lexical object where data are to be saved from.
                  */
                 virtual void write(Lexical& data);
             };

=== modified file 'src/linguistics.cpp'
--- src/linguistics.cpp	2011-05-12 22:24:35 +0000
+++ src/linguistics.cpp	2011-05-12 22:24:35 +0000
@@ -107,11 +107,11 @@
                 jsonNodeWriter.first->connect(&JsonNode::exists);
                 jsonNodeWriter.second->connect(&JsonNodeWriter::obtain);
 
-                /*NodeInteroperingSignalPair xmlNodeWriter;
+                NodeInteroperingSignalPair xmlNodeWriter;
                 xmlNodeWriter.first = new NodeIOExistsSignal;
                 xmlNodeWriter.second = new NodeIOHandleSignal;
                 xmlNodeWriter.first->connect(&XmlNode::exists);
-                xmlNodeWriter.second->connect(&XmlNodeWriter::obtain);*/
+                xmlNodeWriter.second->connect(&XmlNodeWriter::obtain);
 #ifdef DEBUG
                 cout << "(database) Parsing linguistics data... " << endl;
 #endif
@@ -123,8 +123,8 @@
                 NodeWriter::addHandle(localNodeWriter);
 
                 if (XmlNode::loadLocale(locale)) {
-                    //NodeReader::addHandle(xmlNodeReader);
-                    //NodeWriter::addHandle(xmlNodeWriter);
+                    NodeReader::addHandle(xmlNodeReader);
+                    NodeWriter::addHandle(xmlNodeWriter);
                 }
 
                 if (JsonNode::loadLocale(locale)) {
@@ -768,40 +768,59 @@
 			  return new XmlNodeReader(nodeID, nodeLocale);
 			}
 
-            void XmlNodeReader::read(Lexical& out)
+            void XmlNodeReader::read(Lexical& data)
             {
-                ostringstream outData;
-                Element* theNode = XmlNode::obtainNode(this->getID(), this->getLocale());
-                NodeSet theLinks = theNode->find("Link");
+//                 ostringstream outData;
+//                 Element* theNode = XmlNode::obtainNode(this->getID(), this->getLocale());
+//                 NodeSet theLinks = theNode->find("Link");
 
-                outData << theNode->get_attribute_value("symbol");
+                string path = LocalNode::getPath(this->getID(), this->getLocale());
+                ifstream ifNode(path.c_str());
+                
+                {
+                    boost::archive::xml_iarchive ifNodeArchive(ifNode);
+                    ifNodeArchive >> BOOST_SERIALIZATION_NVP(data);
+                }
+                
+                /*outData << theNode->get_attribute_value("symbol");
                 if (!theLinks.empty()) {
                     for (NodeSet::const_iterator itr = theLinks.begin(); itr != theLinks.end(); itr++) {
                         Element* theLink = dynamic_cast<Element*> (*itr);
                         outData << theLink->get_attribute_value("flag") << " " << theLink->get_attribute_value("semanticID") << endl;
                     }
-                }
-                
-                string theData = outData.str();
-                
-                if (!theData.empty()) {
-                    out.flags().clear();
-                    string symbol, flags, semid;
-                    istringstream inData(theData);
-                    
-                    inData >> out.symbol();
-                    
-                    while (inData >> flags >> semid)
-                        out.flags().insert(Lexical::LexicalMap::value_type(flags, semid));
-                    
-                    inData.clear();
-                }
+                }*/
+                
+//                 string theData = outData.str();
+//                 
+//                 if (!theData.empty()) {
+//                     out.flags().clear();
+//                     string symbol, flags, semid;
+//                     istringstream inData(theData);
+//                     
+//                     inData >> out.symbol();
+//                     
+//                     while (inData >> flags >> semid)
+//                         out.flags().insert(Lexical::LexicalMap::value_type(flags, semid));
+//                     
+//                     inData.clear();
+//                 }
 
 //                 return outData.str();
             }
 
-			/*XmlNodeWriter* XmlNodeWriter::obtain (const string&, const string&){
-			}*/
+			XmlNodeWriter* XmlNodeWriter::obtain (const string& nodeID, const string& nodeLocale)
+            { return new XmlNodeWriter(nodeID, nodeLocale); }
+            
+            void XmlNodeWriter::write(Lexical& data)
+            {
+                string path = LocalNode::getPath(this->getID(), this->getLocale());
+                ofstream ofNode(path.c_str(), ios::trunc);
+                
+                {
+                    boost::archive::xml_oarchive ofNodeArchive(ofNode);
+                    ofNodeArchive << BOOST_SERIALIZATION_NVP(data);
+                }
+            }
 
             void Lexical::load(NodeReader& nodeReader)
             {
@@ -816,8 +835,8 @@
             template<class Archive>
             void Lexical::serialize(Archive& ar, unsigned int const version)
             {
-                ar & this->_symbol;
-                ar & this->_flags;
+                ar & BOOST_SERIALIZATION_NVP(_symbol);
+                ar & BOOST_SERIALIZATION_NVP(_flags);
             }
             
             string Lexical::toString()


Follow ups