Commit 8fdb9e5a authored by jan.koester's avatar jan.koester
Browse files

inittal push

parent c3ce83aa
Loading
Loading
Loading
Loading

CMakeLists.txt

0 → 100644
+7 −0
Original line number Diff line number Diff line
cmake_minimum_required(VERSION 3.31)

project(webgui)

find_package(tinyxml2 REQUIRED)

add_subdirectory(src)

examples/minimal.webui

0 → 100644
+5 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<webgui version="1.0" revesion="1" created="2025-09-17T05:44:02+02:00">
    <form color="rgb(39, 42, 44)" width="100" height="100" y="0" x="0">
    </form>
</webgui>

src/CMakeLists.txt

0 → 100644
+1 −0
Original line number Diff line number Diff line
add_library(webguilib SHARED file.cpp)

src/file.cpp

0 → 100644
+130 −0
Original line number Diff line number Diff line
#include <string>
#include <memory>
#include <tinyxml2.h>

#include <cstring>

#include "file.h"

namespace webgui {
    DomExecption &DomExecption::operator<<(const std::string &src){
        msg+=src;
        return *this;
    }

    const std::string DomExecption::what() const{
        return msg;
    }

    // --- NodeProperty Class ---
    NodeProperty::NodeProperty(const std::string &key) : _Key(key) {
        if(_Key.empty()){
            DomExecption excp;
            excp << "Proeperty must have a Key";
            throw excp;
        }
    }

    NodeProperty::NodeProperty(const NodeProperty &src) : _Key(src._Key), _Value(src._Value) {}

    NodeProperty &NodeProperty::operator=(const std::string &src) {
        _Value = src;
        return *this;
    }

    // --- Node Class ---
    Node::Node(const std::string &key) : _Key(key) {}

    Node::Node(const Node &src) : _Key(src._Key), _Value(src._Value) {
        if (src._Child) {
            _Child = std::make_unique<Node>(*src._Child);
        }
        if (src._Next) {
            _Next = std::make_unique<Node>(*src._Next);
        }
        if (src._Property) {
            _Property = std::make_unique<NodeProperty>(*src._Property);
        }
    }

    Node &Node::operator=(const std::string &src) {
        _Value = src;
        return *this;
    }

    void Node::setProperty(const NodeProperty &prop) {
        std::unique_ptr<NodeProperty> exists = std::move(_Property);
        while(exists){
            if (exists && exists->_Key == prop._Key) {
                exists->_Value=prop._Value;
                return;
            }
            exists=std::move(exists->_Next);
        }

        std::unique_ptr<NodeProperty> newProp = std::make_unique<NodeProperty>(prop);
        if (!_Property) {
            _Property = std::move(newProp);
        } else {
            while(_Property->_Next);
            _Property->_Next=std::move(newProp);
        }

        _Property->_Key=prop._Key;
        _Property->_Value=prop._Value;

    }

    void Node::delProperty(const std::string &key) {
        std::unique_ptr<NodeProperty> currentprop = std::move(_Property);
        std::unique_ptr<NodeProperty> lastprop=nullptr;
        while(currentprop){
            if (currentprop && currentprop->_Key == key) {
                if(lastprop && currentprop->_Next)
                    lastprop=std::move(currentprop->_Next);
                currentprop.reset();
            }
            currentprop=std::move(currentprop->_Next);
            lastprop=std::move(currentprop);
        }
    }

    void Node::addChild(const Node &child) {
        _Child = std::make_unique<Node>(child);
    }

    void Node::delChild() {
        _Child.reset();
    }

    void Node::nextNode(const Node &next) {
        _Next = std::make_unique<Node>(next);
    }

    void Node::delNext() {
        _Next.reset();
    }

    // --- File Class ---
    Dom::Dom() : Version("Version"), Created("Created"), Revesion("Revesion") {}

    void Dom::loadXMLfile(const std::string &path){
        tinyxml2::XMLDocument xmlfile;
        xmlfile.LoadFile(path.c_str());
        tinyxml2::XMLNode *root=xmlfile.FirstChild();
        if(!root){
            DomExecption excp;
            excp << "no root node found !";
            throw excp;
        }
        if(strcmp(root->ToElement()->Name(),"wegui")!=0){
            DomExecption excp;
            excp << "no webgui defenition file!";
            throw excp;
        }



    }

} // namespace webgui

src/file.h

0 → 100644
+61 −0
Original line number Diff line number Diff line
#include <string>
#include <memory>
namespace webgui {
    class DomExecption{
    public:
        DomExecption &operator<<(const std::string &src);
        const std::string what() const;
    private:
        std::string msg;
    };

    class NodeProperty {
    public:
        NodeProperty(const std::string &key);
        NodeProperty(const NodeProperty &src);

        NodeProperty &operator=(const std::string &src);
    private:
        std::unique_ptr<NodeProperty> _Next;
        std::string                   _Key;
        std::string                   _Value;
        friend class Node;
        friend class File;
    };

    class Node{
    public:
        Node(const std::string &key);
        Node(const Node &src);

        Node &operator=(const std::string &src);

        void setProperty(const NodeProperty &prop);
        void delProperty(const std::string &key);

        void addChild(const Node &child);
        void delChild();

        void nextNode(const Node &next);
        void delNext();
    private:
        std::string _Key;
        std::string _Value;

        std::unique_ptr<Node>         _Child;
        std::unique_ptr<Node>         _Next;
        std::unique_ptr<NodeProperty> _Property;
    };

    class Dom {
    public:
        Dom();

        void loadXMLfile(const std::string &path);

        NodeProperty              Version;
        NodeProperty              Created;
        NodeProperty              Revesion;
        std::unique_ptr<Node>     RootNode;
    };
};
Loading