Skip to content

Latest commit

 

History

History
399 lines (285 loc) · 12 KB

File metadata and controls

399 lines (285 loc) · 12 KB

Tiny.cpp Documentation

C++11 License Release Workflow

Supported Windows Linux macOS FreeBSD and so on


Look for other language documentation?


Overview

Tiny.cpp is an extremely tiny, lightweight, and easy-to-use foundational library. It provides core functionalities including an event system, file operations, system information retrieval, command-line parsing, and Terminal User Interface (TUI). The library is designed with modern C++ and supports Windows and Unix-like systems (Linux, macOS, etc.).


Key Features

  • Modular Architecture: Each module in the src directory can be reused independently without any configuration
  • Zero Dependencies: No third-party library dependencies, only cross-platform architectural design
  • Easy to Use: Adopts modern C++ standards (minimum C++11 support)

Included Modules

Module Path Description Documentation
TUI src/TUI Terminal User Interface, provides basic terminal drawing functionality for easier terminal rendering en/TUI/TUI.md
OS src/OS Operating System, supports basic file and path operations as well as system information viewing en/OS/File.md, en/OS/System.md
Net src/Net Network communication, provides Socket, Address, hostname resolution, and advanced socket options en/Net/Net.md
CommandParser src/Parser Command parser, provides basic command parameter parsing functionality for easy implementation of command-line tools en/Parser/CommandParser.md
IniParser src/Parser INI configuration file parser, supports parsing, manipulating, and serializing INI files en/Parser/IniParser.md
DateTime src/DateTime Date and time utilities, supporting construction, formatting, arithmetic, and timestamp conversion en/DateTime/DateTime.md
Events src/Events Event system, provides basic components for easy implementation of timers, asynchronous functions, etc. en/Events/Event.md

Installation

Download Pre-built Project

You can directly download the latest pre-built release from Github Release.

Build from Source

CMake

  1. Download project source code via Github:

    git clone https://github.com/CatIsNotFound/Tiny.cpp.git

    For non-stable versions, execute:

    git clone https://github.com/CatIsNotFound/Tiny.cpp.git -b beta
  2. Configure project via CMake

    cd Tiny.cpp
    mkdir build ; cd build
    cmake .. -DCMAKE_INSTALL_PREFIX=/path/to/Tiny.cpp -DCMAKE_BUILD_TYPE=Release -DTINY_BUILD_TEST=OFF 

    Note: Please replace /path/to/Tiny.cpp with your actual installation path.

  3. Build and install to local

    cmake --build . --target install

XMake

If XMake is not installed, execute the following command in the terminal to quickly install XMake:

Linux/MacOS/Unix-like:

curl -fsSL https://xmake.io/shget.text | bash 
wget https://xmake.io/shget.text -O - | bash

Windows:

irm https://xmake.io/psget.text | iex
  1. Download project source code via Github:

    git clone https://github.com/CatIsNotFound/Tiny.cpp.git

    For non-stable versions, execute:

    git clone https://github.com/CatIsNotFound/Tiny.cpp.git -b beta
  2. Configure project via XMake

    cd Tiny.cpp
    xmake f --build_test=n
  3. Build and install to local

    xmake
    xmake package -o /path/to/install

    Note: Please replace /path/to/install with your actual installation path.


Quick Start

Copy Source Code (Most Direct)

Directly copy any directory corresponding to a module from the src directory to your own project. Each module contains a header file (*.hpp) and source file (*.cpp).

Import via CMake

If using CMake as your primary project management tool, it is recommended to import the Tiny project directly via CMake.

Note: Use Tiny as the project library name under CMake, not Tiny.cpp!

  1. Download pre-built binary library or manually build from source to your local machine.

  2. Refer to the following example:

cmake_minimum_required(VERSION 3.24)
project(HelloWorld)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_PREFIX_PATH "/path/to/Tiny.cpp")
find_package(Tiny REQUIRED)

add_executable(${CMAKE_PROJECT_NAME} 
        main.cpp
        # ....
)

target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE
    Tiny::Tiny
)

Import via XMake

Starting from version 1.2.0, Tiny.cpp supports importing via XMake.

To use XMake to import the Tiny.cpp project, you need to first configure the XMake project, then add Tiny.cpp as a dependency in your project.

  1. Download and manually build from source to your local machine.

  2. Manually set up the local repository

xmake repo -g -a local_repo /path/to/package

Note: Please replace /path/to/package with the actual absolute path of the installation package.

You can check if the local repository was added successfully with the following command:

xmake repo -l
  1. Refer to the following example:
add_rules("mode.debug", "mode.release")
set_languages("c++20")
add_requires("tiny.cpp")

target("HelloWorld")
    set_kind("binary")
    add_files("**.cpp")
    add_packages("tiny.cpp")

How to Use

