summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-05 19:41:35 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-05 19:41:35 -0500
commita531cdb8c1e6c47e675f6c256012e61812ce0a44 (patch)
tree2645905f4b60866f1d329217035a6dce72b5ca7f
parent18700b31ed2bc43d5e76ee128d9d68b82dab798e (diff)
downloadhorizon-a531cdb8c1e6c47e675f6c256012e61812ce0a44.tar.gz
horizon-a531cdb8c1e6c47e675f6c256012e61812ce0a44.tar.bz2
horizon-a531cdb8c1e6c47e675f6c256012e61812ce0a44.tar.xz
horizon-a531cdb8c1e6c47e675f6c256012e61812ce0a44.zip
Initial prototype for a script parsing API
-rw-r--r--CMakeLists.txt28
-rw-r--r--hscript/key.hh45
-rw-r--r--hscript/keymanager.hh42
-rw-r--r--hscript/script.cc0
-rw-r--r--hscript/script.hh41
5 files changed, 156 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..8e11d96
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,28 @@
+cmake_minimum_required(VERSION 3.4)
+
+include(FindPkgConfig)
+
+project(Horizon
+ LANGUAGES CXX
+ VERSION 0.1.0)
+
+pkg_check_modules(LIBUDEV REQUIRED libudev)
+pkg_check_modules(PARTED REQUIRED libparted)
+find_library(BCNM_LIBRARY REQUIRED wpactrl PATH_SUFFIXES bcnm)
+
+set(HSCRIPT_SOURCE
+ hscript/script.cc
+)
+
+set(HSCRIPT_INCLUDE
+ hscript/script.hh
+ hscript/keymanager.hh
+ hscript/key.hh
+)
+
+add_library(hscript SHARED ${HSCRIPT_SOURCE})
+target_compile_features(hscript PRIVATE cxx_nullptr)
+target_compile_features(hscript PUBLIC cxx_unicode_literals)
+
+install(TARGETS hscript DESTINATION lib)
+install(FILES ${HSCRIPT_INCLUDE} DESTINATION include/hscript)
diff --git a/hscript/key.hh b/hscript/key.hh
new file mode 100644
index 0000000..06d34f8
--- /dev/null
+++ b/hscript/key.hh
@@ -0,0 +1,45 @@
+/*
+ * key.hh - Definition of the base Key class
+ * libhscript, the HorizonScript library for
+ * Project Horizon
+ *
+ * Copyright (c) 2019 Adélie Linux and contributors. All rights reserved.
+ * This code is licensed under the AGPL 3.0 license, as noted in the
+ * LICENSE-code file in the root directory of this repository.
+ *
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+#include <string>
+
+namespace Horizon {
+namespace Keys {
+
+/*! Base Key class, used by all Keys.
+ * A Getter method is not provided in this base Key class, because each Key may
+ * return a different type of data. For example, `network` may return `bool`.
+ */
+class Key {
+public:
+ /*! Create an instance of the Key. */
+ static Key *create();
+
+ /*! Set the data associated with the Key. */
+ void setData(std::string data);
+
+ /*! Determines if the data associated with the Key is valid. */
+ bool isValid();
+
+ /*! Determines if the Key is required to be present for the HorizonScript
+ * to be considered valid. */
+ static bool isRequired();
+
+ /*! Determines how many times this Key can be repeated.
+ * If this function returns 0, it can be repeated an unlimited number of times.
+ * If this function returns 1, it can only be present once per HorizonScript.
+ */
+ static int maxCount();
+};
+
+}
+}
diff --git a/hscript/keymanager.hh b/hscript/keymanager.hh
new file mode 100644
index 0000000..b3cd109
--- /dev/null
+++ b/hscript/keymanager.hh
@@ -0,0 +1,42 @@
+/*
+ * keymanager.hh - Definition of the key manager
+ * libhscript, the HorizonScript library for
+ * Project Horizon
+ *
+ * Copyright (c) 2019 Adélie Linux and contributors. All rights reserved.
+ * This code is licensed under the AGPL 3.0 license, as noted in the
+ * LICENSE-code file in the root directory of this repository.
+ *
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+#include <vector>
+#include <string>
+#include "key.hh"
+
+namespace Horizon {
+namespace Keys {
+
+/*! Manages the Key classes. */
+class KeyManager {
+private:
+ /*! Create the key manager */
+ KeyManager();
+public:
+ /*! Retrieve the global KeyManager instance. */
+ static const KeyManager *getKeyManager();
+
+ /*! Add a new Key to the key manager. */
+ void addKey(std::string name, bool required, int max, Key*(*key_create_fn)(void));
+
+ /*! Determines if a Key is recognised. */
+ void hasKey(std::string name);
+
+ /*! Create a new Key with the specified name.
+ * Returns nullptr if no Key exists.
+ */
+ Key *createKey(std::string name);
+};
+
+}
+}
diff --git a/hscript/script.cc b/hscript/script.cc
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/hscript/script.cc
diff --git a/hscript/script.hh b/hscript/script.hh
new file mode 100644
index 0000000..feee23b
--- /dev/null
+++ b/hscript/script.hh
@@ -0,0 +1,41 @@
+/*
+ * script.hh - Definition of the Script class
+ * libhscript, the HorizonScript library for
+ * Project Horizon
+ *
+ * Copyright (c) 2019 Adélie Linux and contributors. All rights reserved.
+ * This code is licensed under the AGPL 3.0 license, as noted in the
+ * LICENSE-code file in the root directory of this repository.
+ *
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+#include <string>
+#include <vector>
+
+namespace Horizon {
+
+struct ScriptPrivate;
+
+/*! Defines the Script class, which represents a HorizonScript. */
+class Script {
+public:
+ /*! Load a HorizonScript from the specified path and attempt to parse. */
+ Script(std::string path);
+ /*! Load a HorizonScript from the specified stream and attempt to parse. */
+ Script(std::istream &stream);
+
+ /*! Determines if the HorizonScript parsed correctly. */
+ bool isParsed();
+ /*! Determines if the HorizonScript is valid. */
+ bool isValid();
+
+ /*! Returns a list of errors found while parsing and validating the script. */
+ std::vector<std::string> scriptErrors();
+
+private:
+ /*! Internal data. */
+ ScriptPrivate *internal;
+};
+
+}