summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormanzerbredes <loic.guegan_secondary@yahoo.fr>2015-03-14 20:11:18 +0400
committermanzerbredes <loic.guegan_secondary@yahoo.fr>2015-03-14 20:11:18 +0400
commit84c669f82a8ba1c841f268b0bf3b97f06db331d3 (patch)
tree604e960c4ee4a569db05026395fd4cf4da33284d
parent1f12bca33f6e9ce20181a9d09f62286d11592712 (diff)
Update parser
-rw-r--r--ParserClass/FileManContainer/Website.cpp8
-rw-r--r--ParserClass/FileManContainer/Website.hpp5
-rw-r--r--ParserClass/FileManParser.cpp27
-rw-r--r--ParserClass/FileManParser.hpp64
-rw-r--r--main.cpp71
5 files changed, 89 insertions, 86 deletions
diff --git a/ParserClass/FileManContainer/Website.cpp b/ParserClass/FileManContainer/Website.cpp
index 2810d48..f65a66d 100644
--- a/ParserClass/FileManContainer/Website.cpp
+++ b/ParserClass/FileManContainer/Website.cpp
@@ -12,14 +12,14 @@
#include "Website.hpp"
+//Constructor
Website::Website(){
}
-
-
+//----- Getters -----
std::string Website::getTitle(){
return this->title;
}
@@ -38,7 +38,7 @@ std::string Website::getDescription(){
-
+//----- Setters -----
void Website::setTitle(std::string title){
this->title = title;
}
@@ -56,6 +56,8 @@ void Website::setDescription(std::string description){
}
+
+//Equality comparator
bool Website::operator==(const Website& website) const{
if((this->getId()).compare(website.getId())==0){
return true;
diff --git a/ParserClass/FileManContainer/Website.hpp b/ParserClass/FileManContainer/Website.hpp
index 7d68b91..cb293d4 100644
--- a/ParserClass/FileManContainer/Website.hpp
+++ b/ParserClass/FileManContainer/Website.hpp
@@ -64,9 +64,12 @@ class Website : public AbstractIDManager {
void setPassword(std::string password);
void setDescription(std::string description);
- //bool operator==(Website const& website1, Website const& website2) const;
+ /**
+ * @brief Equality comparator
+ */
bool operator==(const Website& website) const;
+
private:
std::string title; ///< Title of the website
diff --git a/ParserClass/FileManParser.cpp b/ParserClass/FileManParser.cpp
index 1434229..57a485a 100644
--- a/ParserClass/FileManParser.cpp
+++ b/ParserClass/FileManParser.cpp
@@ -35,8 +35,20 @@ FileManParser::FileManParser(std::string data){
}
+std::string FileManParser::getDocument(){
+ std::string data=(this->document)->write_to_string();
+ return data;
+}
+std::vector<Website>* FileManParser::getWebsites(){
+ return this->websites;
+}
+
+
+
+
+//----------------Container part------------------------
void FileManParser::initWebsites(){
this->websites=new std::vector<Website>;
@@ -76,33 +88,18 @@ void FileManParser::initWebsites(){
}
else if(currentChild->get_name().compare("description")==0){
newWebsite.setDescription(cdataContent);
-
}
-
-
}
-
this->websites->push_back(newWebsite);
-
-
}
-
}
-std::string FileManParser::getDocument(){
- std::string data=(this->document)->write_to_string();
- return data;
-}
-
-std::vector<Website>* FileManParser::getWebsites(){
- return this->websites;
-}
void FileManParser::updateParser(){
diff --git a/ParserClass/FileManParser.hpp b/ParserClass/FileManParser.hpp
index 5c64708..f0d01e5 100644
--- a/ParserClass/FileManParser.hpp
+++ b/ParserClass/FileManParser.hpp
@@ -9,6 +9,12 @@
*/
+
+#ifndef __FileManParser__
+#define __FileManParser__
+
+
+
//----- std -----
#include <iostream>
#include <sstream>
@@ -24,7 +30,14 @@
-
+/**
+ * @class FileManParser FileManParser.hpp "/ParserClass/FileManContainer/FileManParser.hpp"
+ * @brief Class for parser un xml file in a string.
+ * @author manzerbredes
+ *
+ * Parse string using libxml++ library.
+ *
+ */
class FileManParser{
@@ -34,39 +47,68 @@ class FileManParser{
FileManParser(std::string data);
- //Get document in string
+ /**
+ * @brief Get document in string
+ *
+ * @return a string that contain the document
+ *
+ * Return current document.
+ * To have an up-to-date document, please run updateParser() before.
+ *
+ */
std::string getDocument();
- //Get container vector pointer:
+ /**
+ * @brief Write data in encrypted file.
+ *
+ * @return vector pointer that point to the vector of website in document
+ *
+ * You can modified this vector, and for apply change run updateParser()
+ *
+ */
std::vector<Website>* getWebsites();
- //Apply change that have made on container
+ /**
+ * @brief Update the parser
+ *
+ * Apply all modifications you have made on the vector object (example std::vector<Website>* websites).
+ *
+ */
void updateParser();
private:
- //Instaciate all website container
+ /**
+ * @brief Instanciate websites vector
+ *
+ * Read the document and create all Website object and put them into
+ * the websites vector attribute.
+ *
+ */
void initWebsites();
//Parser attributes
- std::stringstream dataStream;
- xmlpp::DomParser parser;
+ std::stringstream dataStream; ///< Contain the document you want to parse
+ xmlpp::DomParser parser; ///< Contain the parser
//Document attributes
- xmlpp::Document* document;
- xmlpp::Node* rootNode;
+ xmlpp::Document* document; ///< Contain the document (generate by the parser and dataStream)
+ xmlpp::Node* rootNode; ///< Contain the root node of the document
//Website attributes
- xmlpp::Node* websitesNode;
- std::vector<Website> *websites;
+ xmlpp::Node* websitesNode; ///< Contain the websites node of the document
+ std::vector<Website> *websites; ///< Contain all website of the document (you can modify it and run updateParser to apply all modifications).
};
+
+
+#endif
diff --git a/main.cpp b/main.cpp
index 14c5227..c392103 100644
--- a/main.cpp
+++ b/main.cpp
@@ -11,21 +11,22 @@
+
//----- std -----
#include <iostream>
#include <string>
#include <vector>
+
//----- class -----
#include "FileManIOFile.hpp"
#include "FileManParser.hpp"
#include "Website.hpp"
-#include <list>
-#include <cstdlib>
-#include <libxml++/nodes/node.h>
-#include <libxml++/libxml++.h>
+
+
+
/**
* @fn int main(int argc, char *argv[])
@@ -37,72 +38,30 @@
*/
int main(int argc, char *argv[]){
- /*
- FileManIOFile fichier("Doxygen/bob.bin");
-
- fichier.read("loic");
-
- std::cout << fichier.getData();*/
-
-
- std::stringstream xml;
- xml <<"<?xml version=\"1.0\" standalone=\"yes\" ?>\n\
-<forgetIt> \n\
-<websites> \n\
- \n\
- </websites> \n\
-</forgetIt> \n\
- ";
-
-
- /*FileManParser parser(xml);
+ //TEST PARSER FAKE ARGUMENT
+ FileManParser xmlParser("");
- std::vector<Website> websites= parser.getContainer();
- std::cout << typeid(websites.at(0)).name();*/
+ std::vector<Website> *siteWeb=xmlParser.getWebsites();
- /*xmlpp::DomParser parser;
- parser.parse_file("Doxygen/doc.xml");
- xmlpp::Document* doc=parser.get_document();
- const xmlpp::Node* pNode = doc->get_root_node(); //deleted by DomParser.
- const Glib::ustring nom="news";
- const Glib::ustring nm="";
- xmlpp::Element* elem=(xmlpp::Element*)pNode;*/
+ siteWeb->erase(siteWeb->begin()+1);
- //std::vector<xmlpp::Node*> websites=pNode->find("//websites/*/attribute::id");
-/*
- xmlpp::Element* ell=(xmlpp::Element*)websites.at(0);
- ell->set_child_text("56");
- elem->add_child(nom);
+ xmlParser.updateParser();
- std::cout << doc->write_to_string();*/
- //std::cout << (elem->get_child_text())->get_content();
+ //Save modification in file
+ FileManIOFile save("Doxygen/bob.bin");
+ save.write("loic", xmlParser.getDocument());
- FileManParser fichier("loic");
+ //Print
+ std::cout << xmlParser.getDocument();
- std::vector<Website> *bb=fichier.getWebsites();
-
-
- Website a;
- a.setTitle("pierre");
-
-
- bb->push_back(a);
-
-
-
-
- fichier.updateParser();
-
- std::cout << fichier.getDocument();
return 0;
-
}