Taking the TUI module as an example, assuming you want to use the Terminal module to simply output Hello, Tiny.cpp!, execute the following code:

// If importing via CMake method, use the following import:
#include <Tiny/TUI/Terminal.hpp>
// If directly copying the TUI directory to your project, it might be imported like this:
#include "TUI/Terminal.hpp"

using ter = Tiny::TUI::Terminal;

int main() {
   ter::printLine("Hello, Tiny.cpp!");   
   return 0;
}

Include Methods

If using CMake to install this project, use the following include methods:

// Main header file, includes all modules
#include <Tiny/Tiny.hpp>

// Or include specific modules separately
#include <Tiny/DateTime/DateTime.hpp>
#include <Tiny/Events/Events.hpp>
#include <Tiny/OS/File.hpp>
#include <Tiny/OS/System.hpp>
#include <Tiny/Parser/CommandParser.hpp>
#include <Tiny/Parser/IniParser.hpp>
#include <Tiny/Net/Socket.hpp>
#include <Tiny/TUI/TUI.hpp>

If directly copying the src directory source code, use the following include methods:

// Main header file, includes all modules
#include "Tiny.hpp"

// Or include specific modules separately
#include "DateTime/DateTime.hpp"
#include "Events/Events.hpp"
#include "OS/File.hpp"
#include "OS/System.hpp"
#include "Parser/CommandParser.hpp"
#include "Parser/IniParser.hpp"
#include "Net/Socket.hpp"
#include "TUI/TUI.hpp"

Manual Compilation

# Linux/macOS
g++ -std=c++17 -I./src main.cpp src/Tiny.cpp \
    src/DateTime/DateTime.cpp \
    src/Events/Events.cpp \
    src/OS/File.cpp \
    src/OS/System.cpp \
    src/Parser/CommandParser.cpp \
    src/Parser/IniParser.cpp \
    src/Net/Socket.cpp \
    src/TUI/TUI.cpp \
    src/TUI/Terminal.cpp \
    -o myapp

# Windows (MinGW)
g++ -std=c++17 -I./src main.cpp src/*.cpp src/*/*.cpp -o myapp.exe

Global Configuration and Macros

Operating System Detection Macros

Macro Description Auto-define Condition
TINY_CPP_MY_OS_WINDOWS Enable Windows platform code _WIN32 or _WIN64 defined
TINY_CPP_MY_OS_UNIX Enable Unix platform code __APPLE__, __linux__, or __unix__ defined

Manually specify platform:

// Manually define before including header files
#define TINY_CPP_MY_OS_WINDOWS
#include <Tiny/Tiny.hpp>

Module Namespaces

Namespace Description
Tiny Root namespace
Tiny::OS Operating system related functions (files, system info)
Tiny::DT Date and time utilities
Tiny::TUI Terminal user interface functions
Tiny::Net Network communication functions (Socket, Address, hostname resolution)

Runtime Environment

  • C++ Standard: C++ 11 or higher
  • Operating Systems: Windows (Windows 7+), Linux, macOS, Unix-like systems
  • Compilers: GCC 7+, Clang 5+, MSVC 2017+

Dependencies

  • Windows: Depends on windows.h, shlobj.h, pdh.h (performance counters)
  • Unix/Linux: Depends on standard POSIX interfaces, termios, sys/ioctl.h
  • macOS: Additional dependencies on mach/mach.h and other system interfaces

Module Documentation

DateTime Module

Date and time handling utilities.

Events Module

Asynchronous event management system.

OS Module

Operating system related functions.

Net Module

Network communication utilities.

Parser Module

Command-line argument parser and INI file parser.

TUI Module

Terminal user interface.


Version and Compatibility

Version Information

  • Current Version: Unreleased
  • Release Date: 2026
  • License: MIT License
  • Author: CatIsNotFound

Platform Compatibility

Platform Support Status Tested Version
Windows 10/11 Fully supported Tested
Windows 7/8 Partially supported Not tested
Linux (x86_64) Fully supported Ubuntu 22.04
Linux (ARM64) Fully supported Not tested
macOS (Intel) Fully supported Not tested
macOS (Apple Silicon) Fully supported Not tested

Compiler Compatibility

Compiler Minimum Version Support Status
GCC 7.0 Fully supported
Clang 5.0 Fully supported
MSVC 2017 Fully supported
MinGW-w64 8.0 Fully supported

C++ Standard

  • Required: C++11 or higher
  • Recommended: C++20
  • Tested Standards: C++11, C++20

Known Limitations

  1. Windows 7: Some system information retrieval APIs may not be available
  2. macOS: CPU usage calculation differs slightly from Linux
  3. Terminal: TUI module requires terminal supporting ANSI escape sequences
  4. Encoding: File paths use UTF-8 encoding on Windows

License

Tiny.cpp is licensed under the MIT License. You can view detailed information in the LICENSE file or any other header or source file.