-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from Projekt-zespolowy-TIU/dev
Version 0.1.0 beta
- Loading branch information
Showing
81 changed files
with
3,848 additions
and
1,639 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
[requires] | ||
boost/1.72.0 | ||
jsonformoderncpp/3.7.3@vthiery/stable | ||
|
||
[generators] | ||
qmake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#include "FileIO.h" | ||
|
||
#include <string> | ||
#include <fstream> | ||
#include <nlohmann/json.hpp> | ||
|
||
#include "Networkv4.h" | ||
#include "Networkv6.h" | ||
|
||
namespace core{ | ||
|
||
using json = nlohmann::json; | ||
|
||
void FileIO::saveIPv4(const INetwork& netv4, const QString& path) | ||
{ | ||
std::ofstream o(path.toStdString()); | ||
|
||
info["IPv4IP"] = netv4.Ip().asStringDec().toStdString(); | ||
info["IPv4NetMask"] = netv4.Mask().asStringDec().toStdString(); | ||
|
||
info["IPv4SubnetNames"].clear(); | ||
info["IPv4SubnetHostNumbers"].clear(); | ||
|
||
for(const auto& i : netv4.Subnets()) | ||
{ | ||
info["IPv4SubnetNames"].push_back(i->SubName().toStdString()); | ||
info["IPv4SubnetHostNumbers"].push_back(i->HostNumber().str()); | ||
} | ||
|
||
o<<info; | ||
} | ||
|
||
void FileIO::loadIPv4(std::shared_ptr<INetwork>& netv4, const QString& path) | ||
{ | ||
info.clear(); | ||
std::ifstream i(path.toStdString()); | ||
i>>info; | ||
|
||
std::shared_ptr<INetwork> temp_network = std::make_shared<Networkv4>( | ||
QString{std::string(info["IPv4IP"]).c_str()}, | ||
QString{std::string(info["IPv4NetMask"]).c_str()}); | ||
|
||
for(int i=0; i<int(info["IPv4SubnetNames"].size()) ; i++) | ||
{ | ||
temp_network->addSubnet(cpp_int{std::string{info["IPv4SubnetHostNumbers"][i]}}, | ||
std::string(info["IPv4SubnetNames"][i]).c_str()); | ||
} | ||
|
||
netv4 = temp_network; | ||
} | ||
|
||
void FileIO::saveIPv6(const INetwork& netv6, const QString& path) | ||
{ | ||
std::ofstream o(path.toStdString()); | ||
|
||
info["IPv6IP"] = netv6.Ip().asStringDec().toStdString(); | ||
info["IPv6NetMask"] = netv6.Mask().asStringDec().toStdString(); | ||
|
||
info["IPv6SubnetNames"].clear(); | ||
info["IPv6SubnetHostNumbers"].clear(); | ||
|
||
for(const auto& i : netv6.Subnets()) | ||
{ | ||
info["IPv6SubnetNames"].push_back(i->SubName().toStdString()); | ||
info["IPv6SubnetHostNumbers"].push_back(i->HostNumber().str()); | ||
} | ||
|
||
o<<info; | ||
} | ||
|
||
|
||
void FileIO::loadIPv6(std::shared_ptr<INetwork>& netv6, const QString& path) | ||
{ | ||
info.clear(); | ||
std::ifstream i(path.toStdString()); | ||
i>>info; | ||
|
||
std::shared_ptr<INetwork> temp_network = std::make_shared<Networkv6>( | ||
QString{std::string(info["IPv6IP"]).c_str()}, | ||
QString{std::string(info["IPv6NetMask"]).c_str()}); | ||
|
||
for(int i = 0; i < static_cast<int>((info["IPv6SubnetNames"].size())); i++) | ||
{ | ||
temp_network->addSubnet(cpp_int{std::string{info["IPv6SubnetHostNumbers"][i]}}, | ||
std::string(info["IPv6SubnetNames"][i]).c_str()); | ||
} | ||
|
||
netv6 = temp_network; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef FILEIO_H | ||
#define FILEIO_H | ||
|
||
#include <memory> | ||
#include <QString> | ||
#include <nlohmann/json.hpp> | ||
|
||
#include "INetwork.h" | ||
|
||
|
||
using json = nlohmann::json; | ||
|
||
namespace core { | ||
class FileIO | ||
{ | ||
public: | ||
void saveIPv4(const INetwork& netv4, const QString& path); | ||
void loadIPv4(std::shared_ptr<INetwork>& netv4, const QString& path); | ||
void saveIPv6(const INetwork& netv6, const QString& path); | ||
void loadIPv6(std::shared_ptr<INetwork>& netv6, const QString& path); | ||
|
||
private: | ||
json info; | ||
}; | ||
}; | ||
|
||
|
||
|
||
#endif // FILEIO_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.