#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define endl '\n' #define endll cout << endl #define LL_MAX 2223372036854775807 typedef long long ll; template class Stack { private: struct Node { Node* back; T value; }; Node* Head; public: Stack() { Head = nullptr; } void Add(T component) { Node* bk = Head; Head = new Node; Head->back = bk; Head->value = component; } T Pop() { if (Head != nullptr) { Node* v = Head; Head = Head->back; T value = v->value; delete(v); return value; } } bool isEmpty() { if (Head == nullptr) return true; return false; } }; struct Arg { public: string Name; string Type; string Value; Arg() {} Arg(string n, string t, string v) : Name(n), Type(t), Value(v) {} Arg(string n, string t) : Name(n), Type(t), Value("None") {} }; class SysCall { public: int ID; string Name; vector Args; SysCall(int id, string name, vector args) : ID(id), Name(name), Args(args) {} string toString() { string otv = "ID: " + to_string(ID) + "\t Name: " + Name + "\n"; for (Arg a : Args) { otv += "name: " + a.Name + "\t type: " + a.Type + "\t value: " + a.Value + "\n"; } return otv; } }; class Kernel { private: vector Calls; public: Kernel() { Calls = vector({ SysCall(1, "A", vector({ Arg("AB", "int") })), SysCall(2, "B", vector({ Arg("AB", "int", "163"), Arg("BA", "string", "145")})), SysCall(3, "V", vector({ Arg("BA", "string", "145"), Arg("OT", "bool", "731"), Arg("QA", "float", "921") })), SysCall(4, "ST", vector({ Arg("A", "string", "45"), Arg("O", "string", "71"), Arg("Q", "double", "21") })), SysCall(5, "OP", vector({ Arg("B", "string", "15"), Arg("OGT", "bool", "731"), Arg("QFA", "float", "921") })) }); } void ShowAll() { for (SysCall c : Calls) { cout << c.toString() << "\n"; } } void Call(int id, Stack stack) { cout << "Старт вызова:" << endl; for (auto it : Calls) { if (it.ID == id) { cout << "Вызов " << it.Name << endl; for (auto arg : it.Args) { if (stack.isEmpty()) { cout << "Недостаток аргументов ERROR" << endl; return; } Arg a = stack.Pop(); if (arg.Type != a.Type) { cout << "Неверный тип данных Error \t Название: " << it.Name << endl; return; } cout << "Аргумент: " << a.Type << " Значение: " << a.Value << endl; } cout << "Вызов выполнен успешно" << endl; return; } } cout << "Неверный ID Error" << endl; return; } }; int main1() { setlocale(LC_ALL, "Russian"); Kernel k; endll; Stack S1; S1.Add(Arg("AB", "int")); k.Call(1, S1); endll; Stack S3; S3.Add(Arg("QA", "float", "921")); S3.Add(Arg("OT", "bool", "731")); S3.Add(Arg("BA", "string", "145")); k.Call(3, S3); endll; Stack S2; S2.Add(Arg("QA", "float", "921")); S2.Add(Arg("OT", "bool", "731")); S2.Add(Arg("BA", "string", "145")); k.Call(2, S2); endll; Stack S4; k.Call(4, S4); endll; Stack S5; k.Call(8, S5); return 0; }