Add Basic Managment

This commit is contained in:
ayhammamoun 2019-09-16 14:49:23 +03:00
parent 5b29d3d5c6
commit 777d3d102d
14 changed files with 17428 additions and 0 deletions

34
CMakeLists.txt Normal file
View File

@ -0,0 +1,34 @@
cmake_minimum_required(VERSION 3.5)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
message("${CMAKE_CXX_COMPILER_ID}")
# Set c++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Set c++ compiler options
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -Wall -Werror")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -Wall -Werror")
# Set build type definitions.
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-D__DEBUG__)
endif (CMAKE_BUILD_TYPE STREQUAL "Debug")
if (CMAKE_BUILD_TYPE STREQUAL "Release")
add_definitions(-D__RELEASE__)
endif (CMAKE_BUILD_TYPE STREQUAL "Release")
# skidjular
project("skidjular")
file (GLOB_RECURSE skidjular_hdrs "skidjular/*.h")
file (GLOB_RECURSE skidjular_srcs "skidjular/*.cpp")
include_directories("skidjular/")
add_executable(skidjular ${skidjular_hdrs} ${skidjular_srcs})

7
build-debug.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh
mkdir build
cd build
cmake -GNinja -DCMAKE_BUILD_TYPE=Debug ..
ninja -j8
cd ..

7
build-release.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh
mkdir build
cd build
cmake -GNinja -DCMAKE_BUILD_TYPE=Release ..
ninja -j8
cd ..

4
clean.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
rm -rf bin
rm -rf build

11
default.nix Normal file
View File

@ -0,0 +1,11 @@
with import <nixpkgs> {}; {
skidjularENV = stdenv.mkDerivation {
name = "skidjular-env";
buildInputs = [
stdenv
cmake
gcc
ninja
];
};
}

View File

@ -0,0 +1,13 @@
#include "dispatcher.h"
Dispatcher::Dispatcher(std::vector<std::string> args) {
this->m_parsedArgs = args;
}
Dispatcher::~Dispatcher(void) {}
auto Dispatcher::dispatch()->disfunc_ret {
return disfunc_ret_fail;
}
auto Dispatcher::addArgument(std::vector<std::string> argument, disfunc func)->void {
}

View File

@ -0,0 +1,31 @@
#pragma once
#ifndef DISPATCHER_H
#define DISPATCHER_H
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <functional>
#define disfunc_ret bool
#define disfunc_ret_fail false
#define disfunc_ret_success true
#define disfunc_arg
//#define disfunc std::function<disfunc_ret(disfunc_arg)>
using disfunc = std::function<disfunc_ret(disfunc_arg)>;
class Dispatcher {
public:
Dispatcher(std::vector<std::string> args);
~Dispatcher(void);
auto dispatch()->disfunc_ret;
auto addArgument(std::vector<std::string> argument, disfunc func)->void;
private:
std::vector<std::string> m_parsedArgs;
std::map<std::vector<std::string>, std::string> m_argumentArr;
};
#endif

22
skidjular/main.cpp Normal file
View File

@ -0,0 +1,22 @@
#include <iostream>
#include <string>
#include <memory>
#include "parser/parser.h"
#include "dispatcher/dispatcher.h"
#include "tree/tree.h"
int main(int argc, char** args) {
Tree<int> test;
test.addNode("", "root", 5);
test.addNode("root", "test1", 1);
test.addNode("root", "test3", 3);
test.addNode("test3", "test2", 2);
std::cout << test.searchTree(test.getTree(), "test2")->s_data;
test.remNode("test3");
test.printTree(test.getTree());
std::cout << test.searchTree(test.getTree(), "test2")->s_data;
return 0;
}

View File

@ -0,0 +1,17 @@
#include "parser.h"
Parser::Parser(int argc, char** args) {
if (argc <= 1) {
std::cout << "Usage: skidjular --help or -h\n";
exit(1);
}
args++;
for (int i = 0; i < argc-1; i++)
this->m_parsedArgs.push_back(*(args++));
}
Parser::~Parser(void) {}
auto Parser::get()->std::vector<std::string> {
return this->m_parsedArgs;
}

20
skidjular/parser/parser.h Normal file
View File

@ -0,0 +1,20 @@
#pragma once
#ifndef PARSER_H
#define PARSER_H
#include <iostream>
#include <string>
#include <vector>
class Parser {
public:
Parser(int argc, char** args);
~Parser(void);
auto get()->std::vector<std::string>;
private:
std::vector<std::string> m_parsedArgs;
};
#endif

View File

51
skidjular/tree/tree.h Normal file
View File

@ -0,0 +1,51 @@
#pragma once
#ifndef SKIDS_TREE_H
#define SKIDS_TREE_H
#include <iostream>
#include <vector>
#include <map>
#include <memory>
template<typename T>
struct TreeNode {
std::string s_name;
std::shared_ptr<TreeNode<T>> s_parent;
std::vector<std::shared_ptr<TreeNode<T>>> s_childs;
T s_data;
};
template<typename T>
class Tree {
public:
Tree(void);
~Tree(void);
auto addNode(std::string parent_name, std::string node_name, T data)->bool;
auto addNode(TreeNode<T> node)->bool;
auto remNode(TreeNode<T> node)->bool;
auto remNode(int index)->bool;
auto remNode(std::string name)->bool;
auto searchTree(std::shared_ptr<TreeNode<T>> root, std::string name)->std::shared_ptr<TreeNode<T>>;
auto getTree(void)->std::shared_ptr<TreeNode<T>>;
auto printTree(std::shared_ptr<TreeNode<T>> root)->void;
private:
auto deleteTree(std::shared_ptr<TreeNode<T>> root)->bool;
auto printTree(std::shared_ptr<TreeNode<T>> root, int deep)->void;
private:
std::shared_ptr<TreeNode<T>> m_treeRoot;
std::vector<std::shared_ptr<TreeNode<T>>> m_treeNodes;
std::map<std::string, int> m_treeIDMap;
bool m_treeIDMapDirty = false;
};
#include "tree.tpp"
#endif

