Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'arguspp' C++ extension for Argus #11

Merged
merged 3 commits into from Apr 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 45 additions & 1 deletion scripts/argus.lua
Expand Up @@ -161,7 +161,11 @@ create_packages_projects(external_scaffolds)

core_projects = {
["argus"] = {
_add_includedirs = function() end,
_add_includedirs = function()
includedirs {
"../src",
}
end,
_add_defines = function() end,
_add_libdirs = function() end,
_add_external_links = function() end,
Expand Down Expand Up @@ -197,6 +201,46 @@ core_projects = {
build_c99()
end, -- _create_projects()
},
["arguspp"] = {
_add_includedirs = function()
includedirs {
"../src",
"../srcpp",
}
end,
_add_defines = function() end,
_add_libdirs = function() end,
_add_external_links = function()
links { "argus" }
end,
_add_self_links = function()
links { "arguspp" }
end,
_create_projects = function()
project "arguspp"
language "C++"
kind "StaticLib"
flags {
"ExtraWarnings",
"FatalWarnings",
"No64BitChecks",
"StaticRuntime",
"ObjcARC",
"CppLatest",
}

includedirs {
"../src",
"../srcpp",
}

files {
"../srcpp/arguspp.hpp",
"../srcpp/arguspp.cpp",
}

end, -- _create_projects()
},
["argus-test"] = {
_add_includedirs = function() end,
_add_defines = function() end,
Expand Down
89 changes: 89 additions & 0 deletions srcpp/arguspp.cpp
@@ -0,0 +1,89 @@
#include "arguspp.hpp"

#include <argus_option.h>

#include <string>
#include <vector>

auto argus_setOptionImplicitBool(void* value, int* argc, char*** argv) -> int
{
if (value)
*(bool*)value = 1;
*argc -= 1;
*argv += 1;
return 1;
}

auto argus_setOptionExplicitStdString(void* value, int* argc, char*** argv) -> int
{
if (value != nullptr)
{
std::string& str = *(static_cast<std::string*>(value));
str = (*argv)[1];
}

*argc -= 2;
*argv += 2;
return 2;
}

auto argus_setOptionExplicitStdStringView(void* value, int* argc, char*** argv) -> int
{
if (value != nullptr)
{
std::string_view& str = *(static_cast<std::string_view*>(value));
str = (*argv)[1];
}

*argc -= 2;
*argv += 2;
return 2;
}

auto argus_setOptionExplicitStdVectorOfInt(void* value, int* argc, char*** argv) -> int
{
int count = 1;
if (value != nullptr)
{
std::vector<uint8_t>& v = *(std::vector<uint8_t>*)(value);

while (--(*argc) > 0 && (*(++(*argv)))[0] != '-')
{
v.push_back(std::atoi((*argv)[0]));
count++;
}
}
return count;
}

auto argus_setOptionExplicitStdVectorOfStdString(void* value, int* argc, char*** argv) -> int
{
int count = 1;
if (value != nullptr)
{
std::vector<std::string>& v = *(std::vector<std::string>*)value;
while (--(*argc) > 0 && *(++(*argv))[0] != '-')
{
v.emplace_back((*argv)[0]);
count++;
}
}

return count;
}

auto argus_setOptionExplicitStdVectorOfStdStringView(void* value, int* argc, char*** argv) -> int
{
int count = 1;
if (value != nullptr)
{
std::vector<std::string_view>& v = *(std::vector<std::string_view>*)value;
while (--(*argc) > 0 && *(++(*argv))[0] != '-')
{
v.emplace_back((*argv)[0]);
count++;
}
}

return count;
}
14 changes: 14 additions & 0 deletions srcpp/arguspp.hpp
@@ -0,0 +1,14 @@
#ifndef ARGUSPP_HPP_INCL
#define ARGUSPP_HPP_INCL

extern "C"
{
auto argus_setOptionImplicitBool(void* value, int* argc, char*** argv) -> int;
auto argus_setOptionExplicitStdString(void* value, int* argc, char*** argv) -> int;
auto argus_setOptionExplicitStdStringView(void* value, int* argc, char*** argv) -> int;
auto argus_setOptionExplicitStdVectorOfInt(void* value, int* argc, char*** argv) -> int;
auto argus_setOptionExplicitStdVectorOfStdString(void* value, int* argc, char*** argv) -> int;
auto argus_setOptionExplicitStdVectorOfStdStringView(void* value, int* argc, char*** argv) -> int;
}

#endif // ARGUSPP_HPP_INCL