Skip to content

Commit

Permalink
Merge pull request #24 from Projekt-zespolowy-TIU/dev
Browse files Browse the repository at this point in the history
Version 0.0.2 alpha
  • Loading branch information
Mat3oo authored Jun 3, 2020
2 parents da5480e + 0842f3a commit 7db6cd3
Show file tree
Hide file tree
Showing 54 changed files with 1,194 additions and 882 deletions.
59 changes: 28 additions & 31 deletions src/console/main.cpp
Original file line number Diff line number Diff line change
@@ -1,83 +1,80 @@
#include <QCoreApplication>
#include <iostream>
#include <vector>
#include <memory>
#include <QTextStream>
#include <string>
#include <QCoreApplication>

#include "IPstructs.h"
#include "SubnetsCalculatorV4.h"
#include "coreUtils.h"
#include "core/IPv4address.h"
#include "core/IPv4mask.h"
#include "core/Networkv4.h"
#include "core/SubnetsCalculatorV4.h"
#include "core/coreUtils.h"

using namespace core;

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

Networkv4 mainNetwork;
IPv4address address;
IPv4mask mask;

std::cout << "Podaj adres IPv4 sieci glownej: ";
try {
std::cin >> mainNetwork.Ip;
std::cin >> address;
} catch (const IPFormatExcept& e) {
std::cout << "\nException: " << e.what() << '\n';
return 1; //TODO: should return something more meaningful
}

std::cout << "Podaj maske IPv4 sieci glownej: ";
try {
std::cin >> mainNetwork.NetMask;
std::cin >> mask;
} catch (const IPFormatExcept& e) {
std::cout << "\nException: " << e.what() << '\n';
return 1; //TODO: should return something more meaningful
}

if(mainNetwork.isHost(*mainNetwork.Ip)) //without this UNDEFINED BEHAVIOR until using ctor for object mainNetwork
{
std::cout << "Warning: Podane IP sieci jest IP hosta dla podanej maski!\n";
mainNetwork.fix();
}
Networkv4 mainNetwork{address, mask};

std::cout << "IP sieci glownej: " << *mainNetwork.Ip << '\n'
<< "Maska sieci glownej: " << *mainNetwork.NetMask << '\n';
std::cout << "IP sieci glownej: " << mainNetwork.Ip() << '\n'
<< "Maska sieci glownej: " << mainNetwork.Mask() << '\n';

std::cout << "Ile sieci zaadresowac?: ";
int networkNumber = 0;
std::cin >> networkNumber;

std::vector<std::shared_ptr<Subnet>> subnets;

for(int i = 0; i < networkNumber; i++)
{
Subnetv4 tempSubnet;
std::cout << "Podaj nazwe podsieci [" << i << "]: ";
std::cin >> tempSubnet.SubName;
QString subname;
std::cin >> subname;
std::cout << "Ilosc hostow w podsieci [" << i << "]: ";
std::cin >> tempSubnet.HostNumber;
subnets.push_back(std::make_shared<Subnetv4>(tempSubnet));
cpp_int hostNumber;
std::cin >> hostNumber;
mainNetwork.addSubnet(hostNumber, subname);
}

SubnetsCalculatorV4 calc;

try {
calc.calcSubnets(mainNetwork, subnets);
} catch (const IPSubnetworkExcept& e) {
calc.calcSubnets(mainNetwork);
} catch (const SubnetExcept& e) {
std::cout << "\nException: " << e.what() << '\n';
return 1; //TODO: should return something more meaningful
}

for(const auto& sub : subnets)
for(const auto& sub : mainNetwork.Subnets())
{
std::cout << "\nNazwa podsieci: " << sub->SubName
<< "\nIP: " << *sub->Ip
<< " Maska: " << *sub->NetMask
<< " Broadcast: " << *sub->getBroadcast()
std::cout << "\nNazwa podsieci: " << sub->SubName()
<< "\nIP: " << sub->Ip()
<< " Maska: " << sub->Mask()
<< " Broadcast: " << *dynamic_cast<Subnetv4&>(*sub).getBroadcast()
<< "\nminHost: " << *sub->getMinHost()
<< " maxHost: " << *sub->getMaxHost() << '\n';
for(const auto& host : sub->HostsList)
std::cout << '\t' << host.Name
<< *host.Ip << '\n';
for(const auto& host : sub->HostsList())
std::cout << '\t' << host->Name()
<< " " <<host->Ip() << '\n';
}

return a.exec();
Expand Down
34 changes: 34 additions & 0 deletions src/core/Host.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "Host.h"

