A lightweight C++20 header-only library providing fundamental type definitions and utilities for the Neko ecosystem.
NekoSchema serves as a foundational module that defines common types, enumerations, and exception handling utilities. It provides consistent type aliases and basic infrastructure components that can be shared across multiple projects.
- Type Definitions: Standard type aliases for integers, strings, and character types
- Enumerations: Common enums for synchronization modes, states, and priorities
- Exception Handling: Comprehensive exception classes with source location tracking
- Auto Source Location: Utilities for capturing and handling source code location information
- Header-Only: No compilation required, just include and use
- C++20 Module Support: Optional module interface for modern C++20 projects
- C++20 or higher compatible compiler
- CMake 3.14 or higher
- Git
Configuration : CMake | vcpkg | Conan | Manual | Test
Example: Type Definitions | Automatic Source Location | Exception Handling
Add NekoSchema to your CMake project using FetchContent:
include(FetchContent)
# Add NekoSchema to your CMake project
FetchContent_Declare(
NekoSchema
GIT_REPOSITORY https://github.com/moehoshio/NekoSchema.git
GIT_TAG main
)
FetchContent_MakeAvailable(NekoSchema)
# Define your target and link NekoSchema
add_executable(your_target main.cpp)
target_link_libraries(your_target PRIVATE Neko::Schema)To enable C++20 module support, use the NEKO_SCHEMA_ENABLE_MODULE option:
FetchContent_Declare(
...
)
# Set Options Before Building
set(NEKO_SCHEMA_ENABLE_MODULE ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(NekoSchema)
...
target_link_libraries(your_target PRIVATE Neko::Schema::Module)Import the module in your source code:
import neko.schema;Install NekoSchema using vcpkg:
vcpkg install neko-schemaOr add it to your vcpkg.json:
{
"dependencies": ["neko-schema"]
}Then in your CMakeLists.txt:
find_package(NekoSchema CONFIG REQUIRED)
target_link_libraries(your_target PRIVATE Neko::Schema)When configuring your project, specify the vcpkg toolchain file:
cmake -B build -DCMAKE_PREFIX_PATH=/path/to/vcpkg/installed/x64-windows
cmake --build build --config DebugNote: Installing via vcpkg does not support modules.
Add NekoSchema to your conanfile.txt:
[requires]
neko-schema/*
[generators]
CMakeDeps
CMakeToolchainOr use it in your conanfile.py:
from conan import ConanFile
class YourProject(ConanFile):
requires = "neko-schema/*"
generators = "CMakeDeps", "CMakeToolchain"Then install and use:
conan install . --build=missing
cmake -B build -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake
cmake --build buildIn your CMakeLists.txt:
find_package(NekoSchema CONFIG REQUIRED)
target_link_libraries(your_target PRIVATE Neko::Schema)To enable C++20 module support with Conan, use the enable_module option:
conan install . --build=missing -o neko-schema/*:enable_module=TrueOr specify it in your conanfile.txt:
[requires]
neko-schema/*
[options]
neko-schema/*:enable_module=True
[generators]
CMakeDeps
CMakeToolchainOr in your conanfile.py:
from conan import ConanFile
class YourProject(ConanFile):
requires = "neko-schema/*"
generators = "CMakeDeps", "CMakeToolchain"
def configure(self):
self.options["neko-schema"].enable_module = TrueThen link against the module target in your CMakeLists.txt:
find_package(NekoSchema CONFIG REQUIRED)
target_link_libraries(your_target PRIVATE Neko::Schema::Module)- Clone or download the repository to your local machine:
git clone https://github.com/moehoshio/NekoSchema.gitor
curl -L -o NekoSchema.zip https://github.com/moehoshio/NekoSchema/archive/refs/heads/main.zip
unzip NekoSchema.zip- Copy the
includefolder to your include directory
cp -r NekoSchema/include/ /path/to/your/include/Numerical Types:
#include <neko/schema/types.hpp>
neko::uint8 c = 255;
neko::int16 s = -32768;
neko::uint32 count = 42;
neko::int64 i = -123456789;String Types:
#include <neko/schema/types.hpp>
neko::cstr t = "Sample C-String";
neko::uchar c = 'A';
neko::strview text = t;Enumerations:
#include <neko/schema/types.hpp>
neko::SyncMode mode = neko::SyncMode::Async;
neko::State state = neko::State::Completed;
neko::Priority priority = neko::Priority::High;With the neko::SrcLocInfo object, you can automatically capture source code location information by simply constructing an empty object ({}).
#include <neko/schema/srcLoc.hpp>
void exampleFunction(const neko::SrcLocInfo & srcloc = {}) {
std::cout<< "call from " << srcloc.getFile() << ":" << srcloc.getLine() << " in function " << srcloc.getFunc() << std::endl;
}
void anotherFunction(const neko::SrcLocInfo & srcloc) {
if (srcloc.hasInfo()){
// ...
}
}
int main() {
exampleFunction(); // Automatically captures the call site information
anotherFunction(neko::SrcLocInfo("file.cpp", 2, "CustomFunction")); // You can also provide custom source location
}#include <neko/schema/exception.hpp>
int main() {
try {
// Recommended names (old aliases are deprecated and will warn):
throw neko::ex::RuntimeError("Sample runtime error", {});
} catch (const neko::ex::RangeError &e) {
std::cout << "Range error: " << e.what() << std::endl;
} catch (const neko::ex::SystemError &e) {
if (e.hasSrcLocInfo()) {
auto loc = e.getSrcLoc();
std::cout << "System error from " << loc.getFile() << ':' << loc.getLine() << " in " << loc.getFunc() << '\n';
}
} catch (const neko::ex::Exception &e) {
std::cout << "Generic error: " << e.what() << std::endl;
}
}Note: using legacy names (e.g.,
neko::ex::Runtime,OutOfRange,InvalidArgument) remains possible but is marked[[deprecated]]and will emit a compiler warning. Prefer the new names such asRuntimeError,RangeError, andArgumentError.
You can run the tests to verify that everything is working correctly.
If you haven't configured the build yet, please run:
cmake -B ./build -D NEKO_SCHEMA_AUTO_FETCH_DEPS=ON -D NEKO_SCHEMA_BUILD_TESTS=ON -S .Now, you can build the test files (you must build them manually at least once before running the tests!).
cmake --build ./build --config DebugThen, you can run the tests with the following commands:
cd ./build && ctest --output-on-failureIf everything is set up correctly, you should see output similar to the following:
Test project /path/to/NekoSchema/build
Start 1: TypesTest.BasicTypesSize
1/28 Test #1: TypesTest.BasicTypesSize ........................
..... Passed 0.02 sec
.....
Start 28: PerformanceTest.ConstexprMapLookupSpeed
28/28 Test #28: PerformanceTest.ConstexprMapLookupSpeed .........
..... Passed 0.02 sec
100% tests passed, 0 tests failed out of 28
Total Test time (real) = 0.58 secIf you want to disable building and running tests, you can set the following CMake option when configuring your project:
cmake -B ./build -DNEKO_SCHEMA_BUILD_TESTS=OFF -S .This will skip test targets during the build process.
LICENSE MIT OR Apache-2.0
- NekoNet: A modern , easy-to-use C++20 networking library via libcurl.
- NekoLog: An easy-to-use, modern, lightweight, and efficient C++20 logging library.
- NekoEvent: A modern easy to use type-safe and high-performance event handling system for C++.
- NekoSchema: A lightweight, header-only C++20 schema library.
- NekoSystem: A modern C++20 cross-platform system utility library.
- NekoFunction: A comprehensive modern C++ utility library that provides practical functions for common programming tasks.
- NekoThreadPool: An easy to use and efficient C++ 20 thread pool that supports priorities and submission to specific threads.