diff --git a/CMakeLists.txt b/CMakeLists.txt index 0901985..9e35811 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,6 @@ add_subdirectory(Math) add_subdirectory(Allocators) add_subdirectory(Strings) add_subdirectory(Language) -add_subdirectory(CommandLine) add_subdirectory(Externals) add_subdirectory(Connection) add_subdirectory(Graphics) diff --git a/CommandLine/CMakeLists.txt b/CommandLine/CMakeLists.txt deleted file mode 100644 index 8627579..0000000 --- a/CommandLine/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -project(CommandLine) - -### ---------------------- Static Library --------------------- ### -file(GLOB SOURCES "./private/*.cpp") -file(GLOB HEADERS "./public/*.hpp") -add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS}) -target_include_directories(${PROJECT_NAME} PUBLIC ./public/) -target_link_libraries(${PROJECT_NAME} PUBLIC Language Connection) - -### -------------------------- Tests -------------------------- ### -enable_testing() -file(GLOB TEST_SOURCES "./tests/*.cpp") -add_executable(${PROJECT_NAME}Tests ${TEST_SOURCES}) -target_link_libraries(${PROJECT_NAME}Tests ${PROJECT_NAME} Utils) -add_test(NAME ${PROJECT_NAME}Tests COMMAND ${PROJECT_NAME}Tests) diff --git a/CommandLine/private/CmdLineInterpreter.cpp b/CommandLine/private/CmdLineInterpreter.cpp deleted file mode 100644 index 8b9761b..0000000 --- a/CommandLine/private/CmdLineInterpreter.cpp +++ /dev/null @@ -1,117 +0,0 @@ -#include "CmdLineInterpreter.hpp" - -#define MAX_LINE_LENGTH 1024 - -#include -#include - -using namespace tp; - -static bool helpFunction(CmdLineInterpreter* self, const CommandLine& args) { - self->help(args); - return true; -} - -void CmdLineInterpreter::help(const CommandLine& args) const { - auto commandName = args.getString("CommandName"); - auto allCommands = commandName == "_none_"; - - if (allCommands) { - printf("Commands:\n"); - for (auto command : mCommands) { - printf(" %s\n", command->key.read()); - } - return; - } - - auto idx = mCommands.presents(commandName); - if (!idx) { - printf("Command '%s' not found\n", commandName.read()); - return; - } - - printf("Command '%s'\n", commandName.read()); - auto command = &mCommands.getSlotVal(idx); - command->args->help(); -} - -CmdLineInterpreter::CmdLineInterpreter() { - auto helpArgs = new CommandLine{ { "CommandName", "_none_" } }; - - addCommand("help", helpArgs, (CommandFunction) helpFunction, this); -} - -void CmdLineInterpreter::addCommand(const String& id, CommandLine* args, CommandFunction function, void* customData) { - ASSERT(!mCommands.presents(id)) - mCommands.put(id, { args, function, customData }); -} - -void CmdLineInterpreter::run() { - char buffer[MAX_LINE_LENGTH]; - printf("Command Line Interpreter (or type 'exit' to quit):\n"); - - while (true) { - printf("%s >> ", mName.read()); - - // Read input from the user - if (fgets(buffer, MAX_LINE_LENGTH, stdin) == nullptr) { - printf("Error reading input.\n"); - return; - } - - // Remove the trailing newline character if it exists - auto length = strlen(buffer); - if (length > 0 && buffer[length - 1] == '\n') { - buffer[length - 1] = '\0'; - } - - // Check if the user wants to exit - if (strcmp(buffer, "exit") == 0) { - return; - } - - // Process the input here - processCommand(buffer); - } -} - -bool CmdLineInterpreter::processCommand(int1* commandString) { - ualni commandLen = 0; - for (auto i = commandString; *i != 0; i++) { - if (*i == ' ') break; - commandLen++; - } - - commandString[commandLen] = 0; - auto args = commandString + commandLen + 1; - - auto idx = mCommands.presents(commandString); - if (!idx) { - printf("ERROR: Command '%s' is not found\n", commandString); - printf("Please execute 'help' for more information\n\n"); - return true; - } - - auto command = &mCommands.getSlotVal(idx); - - command->args->parse(args); - - if (command->args->mError) { - printf("ERROR: Command call '%s' has invalid arguments\n", commandString); - command->args->resetError(); - return true; - } - - if (!command->function(command->customData, *command->args)) { - printf("ERROR: Command call '%s' failed\n", commandString); - return true; - } - - return true; -} - -CmdLineInterpreter::~CmdLineInterpreter() { - for (auto cmd : mCommands) { - delete cmd->val.args; - } -} diff --git a/CommandLine/private/CommandLine.cpp b/CommandLine/private/CommandLine.cpp deleted file mode 100644 index afeeeb9..0000000 --- a/CommandLine/private/CommandLine.cpp +++ /dev/null @@ -1,464 +0,0 @@ -#include "CommandLine.hpp" - -using namespace tp; - -static ModuleManifest* sModuleDependencies[] = { &gModuleTokenizer, &gModuleConnection, nullptr }; -ModuleManifest tp::gModuleCommandLine = ModuleManifest("CommandLine", nullptr, nullptr, sModuleDependencies); - -const char* regexSpace = "\n|\t| |\r"; -const char* regexFalse = "N|n|(False)|(false)"; -const char* regexTrue = "Y|y|(True)|(true)"; -const char* regexInt = "((\\-)|(\\+))?[0-9]+"; -const char* regexFloat = R"(((\-)|(\+))?([0-9]+)(\.)([0-9]*)?)"; -const char* regexString = "'{'-'}*'"; - -CommandLine::Arg::Arg(const Arg& arg) { - mId = arg.mId; - switch (arg.mType) { - case CommandLine::Arg::INT: - mType = INT; - mInt = arg.mInt; - break; - case CommandLine::Arg::FLOAT: - mType = FLOAT; - mFloat = arg.mFloat; - break; - case CommandLine::Arg::BOOL: - mType = BOOL; - mBool = arg.mBool; - break; - case CommandLine::Arg::STR: - mType = STR; - new (&mStr) StringArg(); - mStr = arg.mStr; - break; - case CommandLine::Arg::FILE_IN: - mType = FILE_IN; - new (&mFile) FileInputArg(); - mFile = arg.mFile; - break; - default: ASSERT(false) - } - mOptional = arg.mOptional; -} - -CommandLine::Arg::Arg(const String& id, Type type) { - mId = id; - switch (type) { - case CommandLine::Arg::INT: - mType = INT; - new (&mInt) IntArg(); - break; - case CommandLine::Arg::FLOAT: - mType = FLOAT; - new (&mFloat) FloatArg(); - break; - case CommandLine::Arg::BOOL: - mType = BOOL; - new (&mBool) BoolArg(); - break; - case CommandLine::Arg::STR: - mType = STR; - new (&mStr) StringArg(); - break; - case CommandLine::Arg::FILE_IN: - mType = FILE_IN; - new (&mFile) FileInputArg(); - break; - default: ASSERT(false) - } - mOptional = false; -} - -CommandLine::Arg::Arg(const String& id, const Range& aAcceptingRange) { - mId = id; - mType = FLOAT; - mInt = { 0, 0, aAcceptingRange }; - mOptional = false; -} - -CommandLine::Arg::Arg(const String& id, const Range& aAcceptingRange) { - mId = id; - mType = FLOAT; - mFloat = { 0, 0, aAcceptingRange }; - mOptional = false; -} - -CommandLine::Arg::Arg(const String& id, const Range& aAcceptingRange, alni aDefault) { - mId = id; - mType = INT; - mInt = { 0, aDefault, aAcceptingRange }; -} - -CommandLine::Arg::Arg(const String& id, const Range& aAcceptingRange, alnf aDefault) { - mId = id; - mType = FLOAT; - mFloat = { 0, aDefault, aAcceptingRange }; -} - -CommandLine::Arg::Arg(const String& id, bool aDefault) { - mId = id; - mType = BOOL; - mBool.mDefault = aDefault; -} - -CommandLine::Arg::Arg(const String& id, const char* aDefault) { - mId = id; - mType = STR; - new (&mStr) StringArg(); - mStr.mDefault = aDefault; -} - -CommandLine::Arg::~Arg() { - switch (mType) { - case CommandLine::Arg::STR: mStr.~StringArg(); break; - case CommandLine::Arg::FILE_IN: mFile.~FileInputArg(); break; - default: break; - } -} - -CommandLine::CommandLine(const InitialierList& args) { - bool optional_start = false; - - for (auto& arg : args) { - ASSERT(!mArgs.presents(arg.mId) && "Argument Redefinition") - - auto copy_arg = new Arg(arg); - - mArgs.put(arg.mId, copy_arg); - mArgsOrder.pushBack(mArgs.get(arg.mId)); - - if (arg.mOptional) { - mOptionals++; - } - - if (optional_start) { - ASSERT(arg.mOptional && "Not Optional Argument After Optionals") - } else if (arg.mOptional) { - optional_start = true; - } - } - - mTokenizer.build({ - { regexSpace, TokType::SPACE }, - { regexFalse, TokType::BOOL_FALSE }, - { regexTrue, TokType::BOOL_TRUE }, - { regexInt, TokType::INT }, - { regexFloat, TokType::FLOAT }, - { regexString, TokType::STR }, - }); - - ASSERT(mTokenizer.isBuild() && "Internal Error") - - mArgumentTokenizer.build({ { regexSpace, ArgTokType::SPACE }, { "{ - }*", ArgTokType::ARG } }); - - ASSERT(mTokenizer.isBuild() && "Internal Error") -} - -CommandLine::~CommandLine() { - for (auto arg : mArgsOrder) { - delete arg.data(); - } -} - -bool CommandLine::parse(char argc, const char* argv[], bool logError, ualni skipArgs) { - // discard some arguments - argc -= (char) skipArgs; - argv += skipArgs; - - if (argc < mArgs.size() - mOptionals) { - ErrInvalidArgCount(); - if (logError) { - ErrLog(); - } - return false; - } - - ualni idx = 0; - for (auto arg : mArgsOrder) { - if (idx < argc) { - parseArg(*arg.data(), argv[idx]); - } else { - initDefault(*arg.data()); - } - if (mError) { - if (logError) ErrLog(); - return false; - } - idx++; - } - return true; -} - -bool CommandLine::parse(const char* args, bool logError) { - mArgumentTokenizer.bindSource(args); - mArgumentTokenizer.reset(); - - ualni argc = 0; - auto tok = mArgumentTokenizer.readTok(); - auto argument = mArgsOrder.first(); - - while (tok != ArgTokType::FAILURE && tok != ArgTokType::END) { - if (tok != ArgTokType::ARG) { - tok = mArgumentTokenizer.readTok(); - continue; - } - - if (!argument) { - ErrInvalidArgCount(); - if (logError) ErrLog(); - return false; - } - - parseArg(*argument->data, mArgumentTokenizer.extractVal().read()); - - if (mError && logError) { - ErrLog(); - return false; - } - - argc++; - argument = argument->next; - tok = mArgumentTokenizer.readTok(); - } - - ualni idx = 0; - for (auto arg : mArgsOrder) { - if (idx >= argc) { - initDefault(*arg.data()); - } - if (mError) { - if (logError) ErrLog(); - return false; - } - idx++; - } - return true; -} - -alni CommandLine::getInt(const String& id) const { - auto& arg = getArg(id, Arg::INT); - return arg.mInt.mVal; -} -alnf CommandLine::getFloat(const String& id) const { - auto& arg = getArg(id, Arg::FLOAT); - return arg.mFloat.mVal; -} -bool CommandLine::getBool(const String& id) const { - auto& arg = getArg(id, Arg::BOOL); - return arg.mBool.mFlag; -} -const String& CommandLine::getString(const String& id) const { - auto& arg = getArg(id, Arg::STR); - return arg.mStr.mStr; -} -const LocalConnection::Location& CommandLine::getFile(const String& id) const { - auto& arg = getArg(id, Arg::FILE_IN); - return arg.mFile.mFileLocation; -} - -CommandLine::Arg& CommandLine::getArg(const String& id, Arg::Type type) { - auto idx = mArgs.presents(id); - ASSERT(idx && "Invalid Id") - auto& arg = mArgs.getSlotVal(idx); - ASSERT(arg->mType == type && "Invalid Type Requested") - return *arg; -} - -const CommandLine::Arg& CommandLine::getArg(const String& id, Arg::Type type) const { - auto idx = mArgs.presents(id); - ASSERT(idx && "Invalid Id") - auto& arg = mArgs.getSlotVal(idx); - ASSERT(arg->mType == type && "Invalid Type Requested") - return *arg; -} - -void CommandLine::ErrInvalidArgCount() { mError = { "Invalid Number Of Arguments Passed", nullptr }; } -void CommandLine::ErrInvalidArgSyntax(Arg* arg) { mError = { "Invalid Syntax Of Argument", arg }; } -void CommandLine::ErrInvalidArgType(Arg* arg) { mError = { "Invalid Type Of Argument", arg }; } -void CommandLine::ErrFileNotExists(Arg* arg) { mError = { "File Not Exists", arg }; } -void CommandLine::ErrFileCouldNotOpen(Arg* arg) { mError = { "Could Not Open File", arg }; } -void CommandLine::ErrValNotinRange(Arg* arg) { mError = { "Value Not In Range", arg }; } - -void CommandLine::ErrLog() { - printf("\nERROR : Invalid Command Line\n"); - - if (mError.mArg) { - alni idx = 0; - for (auto arg : mArgsOrder) { - if (mError.mArg == arg.data()) break; - idx++; - } - - printf("\nArgument: %lli\n", idx); - logArg(*mError.mArg); - } - - printf("Error Description: %s. \n", mError.mDescr); - - printf("\nExpected Arguments are: \n"); - ualni idx = 0; - for (auto arg : mArgsOrder) { - printf(" -- %lli -- \n", idx); - logArg(*arg.data()); - idx++; - } - - printf("\nNote regex for types are:\n"); - printf(" False - %s\n", regexFalse); - printf(" True - %s\n", regexTrue); - printf(" Int - %s\n", regexInt); - printf(" Float - %s\n", regexFloat); - printf(" String - %s\n", regexString); - printf(" File - else\n"); -} - -void CommandLine::logArg(const Arg& arg) { - switch (arg.mType) { - case Arg::INT: - { - printf("Type : Int\n"); - printf("Range : %lli - %lli\n", arg.mInt.mAcceptingRange.mBegin, arg.mInt.mAcceptingRange.mEnd); - if (arg.mOptional) { - printf("Default : %lli\n", arg.mInt.mDefault); - } - printf("Value : %lli\n", arg.mInt.mVal); - } - break; - case Arg::FLOAT: - { - printf("Type : Float\n"); - printf("Range : %f - %f\n", (halnf) arg.mFloat.mAcceptingRange.mBegin, (halnf) arg.mFloat.mAcceptingRange.mEnd); - if (arg.mOptional) { - printf("Default : %f\n", arg.mFloat.mDefault); - } - printf("Value : %f\n", arg.mFloat.mVal); - } - break; - case Arg::BOOL: - { - printf("Type : Bool\n"); - if (arg.mOptional) { - printf("Default : %s\n", arg.mBool.mDefault ? "True" : "False"); - } - printf("Value : %s\n", arg.mBool.mFlag ? "True" : "False"); - } - break; - case Arg::STR: - { - printf("Type : String\n"); - if (arg.mOptional) { - printf("Default : %s\n", arg.mStr.mDefault.read()); - } - printf("Value : %s\n", arg.mStr.mStr.read()); - } - break; - case Arg::FILE_IN: - { - printf("Type : File Input\n"); - printf("Value Path : %s\n", arg.mFile.mFileLocation.getLocation().read()); - } - break; - default: ASSERT(false) - } -} - -void CommandLine::initDefault(Arg& arg) { - switch (arg.mType) { - case Arg::INT: arg.mInt.mVal = arg.mInt.mDefault; break; - case Arg::FLOAT: arg.mFloat.mVal = arg.mFloat.mDefault; break; - case Arg::BOOL: arg.mBool.mFlag = arg.mBool.mDefault; break; - case Arg::STR: arg.mStr.mStr = arg.mStr.mDefault; break; - default: break; - } -} - -void CommandLine::parseArg(Arg& arg, const char* src) { - mTokenizer.reset(); - mTokenizer.bindSource(src); - - auto tok = mTokenizer.readTok(); - if (tok < TokType::INT || tok > TokType::STR) { - ErrInvalidArgSyntax(&arg); - return; - } - - auto val = mTokenizer.extractVal(); - - switch (arg.mType) { - case Arg::INT: - { - if (tok != TokType::INT) { - ErrInvalidArgType(&arg); - return; - } - auto converted = String::Logic::convertStringToValue(val.read(), arg.mInt.mVal); - if (converted && arg.mInt.mVal < arg.mInt.mAcceptingRange.mBegin || arg.mInt.mVal > arg.mInt.mAcceptingRange.mEnd) { - ErrValNotinRange(&arg); - return; - } - } - break; - - case Arg::FLOAT: - { - if (tok != TokType::FLOAT) { - ErrInvalidArgType(&arg); - return; - } - auto converted = String::Logic::convertStringToValue(val.read(), arg.mFloat.mVal); - if (converted && arg.mFloat.mVal < arg.mFloat.mAcceptingRange.mBegin || arg.mFloat.mVal > arg.mFloat.mAcceptingRange.mEnd) { - ErrValNotinRange(&arg); - return; - } - } - break; - - case Arg::STR: - { - if (tok != TokType::STR) { - ErrInvalidArgType(&arg); - return; - } - arg.mStr.mStr.resize(val.size() - 2); - memCopy(arg.mStr.mStr.write(), val.read() + 1, val.size() - 2); - } - break; - - case Arg::BOOL: - { - if (tok != TokType::BOOL_FALSE && tok != TokType::BOOL_TRUE) { - ErrInvalidArgType(&arg); - return; - } - arg.mBool.mFlag = tok == TokType::BOOL_TRUE; - } - break; - - case Arg::FILE_IN: - { - if (tok != TokType::STR) { - ErrInvalidArgType(&arg); - return; - } - - arg.mFile.mFileLocation.setLocation(val); - - if (!arg.mFile.mFileLocation.exists()) { - ErrFileNotExists(&arg); - return; - } - } - break; - default: ASSERT(false) - } - - arg.mIsPassed = true; -} - -void CommandLine::help() const { - printf("Arguments:\n"); - for (auto arg : mArgsOrder) { - logArg(*arg.data()); - } -} diff --git a/CommandLine/public/CmdLineInterpreter.hpp b/CommandLine/public/CmdLineInterpreter.hpp deleted file mode 100644 index 5a0943a..0000000 --- a/CommandLine/public/CmdLineInterpreter.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include "CommandLine.hpp" -#include "Map.hpp" - -namespace tp { - - class CmdLineInterpreter { - public: - typedef bool (*CommandFunction)(void* customData, const CommandLine& args); - - private: - struct Command { - CommandLine* args; - CommandFunction function; - void* customData = nullptr; - }; - - Map mCommands; - String mName = "InterpName"; - - public: - CmdLineInterpreter(); - ~CmdLineInterpreter(); - - void setName(const String& name) { mName = name; } - [[nodiscard]] const String& getName() const { return mName; } - - void help(const CommandLine& args) const; - void addCommand(const String& id, CommandLine* args, CommandFunction function, void* customData = nullptr); - void run(); - bool processCommand(int1* command); - }; -} \ No newline at end of file diff --git a/CommandLine/public/CommandLine.hpp b/CommandLine/public/CommandLine.hpp deleted file mode 100644 index e9103e3..0000000 --- a/CommandLine/public/CommandLine.hpp +++ /dev/null @@ -1,131 +0,0 @@ -#pragma once - -#include "LocalConnection.hpp" -#include "Map.hpp" -#include "Tokenizer.hpp" - - -namespace tp { - - extern ModuleManifest gModuleCommandLine; - - struct CommandLine { - - struct IntArg { - alni mVal = 0; - alni mDefault = 0; - Range mAcceptingRange = { -(std::numeric_limits::max() - 1), std::numeric_limits::max() }; - }; - - struct FloatArg { - alnf mVal = 0.f; - alnf mDefault = 0.f; - Range mAcceptingRange = { -(std::numeric_limits::max() - 1), std::numeric_limits::max() }; - }; - - struct BoolArg { - bool mFlag = false; - bool mDefault = false; - }; - - struct StringArg { - String mStr; - String mDefault; - }; - - struct FileInputArg { - LocalConnection::Location mFileLocation; - }; - - struct Arg { - String mId; - enum Type { INT, FLOAT, BOOL, STR, FILE_IN, NONE } mType = NONE; - union { - IntArg mInt; - FloatArg mFloat; - BoolArg mBool; - StringArg mStr; - FileInputArg mFile; - }; - - bool mOptional = true; - bool mIsPassed = false; - - Arg(const Arg& arg); - Arg(const String& id, Type type); - Arg(const String& id, const Range& aAcceptingRange); - Arg(const String& id, const Range& aAcceptingRange); - Arg(const String& id, const Range& aAcceptingRange, alni aDefault); - Arg(const String& id, const Range& aAcceptingRange, alnf aDefault); - Arg(const String& id, bool aDefault); - Arg(const String& id, const char* aDefault); - ~Arg(); - }; - - struct Error { - const char* mDescr = nullptr; - Arg* mArg = nullptr; - operator bool() { return mDescr != nullptr; } - } mError; - - CommandLine(const InitialierList& args); - ~CommandLine(); - - void resetError() { mError.mDescr = nullptr; } - - bool parse(char argc, const char* argv[], bool logError = true, ualni skipArgs = 1); - bool parse(const char* args, bool logError = true); - - void help() const; - - [[nodiscard]] alni getInt(const String& id) const; - [[nodiscard]] alnf getFloat(const String& id) const; - [[nodiscard]] bool getBool(const String& id) const; - [[nodiscard]] const String& getString(const String& id) const; - [[nodiscard]] const LocalConnection::Location& getFile(const String& id) const; - - const CommandLine& operator=(const CommandLine&) = delete; - - private: - enum class TokType { - SPACE, - INT, - FLOAT, - BOOL_FALSE, - BOOL_TRUE, - STR, - NONE, - FAILURE, - END, - }; - typedef SimpleTokenizer Tokenizer; - - Tokenizer mTokenizer; - Map mArgs; - List mArgsOrder; - ualni mOptionals = 0; - - enum class ArgTokType { - SPACE, - ARG, - NONE, - FAILURE, - END, - }; - SimpleTokenizer mArgumentTokenizer; - - Arg& getArg(const String& id, Arg::Type type); - [[nodiscard]] const Arg& getArg(const String& id, Arg::Type type) const; - - void ErrInvalidArgCount(); - void ErrInvalidArgSyntax(Arg* arg); - void ErrInvalidArgType(Arg* arg); - void ErrFileNotExists(Arg* arg); - void ErrFileCouldNotOpen(Arg* arg); - void ErrValNotinRange(Arg* arg); - void ErrLog(); - static void logArg(const Arg& arg); - static void initDefault(Arg& arg); - void parseArg(Arg& arg, const char* src); - }; -} diff --git a/CommandLine/tests/TestCommandLine.cpp b/CommandLine/tests/TestCommandLine.cpp deleted file mode 100644 index 18b3b91..0000000 --- a/CommandLine/tests/TestCommandLine.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "Tests.hpp" - -using namespace tp; - -static CommandLine createCmdLine() { - CommandLine cmd({ - { "bool", CommandLine::Arg::BOOL }, - { "int", CommandLine::Arg::INT }, - { "string", CommandLine::Arg::STR }, - { "float", CommandLine::Arg::FLOAT }, - }); - return cmd; -} - -TEST_DEF_STATIC(Simple) { - auto cmd = createCmdLine(); - const char* args[] = { "false", "2", "'str'", "-0.15" }; - cmd.parse(4, args, true, 0); -} - -TEST_DEF(CommandLine) { testSimple(); } diff --git a/CommandLine/tests/TestInterpreter.cpp b/CommandLine/tests/TestInterpreter.cpp deleted file mode 100644 index a927d6b..0000000 --- a/CommandLine/tests/TestInterpreter.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "CmdLineInterpreter.hpp" -#include "Tests.hpp" - -using namespace tp; - -TEST_DEF_STATIC(Simple) { - - struct TestStruct { - int val = 0; - - static bool print(TestStruct* self, const CommandLine& args) { - printf("Test Val - %i\n", (int) args.getBool("bool")); - return false; - } - }; - - TestStruct self; - - CmdLineInterpreter interp; - - interp.addCommand("test", new CommandLine{ { "bool", CommandLine::Arg::BOOL } }, (CmdLineInterpreter::CommandFunction) TestStruct::print); - - printf("test false\n", stdin); - printf("help\n", stdin); - printf("help test\n", stdin); - printf("exit\n", stdin); - - interp.run(); -} - -TEST_DEF(Interpreter) { - // testSimple(); -} diff --git a/CommandLine/tests/Tests.cpp b/CommandLine/tests/Tests.cpp deleted file mode 100644 index 9cef1ea..0000000 --- a/CommandLine/tests/Tests.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "Tests.hpp" - -int main() { - - tp::ModuleManifest* deps[] = { &tp::gModuleUtils, &tp::gModuleTokenizer, nullptr }; - tp::ModuleManifest testModule("CommandLineTest", nullptr, nullptr, deps); - - if (!testModule.initialize()) { - return 1; - } - - // testCommandLine(); - testInterpreter(); - - testModule.deinitialize(); -} diff --git a/CommandLine/tests/Tests.hpp b/CommandLine/tests/Tests.hpp deleted file mode 100644 index 5e2bbe1..0000000 --- a/CommandLine/tests/Tests.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include "Allocators.hpp" -#include "CommandLine.hpp" -#include "Testing.hpp" - -void testCommandLine(); -void testInterpreter(); diff --git a/Connection/tests/RemoteConnection.hpp b/Connection/tests/RemoteConnection.hpp new file mode 100644 index 0000000..fc3b3a8 --- /dev/null +++ b/Connection/tests/RemoteConnection.hpp @@ -0,0 +1,41 @@ +#pragma once + +#include "ConnectionCommon.hpp" +#include "List.hpp" + +namespace tp { + + class RemoteConnectionContext; + + class RemoteConnection : public Connection { + public: + class Location { + ualni mId = 0; + + public: + Location() = default; + }; + + public: + RemoteConnection(){ MODULE_SANITY_CHECK(gModuleConnection) }; + + virtual ~RemoteConnection() { + if (mStatus.isOpened()) RemoteConnection::disconnect(); + } + + public: + virtual bool connect(const Location& location, const Type& connectionInfo); + virtual bool disconnect(); + + public: + virtual const Location& getLocation() { return mLocation; } + + public: + virtual bool readBytes(Byte* bytes, SizeBytes size); + virtual bool writeBytes(const Byte* bytes, SizeBytes size); + + private: + RemoteConnectionContext* mHandle = nullptr; + Location mLocation; + }; +} \ No newline at end of file diff --git a/Connection/tests/TestRemote.cpp b/Connection/tests/TestRemote.cpp new file mode 100644 index 0000000..4034ce9 --- /dev/null +++ b/Connection/tests/TestRemote.cpp @@ -0,0 +1,11 @@ + +#include "RemoteConnection.hpp" +#include "Testing.hpp" + +using namespace tp; + +TEST_DEF_STATIC(Simple) { + TEST(false); +} + +TEST_DEF(RemoteConnection) { testSimple(); } diff --git a/Language/tests/Test.hpp b/Language/tests/Test.hpp index 98ece66..f0b25f1 100644 --- a/Language/tests/Test.hpp +++ b/Language/tests/Test.hpp @@ -1,6 +1,6 @@ #pragma once -#include "SimpleParser.hpp" +// #include "SimpleParser.hpp" const char* gGrammar = R"( # Grammar in the CF-RE United Format (Defined by language module) diff --git a/Language/tests/Tests.cpp b/Language/tests/Tests.cpp index 09ef6a6..ce4beb2 100644 --- a/Language/tests/Tests.cpp +++ b/Language/tests/Tests.cpp @@ -1,6 +1,7 @@ #include "Test.hpp" +/* using namespace tp; void testAutomation() { @@ -38,3 +39,7 @@ int main() { testModule.deinitialize(); } + +*/ + +int main() { return 0; } \ No newline at end of file diff --git a/Objects/private/parser/parser.cpp b/Objects/private/parser/parser.cpp index c0a09c5..0d1619b 100644 --- a/Objects/private/parser/parser.cpp +++ b/Objects/private/parser/parser.cpp @@ -31,6 +31,7 @@ Parser::Result Parser::parse(const tp::String& stream) { bind(parser); std::string streamStd(stream.read()); + streamStd += "\n"; // for windows os to make happy ASSERT(parser.valid()); diff --git a/Objects/tests/TestInterpreter.cpp b/Objects/tests/TestInterpreter.cpp index 2e0dc42..50119f8 100644 --- a/Objects/tests/TestInterpreter.cpp +++ b/Objects/tests/TestInterpreter.cpp @@ -41,25 +41,26 @@ if (i == 10) { )"; auto script = R"( - var i = false; - print i; + print false; )"; -TEST_DEF_STATIC(Complex) { +TEST_DEF_STATIC(Simple) { auto method = NDO_CAST(MethodObject, NDO->create("method")); auto interpreter = NDO_CAST(InterpreterObject, NDO->create("interpreter")); interpreter->getMember("target method")->setLink(method); - method->mScript->mReadable->val = script1; + method->mScript->mReadable->val = script; method->compile(); interpreter->exec(); NDO->destroy(interpreter); + + printf("\n\nEnd\n\n"); } -TEST_DEF_STATIC(Simple) { +TEST_DEF_STATIC(SimpleSave) { auto method = NDO_CAST(MethodObject, NDO->create("method")); auto interpreter = NDO_CAST(InterpreterObject, NDO->create("interpreter")); @@ -82,7 +83,22 @@ TEST_DEF_STATIC(Simple) { printf("\n\nEnd\n\n"); } +TEST_DEF_STATIC(Complex) { + auto method = NDO_CAST(MethodObject, NDO->create("method")); + auto interpreter = NDO_CAST(InterpreterObject, NDO->create("interpreter")); + + interpreter->getMember("target method")->setLink(method); + + method->mScript->mReadable->val = script1; + method->compile(); + + interpreter->exec(); + + NDO->destroy(interpreter); +} + TEST_DEF(Interpreter) { testSimple(); + testSimpleSave(); // testComplex(); } diff --git a/Objects/tests/Tests.cpp b/Objects/tests/Tests.cpp index d5bcbcd..5e84561 100644 --- a/Objects/tests/Tests.cpp +++ b/Objects/tests/Tests.cpp @@ -18,9 +18,9 @@ int main() { if (module.initialize()) { - // testParser(); - // testCore(); - // testPrimitives(); + testParser(); + testCore(); + testPrimitives(); testInterpreter(); module.deinitialize(); diff --git a/RayTracer/CMakeLists.txt b/RayTracer/CMakeLists.txt index d576294..047fd32 100644 --- a/RayTracer/CMakeLists.txt +++ b/RayTracer/CMakeLists.txt @@ -7,7 +7,7 @@ file(GLOB HEADERS "./public/*.hpp" "./public/*/*.hpp" "./applications/*.hpp") add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS}) target_include_directories(${PROJECT_NAME} PUBLIC ./public/) -target_link_libraries(${PROJECT_NAME} PUBLIC Math CommandLine Connection) +target_link_libraries(${PROJECT_NAME} PUBLIC Math Connection) ### -------------------------- Applications -------------------------- ### add_executable(rayt ./applications/Rayt.cpp applications/SceneLoad.cpp diff --git a/RayTracer/applications/Rayt.cpp b/RayTracer/applications/Rayt.cpp index 8ecda23..cdb66f2 100644 --- a/RayTracer/applications/Rayt.cpp +++ b/RayTracer/applications/Rayt.cpp @@ -3,7 +3,6 @@ #include "Rayt.hpp" -#include "CommandLine.hpp" #include "Timing.hpp" #define STB_IMAGE_WRITE_IMPLEMENTATION diff --git a/RayTracer/private/RayTracer.cpp b/RayTracer/private/RayTracer.cpp index a054eb1..43cc16d 100644 --- a/RayTracer/private/RayTracer.cpp +++ b/RayTracer/private/RayTracer.cpp @@ -1,7 +1,7 @@ #include "MathCommon.hpp" -#include "CommandLine.hpp" +#include "ConnectionCommon.hpp" #include "Module.hpp" #include "Ray.hpp" #include "RayTracer.hpp" @@ -43,7 +43,7 @@ normal = n1 * barycentric.x + n2 * barycentric.y + n3 * barycentric.z; using namespace tp; -ModuleManifest* sDependencies[] = { &gModuleMath, &gModuleCommandLine, &gModuleConnection, nullptr }; +ModuleManifest* sDependencies[] = { &gModuleMath, &gModuleConnection, nullptr }; ModuleManifest tp::gModuleRayTracer = ModuleManifest("RayTracer", nullptr, nullptr, sDependencies);