From 41897f295fbaf4d715a6fc099c81d4e15b48e19b Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Wed, 11 Mar 2015 19:53:47 +0400 Subject: [PATCH] Update ParserClass files --- .../FileManContainer/FileManContainer.cpp | 25 ++++++++++ .../FileManContainer/FileManContainer.hpp | 46 +++++++++++++++++++ ParserClass/FileManContainer/Website.cpp | 17 +++++++ ParserClass/FileManContainer/Website.hpp | 11 ++++- ParserClass/FileManParser.cpp | 24 ++++++++-- ParserClass/FileManParser.hpp | 5 +- main.cpp | 8 +++- 7 files changed, 128 insertions(+), 8 deletions(-) diff --git a/ParserClass/FileManContainer/FileManContainer.cpp b/ParserClass/FileManContainer/FileManContainer.cpp index e69de29..7f04be4 100644 --- a/ParserClass/FileManContainer/FileManContainer.cpp +++ b/ParserClass/FileManContainer/FileManContainer.cpp @@ -0,0 +1,25 @@ +/** + * @file FileManContainer.cpp + * @brief FileManContainer class definitions + * @author manzerbredes + * @date 11 Mars 2015 + * + * Contain all implementation of FileManContainer class. + * + */ + + +#include "FileManContainer.hpp" + +FileManContainer::FileManContainer(){ +} + + + +void FileManContainer::addWebsite(Website website){ + this->websites.push_back(website); +} + +std::vector FileManContainer::getWebsites(){ + return this->websites; +} diff --git a/ParserClass/FileManContainer/FileManContainer.hpp b/ParserClass/FileManContainer/FileManContainer.hpp index e69de29..d5be276 100644 --- a/ParserClass/FileManContainer/FileManContainer.hpp +++ b/ParserClass/FileManContainer/FileManContainer.hpp @@ -0,0 +1,46 @@ +/** + * @file FileManContainer.hpp + * @brief FileManContainer class definitions + * @author manzerbredes + * @date 11 Mars 2015 + * + * Contain all definitions of FileManContainer class. + * + */ + +#ifndef __FileManContainer__ +#define __FileManContainer__ + +//----- std ----- + +#include +#include + +//----- class ----- +#include "Website.hpp" + + +/** + * @class Website Website.hpp "/ParserClass/FileManContainer/Website.hpp" + * @brief Class for manager all FileMan container (websites etc...) + * @author manzerbredes + * + * + * + */ + +class FileManContainer{ + + public: + FileManContainer(); + + void addWebsite(Website website); + std::vector getWebsites(); + + private: + + std::vector websites; +}; + + +#endif diff --git a/ParserClass/FileManContainer/Website.cpp b/ParserClass/FileManContainer/Website.cpp index 0d25344..0e1a670 100644 --- a/ParserClass/FileManContainer/Website.cpp +++ b/ParserClass/FileManContainer/Website.cpp @@ -11,6 +11,20 @@ #include "Website.hpp" + +Website::Website(){ + boost::uuids::uuid uuid = boost::uuids::random_generator()(); + std::stringstream ss; + ss << uuid; + this->id=ss.str(); +} + + + + +std::string Website::getId(){ + return this->id; +} std::string Website::getTitle(){ return this->title; } @@ -29,6 +43,9 @@ std::string Website::getDescription(){ +void Website::setId(std::string id){ + this->id = id; +} void Website::setTitle(std::string title){ this->title = title; } diff --git a/ParserClass/FileManContainer/Website.hpp b/ParserClass/FileManContainer/Website.hpp index 01c41f9..ceb21ad 100644 --- a/ParserClass/FileManContainer/Website.hpp +++ b/ParserClass/FileManContainer/Website.hpp @@ -27,6 +27,10 @@ */ #include +#include +#include // uuid class +#include // generators +#include // streaming operators etc. @@ -43,10 +47,13 @@ class Website{ public: + Website(); + /** * @brief Containner getters. */ + std::string getId(); std::string getTitle(); std::string getUrl(); std::string getUsername(); @@ -57,6 +64,7 @@ class Website{ /** * @brief Containner setters. */ + void setId(std::string title); void setTitle(std::string title); void setUrl(std::string url); void setUsername(std::string username); @@ -66,7 +74,8 @@ class Website{ private: - std::string title; ///< Title en the website + std::string id; ///< id of the website + std::string title; ///< Title of the website std::string url; ///< Url of the website std::string username; ///< username of the account std::string password; ///< password of the account diff --git a/ParserClass/FileManParser.cpp b/ParserClass/FileManParser.cpp index 00db891..8cc72b5 100644 --- a/ParserClass/FileManParser.cpp +++ b/ParserClass/FileManParser.cpp @@ -41,8 +41,8 @@ FileManParser::FileManParser(std::string data){ -std::vector FileManParser::getWebsites(){ - return this->websites; +FileManContainer FileManParser::getContainer(){ + return this->container; } @@ -64,9 +64,25 @@ void FileManParser::initWebsites(){ std::string TagName=xercesc::XMLString::transcode(current->getNodeName()); if( current->getNodeType() == xercesc::DOMNode::ELEMENT_NODE ) { + Website newWebsite; - std::cout << this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"title"); - std::cout << this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"url"); + newWebsite.setTitle(\ + this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"title")); + + newWebsite.setUrl(\ + this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"url")); + + newWebsite.setUsername(\ + this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"username")); + + newWebsite.setPassword(\ + this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"password")); + + newWebsite.setDescription(\ + this->getContentOfChild(dynamic_cast< xercesc::DOMElement* >( current ),"description")); + + + this->container.addWebsite(newWebsite); } } diff --git a/ParserClass/FileManParser.hpp b/ParserClass/FileManParser.hpp index 88c959e..6a977db 100644 --- a/ParserClass/FileManParser.hpp +++ b/ParserClass/FileManParser.hpp @@ -15,6 +15,7 @@ //----- class ----- #include "Website.hpp" +#include "FileManContainer.hpp" //----- xerces ----- #include @@ -35,7 +36,7 @@ class FileManParser{ - std::vector getWebsites(); + FileManContainer getContainer(); void initWebsites(); @@ -50,7 +51,7 @@ class FileManParser{ xercesc::DOMElement* root; - std::vector websites; ///< contain all websites entries + FileManContainer container; ///< contain all container std::string data; ///< contain data to parse diff --git a/main.cpp b/main.cpp index 9a3b3f1..5b4c74d 100644 --- a/main.cpp +++ b/main.cpp @@ -15,11 +15,13 @@ #include #include +#include //----- class ----- #include "FileManIOFile.hpp" #include "FileManParser.hpp" - +#include "FileManContainer.hpp" +#include "Website.hpp" /** * @fn int main(int argc, char *argv[]) @@ -68,6 +70,10 @@ int main(int argc, char *argv[]){ if(fichier.isReadable()) std::cout << fichier.getData();*/ + FileManContainer container= parser.getContainer(); + std::vector websites= container.getWebsites(); + std::cout << websites.at(1).getId(); + return 0; }