136
skidjular/tree/tree.tpp Normal file
View File

@ -0,0 +1,136 @@
#include "tree.h"
template<typename T>
Tree<T>::Tree(void) {}
template<typename T>
Tree<T>::~Tree(void) {
this->deleteTree(this->m_treeRoot);
}
template<typename T>
auto Tree<T>::addNode(std::string parent_name, std::string node_name, T data)->bool {
std::shared_ptr<TreeNode<T>> result = std::make_shared<TreeNode<T>>(TreeNode<T>());
// Fill data for new node.
result->s_name = node_name;
result->s_data = data;
// Check if new node is a root node.
if (parent_name == "") {
// TODO: check return of delete function.
if (this->m_treeRoot) this->deleteTree(this->m_treeRoot);
this->m_treeRoot = result;
}
else {
// Find parent for new node.
result->s_parent = this->searchTree(this->getTree(), parent_name);
// Add new node as child of parent node, if and only if it's not a root node.
result->s_parent->s_childs.push_back(result);
}
// Add new Node to node array.
this->m_treeNodes.push_back(result);
// Add new Node to nodeID map.
this->m_treeIDMap.insert(std::make_pair(result->s_name, (int)(m_treeNodes.size()-1)));
return true;
}
template<typename T>
auto Tree<T>::addNode(TreeNode<T> node)->bool {
std::shared_ptr<TreeNode<T>> result = std::make_shared<TreeNode<T>>(node);
// Add new Node to node array.
this->m_treeNodes.push_back(result);
// Add new Node to nodeId map.
this->m_treeIDMap.insert(std::make_pair(result->s_name, (int)(m_treeNodes.size()-1)));
// Check if new node is a root node.
if (result->s_name == "") {
// TODO: check return of delete function.
if (this->m_treeRoot) this->deleteTree(this->m_treeRoot);
this->m_treeRoot = result;
}
else
// Add new node as child of parent node, if and only if it's not a root node.
result->s_parent->s_childs.push_back(result);
return true;
}
template<typename T>
auto Tree<T>::remNode(TreeNode<T> node)->bool {
return this->deleteTree(this->searchTree(this->getTree(), node.s_name));
}
template<typename T>
auto Tree<T>::remNode(int index)->bool {
return this->deleteTree(this->m_treeNodes[index]);
}
template<typename T>
auto Tree<T>::remNode(std::string name)->bool {
return this->deleteTree(this->searchTree(this->getTree(), name));
}
template<typename T>
auto Tree<T>::getTree(void)->std::shared_ptr<TreeNode<T>> {return this->m_treeRoot;}
template<typename T>
auto Tree<T>::searchTree(std::shared_ptr<TreeNode<T>> root, std::string name)->std::shared_ptr<TreeNode<T>> {
if (this->m_treeIDMapDirty) {
// Check if root is null.
if (root == nullptr) return nullptr;
// Check if passed node is the searched node.
if (root->s_name == name)
return root;
// Check if one of the childs is the searched node.
for (auto item : root->s_childs) {
auto result = this->searchTree(item, name);
if (result->s_name == name)
return result;
}
}
else
return this->m_treeNodes[this->m_treeIDMap[name]];
return std::make_shared<TreeNode<T>>(TreeNode<T>());
}
template<typename T>
auto Tree<T>::deleteTree(std::shared_ptr<TreeNode<T>> root)->bool {
// Delete it's childs first.
for (auto item : root->s_childs)
if (item && !this->deleteTree(item))
std::cout << "Couldn't delete node. Memory Leaks may occur!";
// Delete current node.
// TODO: Find how-to do it here.
// Find node and remove it from node array.
for (unsigned int i = 0; i < this->m_treeNodes.size(); i++)
if (this->m_treeNodes[i]->s_name == root->s_name) {
this->m_treeNodes.erase(std::begin(this->m_treeNodes)+i);
this->m_treeIDMapDirty = true;
}
return true;
}
template<typename T>
auto Tree<T>::printTree(std::shared_ptr<TreeNode<T>> root)->void {
this->printTree(root, 0);
}
template<typename T>
auto Tree<T>::printTree(std::shared_ptr<TreeNode<T>> root, int deep)->void {
// Print root.
if (!root->s_parent)
std::cout << "" << root->s_name << "\n";
else {
for (int i = 0; i < deep; i++)
std::cout << " ";
std::cout << "" << root->s_name << "\n";
}
// Print it's childs.
for (auto item : root->s_childs)
this->printTree(item, deep+1);
}

17075
vendor/catch.hpp vendored Normal file

File diff suppressed because it is too large Load Diff