Something idk

This commit is contained in:
Shr3dd3r 2023-08-29 05:16:44 +03:00
parent c12682dd2a
commit ef784580b4
9 changed files with 67 additions and 32 deletions

View File

@ -7,4 +7,5 @@ _Эталонная имплементация библиотеки с реал
## Пространства имён ## Пространства имён
`Stadium::Base`: базовые инструменты, не подлежащие принципиальному изменению в будущем. `Stadium::Base`: базовые инструменты, не подлежащие принципиальному изменению в будущем.
`Stadium::v1`: то, что может быть изменено в последующих версиях.

View File

@ -1,5 +1,5 @@
/* /*
* event.hpp * Event.hpp
* Copyright (c) 2023 Cyclone Team. Licensed under GNU GPLv3-only terms. * Copyright (c) 2023 Cyclone Team. Licensed under GNU GPLv3-only terms.
* *
*/ */
@ -9,11 +9,18 @@
namespace Stadium { #include "KLDR.hpp"
namespace Base {
template <typename CategoryT = uint8_t, typename SubcategoryT = uint8_t>
namespace Stadium {
namespace v1 {
template <typename CategoryT = uint8_t, typename SubcategoryT = uint8_t, typename PayloadT = KLDRArray<>> // TODO: переделать через рантайм-дрисню
class Event { class Event {
// TODO: add static assertion of PayloadT (???)
// P.S.: https://stackoverflow.com/questions/874298/c-templates-that-accept-only-certain-types
public: public:
struct { struct {
CategoryT Category; CategoryT Category;
@ -21,7 +28,7 @@ class Event {
} Type; // ??? } Type; // ???
uint32_t ServerSession; uint32_t ServerSession;
// TODO: payload hash // TODO: payload hash
// TODO: payload PayloadT Payload;
}; };
} }

35
src/EventQueue.hpp Normal file
View File

@ -0,0 +1,35 @@
/*
* EventQueue.hpp
* Copyright (c) 2023 Cyclone Team. Licensed under GNU GPLv3-only terms.
*
*/
#ifndef LIBSTADIUM_EVENTQUEUE_HPP
#define LIBSTADIUM_EVENTQUEUE_HPP
#include <vector>
#include "Event.hpp"
namespace Stadium {
namespace Base {
template <typename EventT = Event<>> // TODO: переделать через рантайм-дрисню
class EventQueue {
protected:
std::vector<EventT> Queue;
public:
//void Add (EventT);
//EventT Get ();
};
}
}
#endif

View File

@ -1,5 +1,5 @@
/* /*
* kldr.hpp * KLDR.hpp
* Copyright (c) 2023 Cyclone Team. Licensed under GNU GPLv3-only terms. * Copyright (c) 2023 Cyclone Team. Licensed under GNU GPLv3-only terms.
* *
*/ */
@ -18,7 +18,8 @@
namespace Stadium { namespace Stadium {
namespace Base {
namespace v1 {
enum KLDRDefaultKeys : uint8_t { enum KLDRDefaultKeys : uint8_t {
Data = 0x01, Data = 0x01,
@ -35,6 +36,10 @@ enum KLDRDefaultKeys : uint8_t {
SignedDataHash = 0x13 SignedDataHash = 0x13
}; };
}
namespace Base {
/* /*
* KLDR stands for "Key-Length-Data-Repeat" * KLDR stands for "Key-Length-Data-Repeat"
* Schematically, binary array with KLDR-formatted data looks like this. * Schematically, binary array with KLDR-formatted data looks like this.
@ -183,7 +188,7 @@ class KLDRArray {
this->AddF(key, length, data); this->AddF(key, length, data);
} }
// Get just value from array by key // Get just pointer to value from array by key
void* Get (KeyT key) { void* Get (KeyT key) {
for (size_t i = 0; i < this->CellsAmount(); i++) { for (size_t i = 0; i < this->CellsAmount(); i++) {
if (this->Keys[i] == key) { if (this->Keys[i] == key) {
@ -193,7 +198,7 @@ class KLDRArray {
throw std::invalid_argument("invalid KLDRArray key"); throw std::invalid_argument("invalid KLDRArray key");
} }
// Get value and length from array by key // Get pointer to value and length from array by key
void* Get (KeyT key, LengthT* length) { void* Get (KeyT key, LengthT* length) {
for (size_t i = 0; i < this->CellsAmount(); i++) { for (size_t i = 0; i < this->CellsAmount(); i++) {
if (this->Keys[i] == key) { if (this->Keys[i] == key) {
@ -236,6 +241,7 @@ class KLDRArray {
}; };
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* stadium.cpp * Stadium.cpp
* Copyright (c) 2023 Cyclone Team. Licensed under GNU GPLv3-only terms. * Copyright (c) 2023 Cyclone Team. Licensed under GNU GPLv3-only terms.
* *
* -> [ Incoming Events Queue ] --> [ Base Event Handlers ] * -> [ Incoming Events Queue ] --> [ Base Event Handlers ]
@ -11,7 +11,7 @@
* <- [ Custom Methods ] * <- [ Custom Methods ]
*/ */
#include "stadium.hpp" #include "Stadium.hpp"

View File

@ -1,5 +1,5 @@
/* /*
* stadium.hpp * Stadium.hpp
* Copyright (c) 2023 Cyclone Team. Licensed under GNU GPLv3-only terms. * Copyright (c) 2023 Cyclone Team. Licensed under GNU GPLv3-only terms.
* *
*/ */
@ -9,18 +9,14 @@
#include "kldr.hpp" #include "EventQueue.hpp"
namespace Stadium { namespace Stadium {
namespace v1 { namespace v1 {
// class EventsQueue { // TODO
// public:
// void Add (); // TODO
// void Pop (); // TODO
// };
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* utils.hpp * Utils.hpp
* Copyright (c) 2023 Cyclone Team. Licensed under GNU GPLv3-only terms. * Copyright (c) 2023 Cyclone Team. Licensed under GNU GPLv3-only terms.
* *
*/ */

View File

@ -1,10 +0,0 @@
/*
* event.cpp
* Copyright (c) 2023 Cyclone Team. Licensed under GNU GPLv3-only terms.
*
*/
#include "event.hpp"

View File

@ -1,6 +1,6 @@
#include <cstdio> #include <cstdio>
#include "stadium.hpp" #include "Stadium.hpp"
#include "utils.hpp" #include "Utils.hpp"
int main () { int main () {