diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..127a5bc --- /dev/null +++ b/LICENSE @@ -0,0 +1,23 @@ +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..088a300 --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +# strict variant + +This library was adapted from [cbeck88/strict-variant](https://github.com/cbeck88/strict-variant) to compile to Arduino/ESP32 platform. + +Documentation +============= + +On [Chris Beck's github pages](https://cbeck88.github.io/strict-variant/index.html). + +Compiler Compatibility +====================== + +`strict_variant` targets the C++11 standard. + +It is known to work with `gcc >= 4.8` and `clang >= 3.5`, and is tested against `MSVC 2015`. + +`strict_variant` can be used as-is in projects which require `-fno-exceptions` and `-fno-rtti`. + +Licensing and Distribution +========================== + +**strict variant** is available under the boost software license. \ No newline at end of file diff --git a/examples/StrictVariantBasic/main.cpp b/examples/StrictVariantBasic/main.cpp new file mode 100644 index 0000000..ff74696 --- /dev/null +++ b/examples/StrictVariantBasic/main.cpp @@ -0,0 +1,56 @@ +#include +#include "strict_variant/variant.hpp" + +using namespace strict_variant; + +std::string getString(variant v); +int getInt(variant v); +void printParams(std::vector> params); + +void setup() +{ + Serial.begin(115200); + + printf("Starting ..."); + + std::vector> params; + + variant param1; + param1 = "1031001"; + + variant param2; + param2 = 60; + + params.push_back(param1); + params.push_back(param2); + + printParams(params); + + while (1); +} + +void loop() +{ +} + +void printParams(std::vector> params) +{ + printf("Printing parameters...\n"); + + variant param1 = params[0]; + printf("Param1: %s\n", getString(param1).c_str()); + + variant vlimCurva; + vlimCurva = params[1]; + printf("Param2: %d\n", getInt(vlimCurva)); +} + +int getInt(variant v) +{ + return *(get(&v)); +} + +std::string getString(variant v) +{ + return *(get(&v)); +} \ No newline at end of file diff --git a/library.json b/library.json new file mode 100644 index 0000000..ed133b6 --- /dev/null +++ b/library.json @@ -0,0 +1,23 @@ +{ + "name": "strict_variant", + "version": "1.0.0", + "description": "A realtime/embedded-friendly C++11 variant type which is never empty and prevents undesirable implicit conversions.", + "keywords": "variant, polymorphism, container, cpp11, type-safety, union", + "authors": + [ + { + "name": "Vinicius de Sá", + "url": "https://github.com/xvinny", + "maintainer": true + } + ], + "repository": + { + "type": "git", + "url": "https://github.com/xvinny/strict_variant.git" + }, + "homepage": "https://github.com/xvinny/strict_variant", + "frameworks": [ "arduino" ], + "platforms": "*", + "examples": "examples/*/*.cpp" +} \ No newline at end of file diff --git a/library.properties b/library.properties new file mode 100644 index 0000000..556b4d1 --- /dev/null +++ b/library.properties @@ -0,0 +1,9 @@ +name=strict_variant +version=1.0.0 +author=Vinicius de Sá +maintainer=Vinicius de Sá +sentence=A realtime/embedded-friendly C++11 variant type which is never empty and prevents undesirable implicit conversions +paragraph=Includes an example for Arduino. +category=Other +url=https://github.com/xvinny/strict_variant +architectures=* \ No newline at end of file diff --git a/src/strict_variant/alloc_variant.hpp b/src/strict_variant/alloc_variant.hpp new file mode 100644 index 0000000..6782ac2 --- /dev/null +++ b/src/strict_variant/alloc_variant.hpp @@ -0,0 +1,36 @@ +// (C) Copyright 2016 - 2018 Christopher Beck + +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt) + +#pragma once + +#include +#include +#include +#include + +namespace strict_variant { + +//[ strict_variant_alloc_variant +template