namespace core {
Host::Host(std::unique_ptr<IPaddress> ip, const QString& name, const cpp_int& id):
_Ip{std::move(ip)},
_Name{name},
_Id{id}
{}

const IPaddress& Host::Ip() const
{
return *_Ip;
}

QString Host::Name() const
{
return _Name;
}

boost::multiprecision::cpp_int Host::Id() const
{
return _Id;
}

void Host::Ip(std::unique_ptr<IPaddress> ip)
{
_Ip = std::move(ip);
}

void Host::Name(const QString& name)
{
_Name = name;
}
}
32 changes: 32 additions & 0 deletions src/core/Host.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once
#ifndef HOST_H
#define HOSTH

#include <memory>
#include <QString>
#include <boost/multiprecision/cpp_int.hpp>

#include "IPaddress.h"

namespace core {
using boost::multiprecision::cpp_int;

class Host final
{
public:
Host(std::unique_ptr<IPaddress> ip, const QString& name, const cpp_int& id);

const IPaddress& Ip() const;
QString Name() const;
cpp_int Id() const;

void Ip(std::unique_ptr<IPaddress> ip);
void Name(const QString& name);
private:
std::unique_ptr<IPaddress> _Ip;
QString _Name;
cpp_int _Id;
};
};

#endif // HOST_H
27 changes: 27 additions & 0 deletions src/core/IIPaddrPrintable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once
#ifndef IIPADDRPRINTABLE_H
#define IIPADDRPRINTABLE_H

#include <QString>

namespace core{
class IIPaddrPrintable
{
public:
virtual QString asStringDec() const = 0;
virtual QString asStringBin() const = 0;

//~~~~~~~~~~~~~~~~INTERFACE OVERHEAD~~~~~~~~~~~~~~~~//
public:
virtual ~IIPaddrPrintable() = default;
protected:
IIPaddrPrintable() = default;
IIPaddrPrintable(const IIPaddrPrintable&) = default;
IIPaddrPrintable& operator=(const IIPaddrPrintable&) = default;
IIPaddrPrintable(IIPaddrPrintable&&) noexcept = default;
IIPaddrPrintable& operator=(IIPaddrPrintable&&) noexcept = default;
//~~~~~~~~~~~~~~~~INTERFACE OVERHEAD~~~~~~~~~~~~~~~~//
};
};

#endif // IIPADDRPRINTABLE_H
24 changes: 0 additions & 24 deletions src/core/IIPaddress.h

This file was deleted.

22 changes: 0 additions & 22 deletions src/core/IIPmask.h

This file was deleted.

11 changes: 5 additions & 6 deletions src/core/IIPparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@
#define IIPPARSER_H

#include <QString>
#include <memory>
#include <boost/dynamic_bitset.hpp>

namespace core{
class IPaddressBase; //forward declaration
class IPmaskBase; //forward declaration

class IIPparser
{
public:
virtual std::shared_ptr<IPaddressBase> ipFromString(const QString&) const = 0;
virtual std::shared_ptr<IPmaskBase> ipMaskFromString(const QString&) const = 0;
virtual boost::dynamic_bitset<> ipFromString(const QString&) const = 0;

//~~~~~~~~~~~~~~~~INTERFACE OVERHEAD~~~~~~~~~~~~~~~~//
public:
virtual ~IIPparser() = default;
protected:
IIPparser() = default;
IIPparser(const IIPparser&) = default;
IIPparser& operator=(const IIPparser&) = default;
IIPparser(IIPparser&&) noexcept = default;
IIPparser& operator=(IIPparser&&) noexcept = default;
//~~~~~~~~~~~~~~~~INTERFACE OVERHEAD~~~~~~~~~~~~~~~~//
};
};

Expand Down
42 changes: 42 additions & 0 deletions src/core/INetwork.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once
#ifndef INETWORK_H
#define INETWORK_H

#include <vector>
#include <QString>
#include <boost/multiprecision/cpp_int.hpp>

#include "IPaddress.h"
#include "ISubnet.h"

namespace core {
using boost::multiprecision::cpp_int;

class INetwork
{
public:
virtual const IPaddress& Ip() const = 0;
virtual const IPaddress& Mask() const = 0;
virtual const std::vector<std::shared_ptr<ISubnet>>& Subnets() const = 0;

virtual void Subnets(const std::vector<std::shared_ptr<ISubnet>>& subnets) = 0;

virtual void addSubnet(const cpp_int& hostNumber, const QString& name) = 0;

virtual cpp_int hostsCapacity() const = 0;
virtual bool isSubnet(const IPaddress& hostIP) const = 0;

//~~~~~~~~~~~~~~~~INTERFACE OVERHEAD~~~~~~~~~~~~~~~~//
public:
virtual ~INetwork() = default;
protected:
INetwork() = default;
INetwork(const INetwork&) = default;
INetwork& operator=(const INetwork&) = default;
INetwork(INetwork&&) noexcept = default;
INetwork& operator=(INetwork&&) noexcept = default;
};
//~~~~~~~~~~~~~~~~INTERFACE OVERHEAD~~~~~~~~~~~~~~~~//
}

#endif // INETWORK_H
Loading

0 comments on commit 7db6cd3

Please sign in to comment.